-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
62 lines (52 loc) · 1.33 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
// Main entry point of the application and the composition root.
package main
import (
"encoding/json"
"fmt"
"net/http"
"turboenigma/handler"
"turboenigma/model"
"turboenigma/provider"
)
func InitEnvironment() *Env {
env, err := NewEnv([]string{
"HTTP_PORT",
"MESSAGE",
"NOTIFICATION_RULES",
"REACTION_RULES",
"SLACK_AVATAR_URL",
"SLACK_USERNAME",
"SLACK_TOKEN",
})
if err != nil {
panic(err)
}
return env
}
func main() {
EnvManager = InitEnvironment()
var notificationRules []model.NotificationRule
if err := json.Unmarshal([]byte(EnvManager.Get("NOTIFICATION_RULES")), ¬ificationRules); err != nil {
panic(err)
}
var reactionRules []model.ReactionRule
if err := json.Unmarshal([]byte(EnvManager.Get("REACTION_RULES")), &reactionRules); err != nil {
panic(err)
}
slack := provider.NewSlack(
http.DefaultClient,
notificationRules,
reactionRules,
EnvManager.Get("SLACK_TOKEN"),
EnvManager.Get("MESSAGE"),
EnvManager.Get("SLACK_AVATAR_URL"),
EnvManager.Get("SLACK_USERNAME"),
)
http.HandleFunc("/", handler.NewGitlab(slack).ServeHTTP)
http.HandleFunc("/healthcheck", handler.NewHealthCheck().ServeHTTP)
address := fmt.Sprintf("0.0.0.0:%s", EnvManager.Get("HTTP_PORT"))
fmt.Println("Server listening on", address)
if err := http.ListenAndServe(address, nil); err != nil {
panic(err)
}
}