Get Bucket List objects compliance MaxKeys to 1000, Rename

Content struct to Item for cosmetic reasons for xml decoding
on client side
This commit is contained in:
Harshavardhana 2015-01-23 12:14:39 -08:00
parent 3e11e9a879
commit d9d80f7c22
2 changed files with 11 additions and 8 deletions

View File

@ -20,13 +20,17 @@ import (
"encoding/xml" "encoding/xml"
) )
const (
MAX_OBJECT_LIST = 1000
)
type ObjectListResponse struct { type ObjectListResponse struct {
XMLName xml.Name `xml:"ListBucketResult"` XMLName xml.Name `xml:"ListBucketResult"`
Name string `xml:"Name"` Name string
Marker string Marker string
MaxKeys int MaxKeys int
IsTruncated bool IsTruncated bool
Contents []Content `xml:"Contents",innerxml` Contents []*Item `xml:"Contents",innerxml`
} }
type BucketListResponse struct { type BucketListResponse struct {
@ -42,7 +46,7 @@ type Bucket struct {
CreationDate string CreationDate string
} }
type Content struct { type Item struct {
Key string Key string
LastModified string LastModified string
ETag string ETag string

View File

@ -157,7 +157,6 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
} }
contentType := "xml" contentType := "xml"
if _, ok := req.Header["Accept"]; ok { if _, ok := req.Header["Accept"]; ok {
if req.Header["Accept"][0] == "application/json" { if req.Header["Accept"][0] == "application/json" {
contentType = "json" contentType = "json"
@ -176,8 +175,8 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`) 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())
} }
@ -228,7 +227,7 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketLi
} }
func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) (data ObjectListResponse) { func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) (data ObjectListResponse) {
contents := []Content{} var contents []*Item
owner := Owner{ owner := Owner{
ID: "minio", ID: "minio",
@ -236,7 +235,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata)
} }
for _, object := range objects { for _, object := range objects {
content := Content{ content := &Item{
Key: object.Key, Key: object.Key,
LastModified: formatDate(object.Created), LastModified: formatDate(object.Created),
ETag: object.ETag, ETag: object.ETag,
@ -249,7 +248,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata)
data = ObjectListResponse{ data = ObjectListResponse{
Name: bucket, Name: bucket,
Contents: contents, Contents: contents,
MaxKeys: len(objects), MaxKeys: MAX_OBJECT_LIST,
IsTruncated: false, IsTruncated: false,
} }
return return