-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.go
61 lines (46 loc) · 1.28 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
package main
import (
"os"
"errors"
"fmt"
"flag"
conf "github.com/cloudfoundry-samples/go_service_broker/config"
webs "github.com/cloudfoundry-samples/go_service_broker/web_server"
utils "github.com/cloudfoundry-samples/go_service_broker/utils"
)
type Options struct {
ConfigPath string
Cloud string
}
var options Options
func init() {
defaultConfigPath := utils.GetPath([]string{"assets", "config.json"})
flag.StringVar(&options.ConfigPath, "c", defaultConfigPath, "use '-c' option to specify the config file path")
flag.StringVar(&options.Cloud, "cloud", utils.AWS, "use '--cloud' option to specify the cloud client to use: AWS or SoftLayer (SL)")
flag.Parse()
}
func main() {
err := checkCloudName(options.Cloud)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
_, err = conf.LoadConfig(options.ConfigPath)
if err != nil {
panic(fmt.Sprintf("Error loading config file [%s]...", err.Error()))
}
server, err := webs.CreateServer(options.Cloud)
if err != nil {
panic(fmt.Sprintf("Error creating server [%s]...", err.Error))
}
server.Start()
}
// Private func
func checkCloudName(name string) error {
fmt.Println(name)
switch name {
case utils.AWS, utils.SOFTLAYER, utils.SL:
return nil
}
return errors.New(fmt.Sprintf("Invalid cloud name: %s", name))
}