mirror of
https://github.com/minio/minio.git
synced 2025-11-20 09:56:07 -05:00
Initial work for xml list objects
This commit is contained in:
29
pkg/webapi/minioapi/definitions.go
Normal file
29
pkg/webapi/minioapi/definitions.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package minioapi
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type ListResponse struct {
|
||||
XMLName xml.Name `xml:"ListBucketResult"`
|
||||
Name string `xml:"Name"`
|
||||
Prefix string
|
||||
Marker string
|
||||
MaxKeys int32
|
||||
IsTruncated bool
|
||||
Contents []Content `xml:"Contents",innerxml`
|
||||
}
|
||||
|
||||
type Content struct {
|
||||
Key string
|
||||
LastModified string
|
||||
ETag string
|
||||
Size uint64
|
||||
StorageClass string
|
||||
Owner Owner
|
||||
}
|
||||
|
||||
type Owner struct {
|
||||
ID string
|
||||
DisplayName string
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package minioapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
@@ -17,6 +19,7 @@ func HttpHandler(storage *mstorage.Storage) http.Handler {
|
||||
api := minioApi{
|
||||
storage: storage,
|
||||
}
|
||||
mux.HandleFunc("/", api.listHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
||||
return mux
|
||||
@@ -46,9 +49,68 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
||||
}
|
||||
}
|
||||
|
||||
func (server *minioApi) listHandler(w http.ResponseWriter, req *http.Request) {
|
||||
vars := mux.Vars(req)
|
||||
|
||||
//delimiter, ok := vars["delimiter"]
|
||||
//encodingType, ok := vars["encoding-type"]
|
||||
//marker, ok := vars["marker"]
|
||||
//maxKeys, ok := vars["max-keys"]
|
||||
bucket := "bucket"
|
||||
//bucket, ok := vars["bucket"]
|
||||
//if ok == false {
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
//}
|
||||
prefix, ok := vars["prefix"]
|
||||
if ok == false {
|
||||
prefix = ""
|
||||
}
|
||||
|
||||
objects := server.storage.ListObjects(bucket, prefix, 1000)
|
||||
response := generateListResult(objects)
|
||||
|
||||
var bytesBuffer bytes.Buffer
|
||||
xmlEncoder := xml.NewEncoder(&bytesBuffer)
|
||||
xmlEncoder.Encode(response)
|
||||
|
||||
w.Header().Set("Content-Type", "application/xml")
|
||||
w.Write(bytesBuffer.Bytes())
|
||||
}
|
||||
|
||||
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||
vars := mux.Vars(req)
|
||||
bucket := vars["bucket"]
|
||||
object := vars["object"]
|
||||
server.storage.StoreObject(bucket, object, req.Body)
|
||||
}
|
||||
|
||||
func generateListResult(objects []mstorage.ObjectMetadata) ListResponse {
|
||||
owner := Owner{
|
||||
ID: "MyID",
|
||||
DisplayName: "MyDisplayName",
|
||||
}
|
||||
contents := []Content{
|
||||
Content{
|
||||
Key: "one",
|
||||
LastModified: "two",
|
||||
ETag: "\"ETag\"",
|
||||
Size: 1,
|
||||
StorageClass: "three",
|
||||
Owner: owner,
|
||||
},
|
||||
Content{
|
||||
Key: "four",
|
||||
LastModified: "five",
|
||||
ETag: "\"ETag\"",
|
||||
Size: 1,
|
||||
StorageClass: "six",
|
||||
Owner: owner,
|
||||
},
|
||||
}
|
||||
data := &ListResponse{
|
||||
Name: "name",
|
||||
Contents: contents,
|
||||
}
|
||||
return *data
|
||||
}
|
||||
|
||||
45
pkg/webapi/minioapi/minioapi_test.go
Normal file
45
pkg/webapi/minioapi/minioapi_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package minioapi
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMinioApi(t *testing.T) {
|
||||
owner := Owner{
|
||||
ID: "MyID",
|
||||
DisplayName: "MyDisplayName",
|
||||
}
|
||||
contents := []Content{
|
||||
Content{
|
||||
Key: "one",
|
||||
LastModified: "two",
|
||||
ETag: "\"ETag\"",
|
||||
Size: 1,
|
||||
StorageClass: "three",
|
||||
Owner: owner,
|
||||
},
|
||||
Content{
|
||||
Key: "four",
|
||||
LastModified: "five",
|
||||
ETag: "\"ETag\"",
|
||||
Size: 1,
|
||||
StorageClass: "six",
|
||||
Owner: owner,
|
||||
},
|
||||
}
|
||||
data := &ListResponse{
|
||||
Name: "name",
|
||||
Contents: contents,
|
||||
}
|
||||
|
||||
xmlEncoder := xml.NewEncoder(os.Stdout)
|
||||
if err := xmlEncoder.Encode(data); err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
fmt.Println("")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user