-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (36 loc) · 1.02 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/rs/cors"
"github.com/vektorprogrammet/build-system/cli"
"github.com/vektorprogrammet/build-system/handlers"
"os"
"github.com/vektorprogrammet/build-system/messenger"
)
func main() {
keepRunning := cli.HandleArguments()
if !keepRunning {
return
}
secret := os.Getenv("GITHUB_WEBHOOKS_SECRET")
slack := messenger.NewSlack(os.Getenv("SLACK_ENDPOINT"), "#staging_log", "vektorbot", ":robot_face:")
webhooks := handlers.WebhookHandler{
Secret: []byte(secret),
Router: mux.NewRouter().PathPrefix("/webhooks/").Subrouter(),
Messenger: slack,
}
webhooks.InitRoutes()
api := handlers.Api{
Router: mux.NewRouter().PathPrefix("/api/").Subrouter(),
}
api.InitRoutes()
serveMux := http.NewServeMux()
serveMux.Handle("/webhooks/", webhooks.Router)
serveMux.Handle("/api/", api.Router)
handler := cors.Default().Handler(serveMux)
fmt.Println("Listening to webhooks on port 5555")
log.Fatal(http.ListenAndServe(":5555", handler))
}