Simple S3-like server for development purposes, written in Go
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Progress towards list

+24 -1
+24 -1
gos3dir.go
··· 35 35 } 36 36 37 37 func (s *server) ls(w http.ResponseWriter, r *http.Request) { 38 - s.logger.Printf("Path %s", r.PathValue("bucket")) 38 + root, err := os.OpenRoot(s.rootDir) 39 + if err != nil { 40 + http.Error(w, err.Error(), http.StatusInternalServerError) 41 + } 42 + defer root.Close() 43 + 44 + bucketName := r.PathValue("bucket") 45 + if bucketName == "" { 46 + // List available buckets 47 + files, err := fs.ReadDir(root.FS(), ".") 48 + if err != nil { 49 + http.Error(w, err.Error(), http.StatusInternalServerError) 50 + return 51 + } 52 + s.logger.Printf("Buckets: %s", files) 53 + } else { 54 + // FIXME: "The returned path ends in a slash only if it represents a root directory, 55 + // such as "/" on Unix or `C:\` on Windows." 56 + prefix := r.URL.Query().Get("prefix") 57 + path := filepath.Join(bucketName, prefix) 58 + s.logger.Printf("Path %s, original prefix %s", path, prefix) 59 + } 60 + 39 61 // TODO: Probably requires actual XML 40 62 w.WriteHeader(http.StatusNotImplemented) 41 63 } ··· 173 195 srv := &server{rootDir: rootDir, logger: logger} 174 196 175 197 // TODO: (Claude) "S3 returns ETags for uploaded objects. Consider adding MD5 hashing" 198 + http.HandleFunc("GET /{$}", srv.ls) 176 199 http.HandleFunc("GET /{bucket}", srv.ls) 177 200 http.HandleFunc("PUT /{bucket}", srv.mb) 178 201 http.HandleFunc("PUT /{bucket}/{key...}", srv.cp)