-
Notifications
You must be signed in to change notification settings - Fork 25
/
server.go
72 lines (66 loc) · 1.75 KB
/
server.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
66
67
68
69
70
71
72
package cmd
import (
"github.com/thecasualcoder/dobby/pkg/server"
"github.com/urfave/cli"
"strconv"
"time"
)
func serverCmd() cli.Command {
return cli.Command{
Name: "server",
Description: "run dobby in server mode",
Usage: "run dobby server",
Action: runServer,
Flags: serverFlags(),
}
}
func serverFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "bind-address, a",
Value: "127.0.0.1",
Usage: "Address of dobby server.",
EnvVar: "BIND_ADDR",
},
cli.StringFlag{
Name: "port, p",
Value: "4444",
Usage: "Port which will be used by dobby server.",
EnvVar: "PORT",
},
cli.StringFlag{
Name: "initial-health",
EnvVar: "INITIAL_HEALTH",
Usage: "Sets the Initial health of the server (/health) (true|false)",
Value: "true",
},
cli.StringFlag{
Name: "initial-readiness",
EnvVar: "INITIAL_READINESS",
Usage: "Sets the Initial readiness of the server (/readiness) (true|false)",
Value: "true",
},
cli.Int64Flag{
Name: "initial-delay",
EnvVar: "INITIAL_DELAY",
Usage: "Sets the Initial delay to start the server (in seconds)",
Value: 0,
},
}
}
func runServer(context *cli.Context) {
bindAddress := context.String("bind-address")
port := context.String("port")
initialDelay := time.Duration(context.Int64("initial-delay")) * time.Second
time.Sleep(initialDelay)
initialHealth := true
if health, err := strconv.ParseBool(context.String("initial-health")); err == nil {
initialHealth = health
}
initialReadiness := true
if readiness, err := strconv.ParseBool(context.String("initial-readiness")); err == nil {
initialReadiness = readiness
}
err := server.Run(bindAddress, port, initialHealth, initialReadiness)
dieIf(err)
}