mirror of
https://github.com/minio/minio.git
synced 2025-01-26 22:23:15 -05:00
Initial work for xml list objects
This commit is contained in:
parent
5a4f472638
commit
53190e1210
@ -5,16 +5,16 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(handler http.Handler) (chan<- string, <-chan error) {
|
func Start(handler http.Handler, address string) (chan<- string, <-chan error) {
|
||||||
ctrlChannel := make(chan string)
|
ctrlChannel := make(chan string)
|
||||||
errorChannel := make(chan error)
|
errorChannel := make(chan error)
|
||||||
go start(ctrlChannel, errorChannel, handler)
|
go start(ctrlChannel, errorChannel, handler, address)
|
||||||
return ctrlChannel, errorChannel
|
return ctrlChannel, errorChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler) {
|
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler, address string) {
|
||||||
log.Println("Starting HTTP Server")
|
log.Println("Starting HTTP Server on " + address)
|
||||||
err := http.ListenAndServe(":8080", router)
|
err := http.ListenAndServe(address, router)
|
||||||
errorChannel <- err
|
errorChannel <- err
|
||||||
close(errorChannel)
|
close(errorChannel)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func Start() {
|
|||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
statusChans = append(statusChans, statusChan)
|
statusChans = append(statusChans, statusChan)
|
||||||
|
|
||||||
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage))
|
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), ":8080")
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
statusChans = append(statusChans, statusChan)
|
statusChans = append(statusChans, statusChan)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,6 +9,8 @@ type Storage struct {
|
|||||||
data map[string][]byte
|
data map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ObjectMetadata struct{}
|
||||||
|
|
||||||
type GenericError struct {
|
type GenericError struct {
|
||||||
bucket string
|
bucket string
|
||||||
path string
|
path string
|
||||||
@ -42,6 +43,10 @@ func (storage *Storage) StoreObject(bucket string, object string, data io.Reader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (storage *Storage) ListObjects(bucket, prefix string, count int) []ObjectMetadata {
|
||||||
|
return []ObjectMetadata{}
|
||||||
|
}
|
||||||
|
|
||||||
func Start() (chan<- string, <-chan error, *Storage) {
|
func Start() (chan<- string, <-chan error, *Storage) {
|
||||||
ctrlChannel := make(chan string)
|
ctrlChannel := make(chan string)
|
||||||
errorChannel := make(chan error)
|
errorChannel := make(chan error)
|
||||||
@ -52,8 +57,5 @@ func Start() (chan<- string, <-chan error, *Storage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
||||||
errorChannel <- errors.New("STORAGE MSG")
|
|
||||||
errorChannel <- errors.New("STORAGE MSG")
|
|
||||||
errorChannel <- errors.New("STORAGE MSG")
|
|
||||||
close(errorChannel)
|
close(errorChannel)
|
||||||
}
|
}
|
||||||
|
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
|
package minioapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/xml"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ func HttpHandler(storage *mstorage.Storage) http.Handler {
|
|||||||
api := minioApi{
|
api := minioApi{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
}
|
}
|
||||||
|
mux.HandleFunc("/", api.listHandler).Methods("GET")
|
||||||
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
||||||
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
||||||
return mux
|
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) {
|
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
object := vars["object"]
|
object := vars["object"]
|
||||||
server.storage.StoreObject(bucket, object, req.Body)
|
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("")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user