-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (50 loc) · 1.67 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"os"
conf "github.com/ssdowd/couchbasebroker/config"
utils "github.com/ssdowd/couchbasebroker/utils"
webs "github.com/ssdowd/couchbasebroker/web_server"
)
// Options represents the options passed to main.
type Options struct {
ConfigPath string
Cloud string
CloudOptionsPath string
}
var options Options
func init() {
defaultConfigPath := utils.GetPath([]string{"assets", "config.json"})
defaultCloudOptsPath := utils.GetPath([]string{"assets", "boshconfig.json"})
flag.StringVar(&options.ConfigPath, "config", defaultConfigPath, "use '--config' option to specify the config file path")
flag.StringVar(&options.Cloud, "service", utils.BOSH, "use '--service' option to specify the cloud client to use: DOCKER, Bosh, AWS or SoftLayer (SL)")
flag.StringVar(&options.CloudOptionsPath, "copts", defaultCloudOptsPath, "use '--copts' option to specify the specific cloud options file")
flag.Parse()
}
func main() {
err := checkCloudName(options.Cloud)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
utils.Logger.Printf("Cloud: %v\n", options.Cloud)
utils.Logger.Printf("Config Path: %v\n", options.ConfigPath)
_, err = conf.LoadConfig(options.ConfigPath)
if err != nil {
panic(fmt.Sprintf("Error loading config file [%v]...", err))
}
server, err := webs.CreateServer(options.Cloud, options.CloudOptionsPath)
if err != nil {
panic(fmt.Sprintf("Error creating server [%v]...", err))
}
server.Start()
}
// Private func
func checkCloudName(name string) error {
switch name {
case utils.DOCKER, utils.AWS, utils.SOFTLAYER, utils.SL, utils.BOSH:
return nil
}
return fmt.Errorf("Invalid cloud name: %s", name)
}