forked from launchdarkly/ld-relay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (43 loc) · 937 Bytes
/
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
package main
import (
"errors"
"fmt"
"net/http"
"os"
"strconv"
)
func runServiceCommand(commandName string, portStr string) error {
var handler http.Handler
switch commandName {
case "streamer":
handler = streamerEndpointHandler()
default:
return errors.New("unknown service name")
}
port, err := strconv.Atoi(portStr)
if err != nil {
return errors.New("invalid port")
}
return runService(port, handler)
}
func maybeError(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func main() {
switch {
case len(os.Args) == 4 && os.Args[1] == "exec":
maybeError(runServiceCommand(os.Args[2], os.Args[3]))
return
case len(os.Args) >= 3 && os.Args[1] == "start":
maybeError(startProcess(os.Args[2], os.Args[3:]))
return
case len(os.Args) == 3 && os.Args[1] == "stop":
maybeError(stopProcess(os.Args[2]))
return
}
fmt.Fprintln(os.Stderr, "see readme for usage")
os.Exit(1)
}