-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (54 loc) · 1.39 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
package main
import (
"net/http"
"os"
"github.com/ninlil/butler"
"github.com/ninlil/butler/log"
"github.com/ninlil/butler/router"
)
var routes = []router.Route{
{Name: "send", Method: "POST", Path: "/send/{id}", Handler: send},
{Name: "stop", Method: "GET", Path: "/stop", Handler: stop},
}
func main() {
initKafka()
os.Exit(run())
}
func stop() int {
if !settings.AllowStop {
return http.StatusForbidden
}
butler.Quit()
return http.StatusOK
}
func run() int {
if !settings.DryRun {
defer butler.Cleanup(config.Close)
routes = append(routes,
router.Route{Name: "metrics", Method: "GET", Path: "/metrics", Handler: metrics.Init()},
)
err := router.Serve(routes, router.WithPort(settings.Port))
if err != nil {
log.Fatal().Msg(err.Error())
}
}
if !config.Load(settings.Config) {
return 1 // dont want os.Exit here, because then the deferred cleanup wouldn't trigger
}
if settings.Echo != nil {
config.Echo()
return 0
}
if settings.DryRun {
log.Info().Msg("dry-run mode")
return 0
}
if !config.Connect() {
log.Warn().Msg("some integrations failed")
}
config.Listen()
log.Info().Msgf("Reconnection delay: %v +/- %v", settings.ReconnectDelay, settings.ReconnectJitter)
log.Info().Msgf("Stop-command %s", flag2text(settings.AllowStop, "enabled", "disabled"))
butler.Run()
return 0
}