|
|
@ -11,6 +11,7 @@ import ( |
|
|
|
// Stores system configuration, populated from CLI or test runner
|
|
|
|
// Stores system configuration, populated from CLI or test runner
|
|
|
|
type GatewayConfig struct { |
|
|
|
type GatewayConfig struct { |
|
|
|
StorageDriver StorageDriver |
|
|
|
StorageDriver StorageDriver |
|
|
|
|
|
|
|
requestBucketChan chan BucketRequest |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Message for requesting a bucket
|
|
|
|
// Message for requesting a bucket
|
|
|
@ -37,7 +38,7 @@ type StorageDriver func(bucket string, input chan ObjectRequest) |
|
|
|
type fakeContext struct{} |
|
|
|
type fakeContext struct{} |
|
|
|
|
|
|
|
|
|
|
|
type GatewayGetHandler struct { |
|
|
|
type GatewayGetHandler struct { |
|
|
|
requestBucketChan chan BucketRequest |
|
|
|
config GatewayConfig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GET requests server
|
|
|
|
// GET requests server
|
|
|
@ -47,7 +48,7 @@ func (handler GatewayGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ |
|
|
|
path := vars["path"] |
|
|
|
path := vars["path"] |
|
|
|
context := fakeContext{} |
|
|
|
context := fakeContext{} |
|
|
|
callback := make(chan Bucket) |
|
|
|
callback := make(chan Bucket) |
|
|
|
handler.requestBucketChan <- BucketRequest{ |
|
|
|
handler.config.requestBucketChan <- BucketRequest{ |
|
|
|
name: bucketName, |
|
|
|
name: bucketName, |
|
|
|
context: context, |
|
|
|
context: context, |
|
|
|
callback: callback, |
|
|
|
callback: callback, |
|
|
@ -64,7 +65,7 @@ func (handler GatewayGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type GatewayPutHandler struct { |
|
|
|
type GatewayPutHandler struct { |
|
|
|
requestBucketChan chan BucketRequest |
|
|
|
config GatewayConfig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
|
|
|
func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
|
|
@ -74,7 +75,7 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ |
|
|
|
object, _ := ioutil.ReadAll(req.Body) |
|
|
|
object, _ := ioutil.ReadAll(req.Body) |
|
|
|
context := fakeContext{} |
|
|
|
context := fakeContext{} |
|
|
|
callback := make(chan Bucket) |
|
|
|
callback := make(chan Bucket) |
|
|
|
handler.requestBucketChan <- BucketRequest{ |
|
|
|
handler.config.requestBucketChan <- BucketRequest{ |
|
|
|
name: bucketName, |
|
|
|
name: bucketName, |
|
|
|
context: context, |
|
|
|
context: context, |
|
|
|
callback: callback, |
|
|
|
callback: callback, |
|
|
@ -84,17 +85,17 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) { |
|
|
|
func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) { |
|
|
|
requestBucketChan := make(chan BucketRequest) |
|
|
|
config.requestBucketChan = make(chan BucketRequest) |
|
|
|
go SynchronizedBucketService(requestBucketChan, config) |
|
|
|
go SynchronizedBucketService(config) |
|
|
|
getHandler := GatewayGetHandler{requestBucketChan: requestBucketChan} |
|
|
|
getHandler := GatewayGetHandler{config} |
|
|
|
putHandler := GatewayPutHandler{requestBucketChan: requestBucketChan} |
|
|
|
putHandler := GatewayPutHandler{config} |
|
|
|
router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET") |
|
|
|
router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET") |
|
|
|
router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT") |
|
|
|
router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SynchronizedBucketService(input chan BucketRequest, config GatewayConfig) { |
|
|
|
func SynchronizedBucketService(config GatewayConfig) { |
|
|
|
buckets := make(map[string]*SynchronizedBucket) |
|
|
|
buckets := make(map[string]*SynchronizedBucket) |
|
|
|
for request := range input { |
|
|
|
for request := range config.requestBucketChan { |
|
|
|
if buckets[request.name] == nil { |
|
|
|
if buckets[request.name] == nil { |
|
|
|
bucketChannel := make(chan ObjectRequest) |
|
|
|
bucketChannel := make(chan ObjectRequest) |
|
|
|
go config.StorageDriver(request.name, bucketChannel) |
|
|
|
go config.StorageDriver(request.name, bucketChannel) |
|
|
|