-
Notifications
You must be signed in to change notification settings - Fork 80
/
ld-relay.go
78 lines (65 loc) · 1.66 KB
/
ld-relay.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
73
74
75
76
77
78
package main
import (
"os"
_ "github.com/kardianos/minwinsvc"
"github.com/launchdarkly/ld-relay/v8/config"
"github.com/launchdarkly/ld-relay/v8/internal/application"
"github.com/launchdarkly/ld-relay/v8/internal/logging"
"github.com/launchdarkly/ld-relay/v8/relay"
"github.com/launchdarkly/ld-relay/v8/relay/version"
)
func main() {
var c config.Config
loggers := logging.MakeDefaultLoggers()
opts, err := application.ReadOptions(os.Args, os.Stderr)
if err != nil {
loggers.Errorf("Error: %s", err)
os.Exit(1)
}
if opts.PrintVersion {
loggers.Infof(
"LaunchDarkly relay version %s\n",
application.DescribeRelayVersion(version.Version),
)
os.Exit(0)
}
loggers.Infof(
"Starting LaunchDarkly relay version %s with %s\n",
application.DescribeRelayVersion(version.Version),
opts.DescribeConfigSource(),
)
if opts.ConfigFile != "" {
if err := config.LoadConfigFile(&c, opts.ConfigFile, loggers); err != nil {
loggers.Errorf("Error loading config file: %s", err)
os.Exit(1)
}
}
if opts.UseEnvironment {
if err := config.LoadConfigFromEnvironment(&c, loggers); err != nil {
loggers.Errorf("Configuration error: %s", err)
os.Exit(1)
}
}
r, err := relay.NewRelay(c, loggers, nil)
if err != nil {
loggers.Errorf("Unable to create relay: %s", err)
os.Exit(1)
}
if c.Main.ExitAlways {
os.Exit(0)
}
port := c.Main.Port.GetOrElse(config.DefaultPort)
_, errs := application.StartHTTPServer(
port,
r,
c.Main.TLSEnabled,
c.Main.TLSCert,
c.Main.TLSKey,
c.Main.TLSMinVersion.Get(),
loggers,
)
for err := range errs {
loggers.Errorf("Error starting http listener on port: %d %s", port, err)
os.Exit(1)
}
}