|
|
@ -46,47 +46,66 @@ const ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Start(config ServerConfig) { |
|
|
|
func Start(config ServerConfig) { |
|
|
|
|
|
|
|
// maintain a list of input and output channels for communicating with services
|
|
|
|
var ctrlChans []chan<- string |
|
|
|
var ctrlChans []chan<- string |
|
|
|
var statusChans []<-chan error |
|
|
|
var statusChans []<-chan error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// a pair of control channels, we use these primarily to add to the lists above
|
|
|
|
var ctrlChan chan<- string |
|
|
|
var ctrlChan chan<- string |
|
|
|
var statusChan <-chan error |
|
|
|
var statusChan <-chan error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// configure web server
|
|
|
|
var storage mstorage.Storage |
|
|
|
var storage mstorage.Storage |
|
|
|
var srv = httpserver.HttpServer{} |
|
|
|
var httpConfig = httpserver.HttpServerConfig{} |
|
|
|
srv.Address = config.Address |
|
|
|
httpConfig.Address = config.Address |
|
|
|
srv.TLS = config.Tls |
|
|
|
httpConfig.TLS = config.Tls |
|
|
|
|
|
|
|
|
|
|
|
if config.CertFile != "" { |
|
|
|
if config.CertFile != "" { |
|
|
|
srv.CertFile = config.CertFile |
|
|
|
httpConfig.CertFile = config.CertFile |
|
|
|
} |
|
|
|
} |
|
|
|
if config.KeyFile != "" { |
|
|
|
if config.KeyFile != "" { |
|
|
|
srv.KeyFile = config.KeyFile |
|
|
|
httpConfig.KeyFile = config.KeyFile |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if config.StorageType == InMemoryStorage { |
|
|
|
// instantiate storage
|
|
|
|
ctrlChan, statusChan, storage = inmemory.Start() |
|
|
|
// preconditions:
|
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
// - storage type specified
|
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
// - any configuration for storage is populated
|
|
|
|
} else if config.StorageType == FileStorage { |
|
|
|
// postconditions:
|
|
|
|
currentUser, err := user.Current() |
|
|
|
// - storage driver is initialized
|
|
|
|
if err != nil { |
|
|
|
// - ctrlChans has channel to communicate to storage
|
|
|
|
log.Fatal(err) |
|
|
|
// - statusChans has channel for messages coming from storage
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
|
|
case config.StorageType == InMemoryStorage: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ctrlChan, statusChan, storage = inmemory.Start() |
|
|
|
|
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
|
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
} |
|
|
|
} |
|
|
|
rootPath := path.Join(currentUser.HomeDir, "minio-storage") |
|
|
|
case config.StorageType == FileStorage: |
|
|
|
_, err = os.Stat(rootPath) |
|
|
|
{ |
|
|
|
if os.IsNotExist(err) { |
|
|
|
// TODO Replace this with a more configurable and robust version
|
|
|
|
err = os.Mkdir(rootPath, 0700) |
|
|
|
currentUser, err := user.Current() |
|
|
|
} else if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("Could not create $HOME/minio-storage", err) |
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rootPath := path.Join(currentUser.HomeDir, "minio-storage") |
|
|
|
|
|
|
|
_, err = os.Stat(rootPath) |
|
|
|
|
|
|
|
if os.IsNotExist(err) { |
|
|
|
|
|
|
|
err = os.Mkdir(rootPath, 0700) |
|
|
|
|
|
|
|
} else if err != nil { |
|
|
|
|
|
|
|
log.Fatal("Could not create $HOME/minio-storage", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctrlChan, statusChan, storage = fs.Start(rootPath) |
|
|
|
|
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
|
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
} |
|
|
|
} |
|
|
|
ctrlChan, statusChan, storage = fs.Start(rootPath) |
|
|
|
default: // should never happen
|
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
log.Fatal("No storage driver found") |
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv) |
|
|
|
// start minio api in a web server, pass storage driver into it
|
|
|
|
|
|
|
|
ctrlChan, statusChan, _ = httpserver.Start(minioapi.HttpHandler(storage), httpConfig) |
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
ctrlChans = append(ctrlChans, ctrlChan) |
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
statusChans = append(statusChans, statusChan) |
|
|
|
|
|
|
|
|
|
|
|