Bucket manager is now configurable as GatewayConfig.BucketServiceDriver

This commit is contained in:
Frederick F. Kautz IV
2014-11-13 22:18:44 -08:00
parent f46fad48b0
commit 101ce51f78
3 changed files with 16 additions and 6 deletions
+6 -2
View File
@@ -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 {