-
Notifications
You must be signed in to change notification settings - Fork 61
/
main.go
58 lines (49 loc) · 2.17 KB
/
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
49
50
51
52
53
54
55
56
57
58
package main
import (
"os"
"github.com/namsral/flag"
log "github.com/sirupsen/logrus"
"github.com/smocker-dev/smocker/server"
"github.com/smocker-dev/smocker/server/config"
)
var appName, buildVersion, buildCommit, buildDate string // nolint
func parseConfig() (c config.Config) {
c.Build = config.Build{
AppName: appName,
BuildVersion: buildVersion,
BuildCommit: buildCommit,
BuildDate: buildDate,
}
// Use a prefix for environment variables
flag.CommandLine = flag.NewFlagSetWithEnvPrefix(os.Args[0], "SMOCKER", flag.ExitOnError)
flag.StringVar(&c.LogLevel, "log-level", "info", "Available levels: panic, fatal, error, warning, info, debug, trace")
flag.StringVar(&c.ConfigBasePath, "config-base-path", "/", "Base path applied to Smocker UI")
flag.IntVar(&c.ConfigListenPort, "config-listen-port", 8081, "Listening port of Smocker administration server")
flag.IntVar(&c.MockServerListenPort, "mock-server-listen-port", 8080, "Listening port of Smocker mock server")
flag.StringVar(&c.StaticFiles, "static-files", "client", "Location of the static files to serve (index.html, etc.)")
flag.IntVar(&c.HistoryMaxRetention, "history-retention", 0, "Maximum number of calls to keep in the history per session (0 = no limit)")
flag.StringVar(&c.PersistenceDirectory, "persistence-directory", "", "If defined, the directory where the sessions will be synchronized")
flag.BoolVar(&c.TLSEnable, "tls-enable", false, "Enable TLS using the provided certificate")
flag.StringVar(&c.TLSCertFile, "tls-cert-file", "/etc/smocker/tls/certs/cert.pem", "Path to TLS certificate file ")
flag.StringVar(&c.TLSKeyFile, "tls-private-key-file", "/etc/smocker/tls/private/key.pem", "Path to TLS key file")
flag.Parse()
return
}
func setupLogger(logLevel string) {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
QuoteEmptyFields: true,
})
level, err := log.ParseLevel(logLevel)
if err != nil {
log.WithError(err).WithField("log-level", level).Warn("Invalid log level, fallback to info")
level = log.InfoLevel
}
log.WithField("log-level", level).Info("Setting log level")
log.SetLevel(level)
}
func main() {
c := parseConfig()
setupLogger(c.LogLevel)
server.Serve(c)
}