Merge pull request #84 from fkautz/pr_out_adding_server_config_structure

master
Frederick F. Kautz IV 10 years ago
commit 0225c51238
  1. 31
      main.go
  2. 35
      pkg/server/server.go

@ -1,13 +1,15 @@
package main package main
import ( import (
"log"
"github.com/minio-io/minio/pkg/server" "github.com/minio-io/minio/pkg/server"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func main() { func main() {
var tls bool var tls bool
var inmemory bool var storageTypeStr string
var address string var address string
var certFile string var certFile string
var keyFile string var keyFile string
@ -16,13 +18,36 @@ func main() {
Short: "minio is a minimal object storage system", Short: "minio is a minimal object storage system",
Long: "", Long: "",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
server.Start(address, tls, certFile, keyFile, inmemory) storageType := getStorageType(storageTypeStr)
serverConfig := server.ServerConfig{
Address: address,
Tls: tls,
CertFile: certFile,
KeyFile: keyFile,
StorageType: storageType,
}
server.Start(serverConfig)
}, },
} }
minioCommand.PersistentFlags().BoolVarP(&tls, "tls", "t", false, "enable tls") minioCommand.PersistentFlags().BoolVarP(&tls, "tls", "t", false, "enable tls")
minioCommand.PersistentFlags().BoolVarP(&inmemory, "inmemory", "m", false, "in memory object storage") minioCommand.PersistentFlags().StringVarP(&storageTypeStr, "storage-type", "s", "file", "file,inmemory")
minioCommand.PersistentFlags().StringVarP(&address, "http-address", "a", ":8080", "http address") minioCommand.PersistentFlags().StringVarP(&address, "http-address", "a", ":8080", "http address")
minioCommand.PersistentFlags().StringVarP(&certFile, "cert", "c", "", "cert file path") minioCommand.PersistentFlags().StringVarP(&certFile, "cert", "c", "", "cert file path")
minioCommand.PersistentFlags().StringVarP(&keyFile, "key", "k", "", "key file path") minioCommand.PersistentFlags().StringVarP(&keyFile, "key", "k", "", "key file path")
minioCommand.Execute() minioCommand.Execute()
} }
func getStorageType(input string) server.StorageType {
switch {
case input == "file":
return server.InMemoryStorage
case input == "inmemory":
return server.InMemoryStorage
default:
{
log.Fatal("Unknown server type:", input)
// needed for compile, should never return after fatal log msg
return server.InMemoryStorage
}
}
}

@ -30,7 +30,22 @@ import (
"github.com/minio-io/minio/pkg/webapi/minioapi" "github.com/minio-io/minio/pkg/webapi/minioapi"
) )
func Start(hostname string, tls bool, certFile, keyFile string, inMemoryStorage bool) { type ServerConfig struct {
Address string
Tls bool
CertFile string
KeyFile string
StorageType StorageType
}
type StorageType int
const (
InMemoryStorage = iota
FileStorage
)
func Start(config ServerConfig) {
var ctrlChans []chan<- string var ctrlChans []chan<- string
var statusChans []<-chan error var statusChans []<-chan error
@ -38,21 +53,21 @@ func Start(hostname string, tls bool, certFile, keyFile string, inMemoryStorage
var statusChan <-chan error var statusChan <-chan error
var storage mstorage.Storage var storage mstorage.Storage
var srv = httpserver.HttpServer{} var srv = httpserver.HttpServer{}
srv.Address = hostname srv.Address = config.Address
srv.TLS = tls srv.TLS = config.Tls
if certFile != "" { if config.CertFile != "" {
srv.CertFile = certFile srv.CertFile = config.CertFile
} }
if keyFile != "" { if config.KeyFile != "" {
srv.KeyFile = keyFile srv.KeyFile = config.KeyFile
} }
if inMemoryStorage { if config.StorageType == InMemoryStorage {
ctrlChan, statusChan, storage = inmemory.Start() ctrlChan, statusChan, storage = inmemory.Start()
ctrlChans = append(ctrlChans, ctrlChan) ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan) statusChans = append(statusChans, statusChan)
} else { } else if config.StorageType == FileStorage {
currentUser, err := user.Current() currentUser, err := user.Current()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -67,6 +82,8 @@ func Start(hostname string, tls bool, certFile, keyFile string, inMemoryStorage
ctrlChan, statusChan, storage = fs.Start(rootPath) ctrlChan, statusChan, storage = fs.Start(rootPath)
ctrlChans = append(ctrlChans, ctrlChan) ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan) statusChans = append(statusChans, statusChan)
} else {
} }
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv) ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv)

Loading…
Cancel
Save