-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (65 loc) · 2.47 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"os"
"os/signal"
"syscall"
"veidemann-scopeservice/pkg/logger"
"veidemann-scopeservice/pkg/script"
"veidemann-scopeservice/pkg/server"
"veidemann-scopeservice/pkg/telemetry"
"github.com/opentracing/opentracing-go"
"github.com/rs/zerolog/log"
"strings"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
func main() {
pflag.String("interface", "", "interface the browser controller api listens to. No value means all interfaces.")
pflag.Int("port", 8080, "port the browser controller api listens to.")
pflag.Bool("include-fragment", false, "if true, do not remove fragment from URI during canonicalization.")
pflag.String("metrics-interface", "", "Interface for exposing metrics. Empty means all interfaces")
pflag.Int("metrics-port", 9153, "Port for exposing metrics")
pflag.String("metrics-path", "/metrics", "Path for exposing metrics")
pflag.String("log-level", "info", "log level, available levels are panic, fatal, error, warn, info, debug and trace")
pflag.String("log-formatter", "logfmt", "log formatter, available values are logfmt and json")
pflag.Bool("log-method", false, "log method names")
pflag.Parse()
_ = viper.BindPFlags(pflag.CommandLine)
viper.SetDefault("ContentDir", "content")
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
log.Fatal().Err(err).Msg("Could not parse flags")
}
logger.InitLog(viper.GetString("log-level"), viper.GetString("log-formatter"), viper.GetBool("log-method"))
script.InitializeCanonicalizationProfiles(viper.GetBool("include-fragment"))
scopeservice := server.New(viper.GetString("interface"), viper.GetInt("port"))
// telemetry setup
tracer, closer := telemetry.InitTracer("Scope checker")
if tracer != nil {
opentracing.SetGlobalTracer(tracer)
defer closer.Close()
}
errc := make(chan error, 1)
ms := telemetry.NewMetricsServer(viper.GetString("metrics-interface"), viper.GetInt("metrics-port"), viper.GetString("metrics-path"))
go func() { errc <- ms.Start() }()
defer ms.Close()
go func() {
signals := make(chan os.Signal, 2)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
select {
case err := <-errc:
log.Err(err).Msg("Metrics server failed")
scopeservice.Shutdown()
case sig := <-signals:
log.Debug().Msgf("Received signal: %scopeservice", sig)
scopeservice.Shutdown()
}
}()
err = scopeservice.Start()
if err != nil {
log.Err(err).Msg("")
}
}