-
Notifications
You must be signed in to change notification settings - Fork 0
/
beethoven.go
76 lines (63 loc) · 1.59 KB
/
beethoven.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
package main
import (
"fmt"
"github.com/ContainX/beethoven/config"
"github.com/ContainX/beethoven/proxy"
"github.com/ContainX/depcon/pkg/logger"
"github.com/op/go-logging"
"github.com/spf13/cobra"
"os"
)
const (
Usage = `
Beethoven (Mesos/Marathon HTTP based Proxy)
== Version: %s - Built: %s ==
`
Example = `
Environment : BT_MARATHON_URLS=http://host:8080,http://host2 beethoven serve
Local Config : beethoven serve --config filepath
Remote Config : beethoven serve --remote http://confighost --name myapp --profile prod
`
)
var (
/* LDFlags */
version = "-"
built = ""
/* CLI commands */
rootCmd = &cobra.Command{
Use: "beethoven [config-file | remote-server-url]",
Short: "Mesos/Marathon HTTP based Proxy",
Long: fmt.Sprintf(Usage, version, built),
Example: Example,
}
serveCmd = &cobra.Command{
Use: "serve",
Short: "Start serving traffic",
Run: serve,
Example: Example,
}
// Logger
log = logger.GetLogger("beethoven")
format = logging.MustStringFormatter("%{time:2006-01-02 15:04:05} %{level:.9s} [%{module}]: %{message}")
)
func serve(cmd *cobra.Command, args []string) {
config, err := config.LoadConfigFromCommand(cmd)
if err != nil {
log.Fatal(err.Error())
}
config.Version = version
proxy.New(config).Serve()
}
func main() {
setupLogging()
rootCmd.AddCommand(serveCmd)
config.AddFlags(serveCmd)
rootCmd.Execute()
}
func setupLogging() {
if os.Getenv("DOCKER_ENV") != "" {
backend := logging.NewLogBackend(os.Stderr, "", 0)
backendFmt := logging.NewBackendFormatter(backend, format)
logging.SetBackend(backendFmt)
}
}