mirror of
https://github.com/minio/minio.git
synced 2025-01-26 22:23:15 -05:00
Merge pull request #43 from harshavardhana/pr_out_list_buckets_response_should_be_nested_xml_buckets
This commit is contained in:
commit
3e11e9a879
@ -32,7 +32,9 @@ type ObjectListResponse struct {
|
|||||||
type BucketListResponse struct {
|
type BucketListResponse struct {
|
||||||
XMLName xml.Name `xml:"ListAllMyBucketsResult"`
|
XMLName xml.Name `xml:"ListAllMyBucketsResult"`
|
||||||
Owner Owner
|
Owner Owner
|
||||||
Buckets []Bucket `xml:"Buckets",innerxml`
|
Buckets struct {
|
||||||
|
Bucket []*Bucket
|
||||||
|
} `xml:"Buckets",innerxml` // Buckets are nested
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bucket struct {
|
type Bucket struct {
|
||||||
|
@ -115,10 +115,13 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
if ok == false {
|
if ok == false {
|
||||||
prefix = ""
|
prefix = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType := "xml"
|
contentType := "xml"
|
||||||
|
if _, ok := req.Header["Accept"]; ok {
|
||||||
if req.Header["Accept"][0] == "application/json" {
|
if req.Header["Accept"][0] == "application/json" {
|
||||||
contentType = "json"
|
contentType = "json"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
buckets := server.storage.ListBuckets(prefix)
|
buckets := server.storage.ListBuckets(prefix)
|
||||||
response := generateBucketsListResult(buckets)
|
response := generateBucketsListResult(buckets)
|
||||||
|
|
||||||
@ -128,13 +131,11 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
encoder = json.NewEncoder(&bytesBuffer)
|
encoder = json.NewEncoder(&bytesBuffer)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "application/xml")
|
w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`)
|
||||||
encoder = xml.NewEncoder(&bytesBuffer)
|
encoder = xml.NewEncoder(&bytesBuffer)
|
||||||
}
|
}
|
||||||
encoder.Encode(response)
|
encoder.Encode(response)
|
||||||
|
|
||||||
w.Write(bytesBuffer.Bytes())
|
w.Write(bytesBuffer.Bytes())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
@ -157,9 +158,11 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
|
|
||||||
contentType := "xml"
|
contentType := "xml"
|
||||||
|
|
||||||
|
if _, ok := req.Header["Accept"]; ok {
|
||||||
if req.Header["Accept"][0] == "application/json" {
|
if req.Header["Accept"][0] == "application/json" {
|
||||||
contentType = "json"
|
contentType = "json"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
objects := server.storage.ListObjects(bucket, prefix, 1000)
|
objects := server.storage.ListObjects(bucket, prefix, 1000)
|
||||||
response := generateObjectsListResult(bucket, objects)
|
response := generateObjectsListResult(bucket, objects)
|
||||||
@ -170,7 +173,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
encoder = json.NewEncoder(&bytesBuffer)
|
encoder = json.NewEncoder(&bytesBuffer)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "application/xml")
|
w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`)
|
||||||
encoder = xml.NewEncoder(&bytesBuffer)
|
encoder = xml.NewEncoder(&bytesBuffer)
|
||||||
}
|
}
|
||||||
encoder.Encode(response)
|
encoder.Encode(response)
|
||||||
@ -202,7 +205,7 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketListResponse) {
|
func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketListResponse) {
|
||||||
listbuckets := []Bucket{}
|
var listbuckets []*Bucket
|
||||||
|
|
||||||
owner := Owner{
|
owner := Owner{
|
||||||
ID: "minio",
|
ID: "minio",
|
||||||
@ -210,7 +213,7 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
listbucket := Bucket{
|
listbucket := &Bucket{
|
||||||
Name: bucket.Name,
|
Name: bucket.Name,
|
||||||
CreationDate: formatDate(bucket.Created),
|
CreationDate: formatDate(bucket.Created),
|
||||||
}
|
}
|
||||||
@ -219,8 +222,8 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketLi
|
|||||||
|
|
||||||
data = BucketListResponse{
|
data = BucketListResponse{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Buckets: listbuckets,
|
|
||||||
}
|
}
|
||||||
|
data.Buckets.Bucket = listbuckets
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user