mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
Merge pull request #16 from fkautz/pr_out_moving_bucket_request_channel_to_private_config_option
Moving bucket request channel to private config option
This commit is contained in:
commit
c39c51328e
21
gateway.go
21
gateway.go
@ -12,6 +12,7 @@ import (
|
||||
// Stores system configuration, populated from CLI or test runner
|
||||
type GatewayConfig struct {
|
||||
StorageDriver StorageDriver
|
||||
requestBucketChan chan BucketRequest
|
||||
}
|
||||
|
||||
// Message for requesting a bucket
|
||||
@ -38,7 +39,7 @@ type StorageDriver func(bucket string, input chan ObjectRequest)
|
||||
type fakeContext struct{}
|
||||
|
||||
type GatewayGetHandler struct {
|
||||
requestBucketChan chan BucketRequest
|
||||
config GatewayConfig
|
||||
}
|
||||
|
||||
// GET requests server
|
||||
@ -48,7 +49,7 @@ func (handler GatewayGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ
|
||||
path := vars["path"]
|
||||
context := fakeContext{}
|
||||
callback := make(chan Bucket)
|
||||
handler.requestBucketChan <- BucketRequest{
|
||||
handler.config.requestBucketChan <- BucketRequest{
|
||||
name: bucketName,
|
||||
context: context,
|
||||
callback: callback,
|
||||
@ -65,7 +66,7 @@ func (handler GatewayGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ
|
||||
}
|
||||
|
||||
type GatewayPutHandler struct {
|
||||
requestBucketChan chan BucketRequest
|
||||
config GatewayConfig
|
||||
}
|
||||
|
||||
func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
@ -75,7 +76,7 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ
|
||||
object, _ := ioutil.ReadAll(req.Body)
|
||||
context := fakeContext{}
|
||||
callback := make(chan Bucket)
|
||||
handler.requestBucketChan <- BucketRequest{
|
||||
handler.config.requestBucketChan <- BucketRequest{
|
||||
name: bucketName,
|
||||
context: context,
|
||||
callback: callback,
|
||||
@ -85,17 +86,17 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ
|
||||
}
|
||||
|
||||
func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) {
|
||||
requestBucketChan := make(chan BucketRequest)
|
||||
go SynchronizedBucketService(requestBucketChan, config)
|
||||
getHandler := GatewayGetHandler{requestBucketChan: requestBucketChan}
|
||||
putHandler := GatewayPutHandler{requestBucketChan: requestBucketChan}
|
||||
config.requestBucketChan = make(chan BucketRequest)
|
||||
go SynchronizedBucketService(config)
|
||||
getHandler := GatewayGetHandler{config}
|
||||
putHandler := GatewayPutHandler{config}
|
||||
router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET")
|
||||
router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT")
|
||||
}
|
||||
|
||||
func SynchronizedBucketService(input chan BucketRequest, config GatewayConfig) {
|
||||
func SynchronizedBucketService(config GatewayConfig) {
|
||||
buckets := make(map[string]*SynchronizedBucket)
|
||||
for request := range input {
|
||||
for request := range config.requestBucketChan {
|
||||
if buckets[request.name] == nil {
|
||||
bucketChannel := make(chan ObjectRequest)
|
||||
go config.StorageDriver(request.name, bucketChannel)
|
||||
|
@ -57,15 +57,18 @@ func (s *MySuite) TestPrintsGateway(c *C) {
|
||||
type TestContext struct{}
|
||||
|
||||
func (s *MySuite) TestBucketCreation(c *C) {
|
||||
requestBucketChan := make(chan BucketRequest)
|
||||
defer close(requestBucketChan)
|
||||
go SynchronizedBucketService(requestBucketChan, GatewayConfig{StorageDriver: InMemoryStorageDriver})
|
||||
config := GatewayConfig{
|
||||
StorageDriver: InMemoryStorageDriver,
|
||||
requestBucketChan: make(chan BucketRequest),
|
||||
}
|
||||
defer close(config.requestBucketChan)
|
||||
go SynchronizedBucketService(config)
|
||||
context := TestContext{}
|
||||
|
||||
// get new bucket A
|
||||
var bucketA1 Bucket
|
||||
callback := make(chan Bucket)
|
||||
requestBucketChan <- BucketRequest{
|
||||
config.requestBucketChan <- BucketRequest{
|
||||
name: "bucketA",
|
||||
context: context,
|
||||
callback: callback,
|
||||
@ -76,7 +79,7 @@ func (s *MySuite) TestBucketCreation(c *C) {
|
||||
// get bucket A again
|
||||
var bucketA2 Bucket
|
||||
callback = make(chan Bucket)
|
||||
requestBucketChan <- BucketRequest{
|
||||
config.requestBucketChan <- BucketRequest{
|
||||
name: "bucketA",
|
||||
context: context,
|
||||
callback: callback,
|
||||
@ -88,7 +91,7 @@ func (s *MySuite) TestBucketCreation(c *C) {
|
||||
// get new bucket B
|
||||
var bucketB Bucket
|
||||
callback = make(chan Bucket)
|
||||
requestBucketChan <- BucketRequest{
|
||||
config.requestBucketChan <- BucketRequest{
|
||||
name: "bucketB",
|
||||
context: context,
|
||||
callback: callback,
|
||||
@ -99,14 +102,17 @@ func (s *MySuite) TestBucketCreation(c *C) {
|
||||
|
||||
func (s *MySuite) TestInMemoryBucketOperations(c *C) {
|
||||
// Test in memory bucket operations
|
||||
requestBucketChan := make(chan BucketRequest)
|
||||
defer close(requestBucketChan)
|
||||
go SynchronizedBucketService(requestBucketChan, GatewayConfig{StorageDriver: InMemoryStorageDriver})
|
||||
config := GatewayConfig{
|
||||
StorageDriver: InMemoryStorageDriver,
|
||||
requestBucketChan: make(chan BucketRequest),
|
||||
}
|
||||
defer close(config.requestBucketChan)
|
||||
go SynchronizedBucketService(config)
|
||||
context := TestContext{}
|
||||
|
||||
// get bucket
|
||||
callback := make(chan Bucket)
|
||||
requestBucketChan <- BucketRequest{
|
||||
config.requestBucketChan <- BucketRequest{
|
||||
name: "bucket",
|
||||
context: context,
|
||||
callback: callback,
|
||||
|
Loading…
Reference in New Issue
Block a user