diff --git a/gateway.go b/gateway.go index 1a15cc699..2112dd6f6 100644 --- a/gateway.go +++ b/gateway.go @@ -12,6 +12,7 @@ import ( // Stores system configuration, populated from CLI or test runner type GatewayConfig struct { StorageDriver StorageDriver + BucketDriver BucketDriver requestBucketChan chan BucketRequest } @@ -32,6 +33,9 @@ type Bucket interface { Put(Context, string, []byte) error } +// Bucket driver function, should read from a channel and respond through callback channels +type BucketDriver func(config GatewayConfig) + // Storage driver function, should read from a channel and respond through callback channels type StorageDriver func(bucket string, input chan ObjectRequest) @@ -87,14 +91,14 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) { config.requestBucketChan = make(chan BucketRequest) - go SynchronizedBucketService(config) + go config.BucketDriver(config) getHandler := GatewayGetHandler{config} putHandler := GatewayPutHandler{config} router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET") router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT") } -func SynchronizedBucketService(config GatewayConfig) { +func SynchronizedBucketDriver(config GatewayConfig) { buckets := make(map[string]*SynchronizedBucket) for request := range config.requestBucketChan { if buckets[request.name] == nil { diff --git a/gateway_test.go b/gateway_test.go index aea5e188a..c730a3cff 100644 --- a/gateway_test.go +++ b/gateway_test.go @@ -19,7 +19,10 @@ func Test(t *testing.T) { TestingT(t) } func (s *MySuite) TestPrintsGateway(c *C) { // set up router with in memory storage driver router := mux.NewRouter() - config := GatewayConfig{StorageDriver: InMemoryStorageDriver} + config := GatewayConfig{ + StorageDriver: InMemoryStorageDriver, + BucketDriver: SynchronizedBucketDriver, + } RegisterGatewayHandlers(router, config) server := httptest.NewServer(router) defer server.Close() @@ -62,7 +65,7 @@ func (s *MySuite) TestBucketCreation(c *C) { requestBucketChan: make(chan BucketRequest), } defer close(config.requestBucketChan) - go SynchronizedBucketService(config) + go SynchronizedBucketDriver(config) context := TestContext{} // get new bucket A @@ -107,7 +110,7 @@ func (s *MySuite) TestInMemoryBucketOperations(c *C) { requestBucketChan: make(chan BucketRequest), } defer close(config.requestBucketChan) - go SynchronizedBucketService(config) + go SynchronizedBucketDriver(config) context := TestContext{} // get bucket diff --git a/minio/main.go b/minio/main.go index 0c847a60a..c75538a76 100644 --- a/minio/main.go +++ b/minio/main.go @@ -26,7 +26,10 @@ func main() { Name: "gateway", Usage: "Start a gateway node", Action: func(c *cli.Context) { - minio.RegisterGatewayHandlers(router, minio.GatewayConfig{StorageDriver: minio.InMemoryStorageDriver}) + minio.RegisterGatewayHandlers(router, minio.GatewayConfig{ + StorageDriver: minio.InMemoryStorageDriver, + BucketDriver: minio.SynchronizedBucketDriver, + }) runServer = true }, },