forked from spacecloud-io/space-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (71 loc) · 1.49 KB
/
main.go
File metadata and controls
82 lines (71 loc) · 1.49 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
"github.com/spaceuptech/space-cloud/config"
)
func main() {
app := cli.NewApp()
app.Version = buildVersion
app.Name = "space-cloud"
app.Usage = "core binary to run space cloud"
app.Commands = []cli.Command{
{
Name: "run",
Usage: "runs the space cloud instance",
Action: actionRun,
Flags: []cli.Flag{
cli.StringFlag{
Name: "port",
Value: "8080",
Usage: "Start HTTP server on port `PORT`",
},
cli.StringFlag{
Name: "config",
Value: "none",
Usage: "Load space cloud config from `FILE`",
},
cli.BoolFlag{
Name: "prod",
Usage: "Run space-cloud in production mode",
EnvVar: "PROD",
},
},
},
{
Name: "init",
Usage: "creates a confg file with sensible defaults",
Action: actionInit,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func actionRun(c *cli.Context) error {
// Load cli flags
port := c.String("port")
configPath := c.String("config")
isProd := c.Bool("prod")
// Project and env cannot be changed once space cloud has started
s := initServer(isProd)
if configPath != "none" {
config, err := config.LoadConfigFromFile(configPath)
if err != nil {
return err
}
err = s.loadConfig(config)
if err != nil {
return err
}
}
s.routes()
fmt.Println("Starting server on port " + port)
return s.start(port)
}
func actionInit(c *cli.Context) error {
return config.GenerateConfig()
}