|
|
@ -51,9 +51,8 @@ type encoder interface { |
|
|
|
|
|
|
|
|
|
|
|
func HttpHandler(storage mstorage.Storage) http.Handler { |
|
|
|
func HttpHandler(storage mstorage.Storage) http.Handler { |
|
|
|
mux := mux.NewRouter() |
|
|
|
mux := mux.NewRouter() |
|
|
|
api := minioApi{ |
|
|
|
var api = minioApi{} |
|
|
|
storage: storage, |
|
|
|
api.storage = storage |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET") |
|
|
|
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET") |
|
|
|
mux.HandleFunc("/{bucket}/", api.listObjectsHandler).Methods("GET") |
|
|
|
mux.HandleFunc("/{bucket}/", api.listObjectsHandler).Methods("GET") |
|
|
@ -61,6 +60,7 @@ func HttpHandler(storage mstorage.Storage) http.Handler { |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET") |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET") |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD") |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD") |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT") |
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT") |
|
|
|
|
|
|
|
|
|
|
|
return mux |
|
|
|
return mux |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -112,9 +112,8 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque |
|
|
|
|
|
|
|
|
|
|
|
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) { |
|
|
|
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) { |
|
|
|
vars := mux.Vars(req) |
|
|
|
vars := mux.Vars(req) |
|
|
|
var prefix string |
|
|
|
prefix, ok := vars["prefix"] |
|
|
|
var ok bool |
|
|
|
if !ok { |
|
|
|
if prefix, ok = vars["prefix"]; ok == false { |
|
|
|
|
|
|
|
prefix = "" |
|
|
|
prefix = "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -144,7 +143,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ |
|
|
|
vars := mux.Vars(req) |
|
|
|
vars := mux.Vars(req) |
|
|
|
bucket := vars["bucket"] |
|
|
|
bucket := vars["bucket"] |
|
|
|
prefix, ok := vars["prefix"] |
|
|
|
prefix, ok := vars["prefix"] |
|
|
|
if ok == false { |
|
|
|
if !ok { |
|
|
|
prefix = "" |
|
|
|
prefix = "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -195,8 +194,7 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
// Write Object Header helper
|
|
|
|
|
|
|
|
|
|
|
|
func writeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMetadata) { |
|
|
|
func writeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMetadata) { |
|
|
|
lastModified := metadata.Created.Format(time.RFC1123) |
|
|
|
lastModified := metadata.Created.Format(time.RFC1123) |
|
|
|
w.Header().Set("ETag", metadata.ETag) |
|
|
|
w.Header().Set("ETag", metadata.ETag) |
|
|
@ -205,53 +203,48 @@ func writeObjectHeaders(w http.ResponseWriter, metadata mstorage.ObjectMetadata) |
|
|
|
w.Header().Set("Content-Type", "text/plain") |
|
|
|
w.Header().Set("Content-Type", "text/plain") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketListResponse) { |
|
|
|
func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResponse { |
|
|
|
var listbuckets []*Bucket |
|
|
|
var listbuckets []*Bucket |
|
|
|
|
|
|
|
var data = BucketListResponse{} |
|
|
|
|
|
|
|
var owner = Owner{} |
|
|
|
|
|
|
|
|
|
|
|
owner := Owner{ |
|
|
|
owner.ID = "minio" |
|
|
|
ID: "minio", |
|
|
|
owner.DisplayName = "minio" |
|
|
|
DisplayName: "minio", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, bucket := range buckets { |
|
|
|
for _, bucket := range buckets { |
|
|
|
listbucket := &Bucket{ |
|
|
|
var listbucket = &Bucket{} |
|
|
|
Name: bucket.Name, |
|
|
|
listbucket.Name = bucket.Name |
|
|
|
CreationDate: bucket.Created.Format(dateFormat), |
|
|
|
listbucket.CreationDate = bucket.Created.Format(dateFormat) |
|
|
|
} |
|
|
|
|
|
|
|
listbuckets = append(listbuckets, listbucket) |
|
|
|
listbuckets = append(listbuckets, listbucket) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data = BucketListResponse{ |
|
|
|
data.Owner = owner |
|
|
|
Owner: owner, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data.Buckets.Bucket = listbuckets |
|
|
|
data.Buckets.Bucket = listbuckets |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) (data ObjectListResponse) { |
|
|
|
func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) ObjectListResponse { |
|
|
|
var contents []*Item |
|
|
|
var contents []*Item |
|
|
|
|
|
|
|
var owner = Owner{} |
|
|
|
|
|
|
|
var data = ObjectListResponse{} |
|
|
|
|
|
|
|
|
|
|
|
owner := Owner{ |
|
|
|
owner.ID = "minio" |
|
|
|
ID: "minio", |
|
|
|
owner.DisplayName = "minio" |
|
|
|
DisplayName: "minio", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, object := range objects { |
|
|
|
for _, object := range objects { |
|
|
|
content := &Item{ |
|
|
|
var content = &Item{} |
|
|
|
Key: object.Key, |
|
|
|
content.Key = object.Key |
|
|
|
LastModified: object.Created.Format(dateFormat), |
|
|
|
content.LastModified = object.Created.Format(dateFormat) |
|
|
|
ETag: object.ETag, |
|
|
|
content.ETag = object.ETag |
|
|
|
Size: object.Size, |
|
|
|
content.Size = object.Size |
|
|
|
StorageClass: "STANDARD", |
|
|
|
content.StorageClass = "STANDARD" |
|
|
|
Owner: owner, |
|
|
|
content.Owner = owner |
|
|
|
} |
|
|
|
|
|
|
|
contents = append(contents, content) |
|
|
|
contents = append(contents, content) |
|
|
|
} |
|
|
|
} |
|
|
|
data = ObjectListResponse{ |
|
|
|
data.Name = bucket |
|
|
|
Name: bucket, |
|
|
|
data.Contents = contents |
|
|
|
Contents: contents, |
|
|
|
data.MaxKeys = MAX_OBJECT_LIST |
|
|
|
MaxKeys: MAX_OBJECT_LIST, |
|
|
|
data.IsTruncated = false |
|
|
|
IsTruncated: false, |
|
|
|
return data |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|