mirror of
https://github.com/minio/minio.git
synced 2025-04-06 12:50:34 -04:00
wip
This commit is contained in:
parent
7db1d5afef
commit
718794205f
@ -61,6 +61,7 @@ func createSelectCases(channels []<-chan error) []reflect.SelectCase {
|
|||||||
func getHttpHandler() http.Handler {
|
func getHttpHandler() http.Handler {
|
||||||
mux := mux.NewRouter()
|
mux := mux.NewRouter()
|
||||||
mux.HandleFunc("/{bucket}/{object:.*}", getObjectHandler).Methods("GET")
|
mux.HandleFunc("/{bucket}/{object:.*}", getObjectHandler).Methods("GET")
|
||||||
|
mux.HandleFunc("/{bucket}/{object:.*}", putObjectHandler).Methods("PUT")
|
||||||
return mux
|
return mux
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,3 +71,10 @@ func getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
object := vars["object"]
|
object := vars["object"]
|
||||||
storage.CopyObjectToWriter(w, bucket, object)
|
storage.CopyObjectToWriter(w, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
bucket := vars["bucket"]
|
||||||
|
object := vars["object"]
|
||||||
|
storage.StoreObject(bucket, object, req.Body)
|
||||||
|
}
|
||||||
|
@ -6,16 +6,29 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage struct{}
|
type Storage struct {
|
||||||
|
data map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error {
|
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error {
|
||||||
// TODO synchronize access
|
// TODO synchronize access
|
||||||
// get object
|
// get object
|
||||||
objectData := "OBJECT: " + bucket + " - " + object
|
key := bucket + ":" + object
|
||||||
objectBuffer := bytes.NewBufferString(objectData)
|
if val, ok := storage.data[key]; ok {
|
||||||
// copy object to writer
|
objectBuffer := bytes.NewBuffer(val)
|
||||||
_, err := io.Copy(w, objectBuffer)
|
_, err := io.Copy(w, objectBuffer)
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
return errors.New("Not Found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (storage *Storage) StoreObject(bucket string, object string, data io.Reader) {
|
||||||
|
key := bucket + ":" + object
|
||||||
|
var bytesBuffer bytes.Buffer
|
||||||
|
if _, ok := io.Copy(&bytesBuffer, data); ok == nil {
|
||||||
|
storage.data[key] = bytesBuffer.Bytes()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start() (chan<- string, <-chan error, *Storage) {
|
func Start() (chan<- string, <-chan error, *Storage) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user