From c766f3617b54d9aba7070a3ea16bd44fadced776 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sun, 18 Jan 2015 16:10:48 -0800 Subject: [PATCH] Populating http handler with test scaffolding --- pkg/server/server.go | 15 ++++++++++----- pkg/storage/storage.go | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 7f926dc79..037ecbd98 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1,23 +1,25 @@ package server import ( - "io" "log" "net/http" "reflect" "github.com/gorilla/mux" "github.com/minio-io/minio/pkg/httpserver" - "github.com/minio-io/minio/pkg/storage" + storageModule "github.com/minio-io/minio/pkg/storage" ) +var storage *storageModule.Storage + func Start() { ctrlChans := make([]chan<- string, 0) statusChans := make([]<-chan error, 0) - ctrlChan, statusChan := storage.Start() + ctrlChan, statusChan, storageSystem := storageModule.Start() ctrlChans = append(ctrlChans, ctrlChan) statusChans = append(statusChans, statusChan) + storage = storageSystem ctrlChan, statusChan = httpserver.Start(getHttpHandler()) ctrlChans = append(ctrlChans, ctrlChan) @@ -58,10 +60,13 @@ func createSelectCases(channels []<-chan error) []reflect.SelectCase { func getHttpHandler() http.Handler { mux := mux.NewRouter() - mux.HandleFunc("/", storageHandler) + mux.HandleFunc("/{bucket}/{object:.*}", storageHandler) return mux } func storageHandler(w http.ResponseWriter, req *http.Request) { - io.WriteString(w, "MINIO") + vars := mux.Vars(req) + bucket := vars["bucket"] + object := vars["object"] + storage.CopyObjectToWriter(w, bucket, object) } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 7e212a6fa..d59ca6edc 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -1,12 +1,28 @@ package storage -import "errors" +import ( + "bytes" + "errors" + "io" +) -func Start() (chan<- string, <-chan error) { +type Storage struct{} + +func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error { + // TODO synchronize access + // get object + objectData := "OBJECT: " + bucket + " - " + object + objectBuffer := bytes.NewBufferString(objectData) + // copy object to writer + _, err := io.Copy(w, objectBuffer) + return err +} + +func Start() (chan<- string, <-chan error, *Storage) { ctrlChannel := make(chan string) errorChannel := make(chan error) go start(ctrlChannel, errorChannel) - return ctrlChannel, errorChannel + return ctrlChannel, errorChannel, &Storage{} } func start(ctrlChannel <-chan string, errorChannel chan<- error) {