minio/main.go

74 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
2015-01-29 01:07:53 +01:00
"log"
2015-01-29 04:52:30 +01:00
"os"
2015-01-29 01:07:53 +01:00
2015-01-29 04:52:30 +01:00
"github.com/codegangsta/cli"
"github.com/minio-io/minio/pkg/server"
)
func main() {
2015-01-29 04:52:30 +01:00
app := cli.NewApp()
app.Name = "minio"
app.Usage = ""
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "http-address,a",
Value: ":8080",
Usage: "http address to listen on",
},
cli.StringFlag{
Name: "cert,c",
Value: "",
Usage: "cert.pem",
},
cli.StringFlag{
Name: "key,k",
Value: "",
Usage: "key.pem",
},
cli.StringFlag{
Name: "storage-type,s",
Value: "file",
Usage: "valid entries: file,inmemory",
},
}
2015-01-29 04:52:30 +01:00
app.Action = func(c *cli.Context) {
storageTypeStr := c.String("storage-type")
address := c.String("http-address")
log.Println(address)
certFile := c.String("cert")
keyFile := c.String("key")
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
log.Fatal("Both certificate and key must be provided to enable https")
}
2015-01-29 10:18:00 +01:00
tls := (certFile != "" && keyFile != "")
2015-01-29 04:52:30 +01:00
storageType := getStorageType(storageTypeStr)
serverConfig := server.ServerConfig{
Address: address,
Tls: tls,
CertFile: certFile,
KeyFile: keyFile,
StorageType: storageType,
}
server.Start(serverConfig)
}
app.Run(os.Args)
}
2015-01-29 01:07:53 +01:00
func getStorageType(input string) server.StorageType {
switch {
case input == "file":
return server.FileStorage
2015-01-29 01:07:53 +01:00
case input == "inmemory":
return server.InMemoryStorage
default:
{
log.Println("Unknown storage type:", input)
log.Println("Choosing default storage type as 'file'..")
return server.FileStorage
2015-01-29 01:07:53 +01:00
}
}
}