-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
59 lines (45 loc) · 910 Bytes
/
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
package main
import (
"net/http"
"os"
"os/signal"
"github.com/kak-tus/healthcheck"
"github.com/kak-tus/loghouse-acceptor/config"
"github.com/kak-tus/loghouse-acceptor/listener"
"go.uber.org/zap"
)
func main() {
logger, err := zap.NewProduction()
if err != nil {
panic(err)
}
log := logger.Sugar()
cnf, err := config.NewConfig()
if err != nil {
log.Panic(err)
}
hlth := healthcheck.NewHandler()
hlth.Add("/healthcheck", func() (healthcheck.State, string) {
return healthcheck.StatePassing, "ok"
})
go func() {
err := http.ListenAndServe(cnf.Healthcheck.Listen, hlth)
if err != nil {
log.Panic(err)
}
}()
lstn, err := listener.NewListener(cnf, log)
if err != nil {
log.Panic(err)
}
lstn.Listen()
st := make(chan os.Signal, 1)
signal.Notify(st, os.Interrupt)
<-st
log.Info("Stop")
err = lstn.Stop()
if err != nil {
log.Panic(err)
}
_ = log.Sync()
}