-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
78 lines (63 loc) · 1.68 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
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
"dev.sum7.eu/genofire/golang-lib/file"
"github.com/bdlm/log"
"gosrc.io/xmpp"
_ "dev.sum7.eu/sum7/hook2xmpp/circleci"
_ "dev.sum7.eu/sum7/hook2xmpp/git"
_ "dev.sum7.eu/sum7/hook2xmpp/gitlab"
_ "dev.sum7.eu/sum7/hook2xmpp/grafana"
_ "dev.sum7.eu/sum7/hook2xmpp/prometheus"
"dev.sum7.eu/sum7/hook2xmpp/runtime"
)
var config = runtime.Config{}
func main() {
configFile := "config.conf"
flag.StringVar(&configFile, "config", configFile, "path of configuration file")
flag.Parse()
if err := file.ReadTOML(configFile, &config); err != nil {
log.WithField("tip", "maybe call me with: hook2xmpp--config /etc/hook2xmpp.conf").Panicf("error on read config: %s", err)
}
log.SetLevel(config.LogLevel)
router := xmpp.NewRouter()
var err error
client, err := xmpp.NewClient(xmpp.Config{
Address: config.XMPP.Address,
Jid: config.XMPP.JID,
Password: config.XMPP.Password,
}, router)
if err != nil {
log.Panicf("error on startup xmpp client: %s", err)
}
cm := xmpp.NewStreamManager(client, postStartup)
go func() {
err := cm.Run()
log.Panic("closed connection:", err)
}()
for hookType, getHandler := range runtime.HookRegister {
hooks, ok := config.Hooks[hookType]
if ok {
http.HandleFunc("/"+hookType, getHandler(client, hooks))
}
}
srv := &http.Server{
Addr: config.WebserverBind,
}
go func() {
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
panic(err)
}
}()
// Wait for system signal
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
closeXMPP(client)
srv.Close()
log.Infof("closed by receiving: %s", sig)
}