7 "github.com/jhalter/mobius"
9 "go.uber.org/zap/zapcore"
14 defaultConfigPath = "/usr/local/var/mobius/config/" // matches Homebrew default config location
19 ctx, cancelRoot := context.WithCancel(context.Background())
21 basePort := flag.Int("bind", defaultPort, "Bind address and port")
22 configDir := flag.String("config", defaultConfigPath, "Path to config root")
23 version := flag.Bool("version", false, "print version and exit")
24 logLevel := flag.String("log-level", "info", "Log level")
28 fmt.Printf("v%s\n", hotline.VERSION)
32 zapLvl, ok := zapLogLevel[*logLevel]
34 fmt.Printf("Invalid log level %s. Must be debug, info, warn, or error.\n", *logLevel)
38 cores := []zapcore.Core{newStdoutCore(zapLvl)}
39 l := zap.New(zapcore.NewTee(cores...))
40 defer func() { _ = l.Sync() }()
43 if _, err := os.Stat(*configDir); os.IsNotExist(err) {
44 logger.Fatalw("Configuration directory not found", "path", configDir)
47 srv, err := hotline.NewServer(*configDir, "", *basePort, logger)
52 // Serve Hotline requests until program exit
53 logger.Fatal(srv.ListenAndServe(ctx, cancelRoot))
56 func newStdoutCore(level zapcore.Level) zapcore.Core {
57 encoderCfg := zap.NewProductionEncoderConfig()
58 encoderCfg.TimeKey = "timestamp"
59 encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
61 return zapcore.NewCore(
62 zapcore.NewConsoleEncoder(encoderCfg),
63 zapcore.Lock(os.Stdout),
68 var zapLogLevel = map[string]zapcore.Level{
69 "debug": zap.DebugLevel,
70 "info": zap.InfoLevel,
71 "warn": zap.WarnLevel,
72 "error": zap.ErrorLevel,