-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
59 lines (48 loc) · 1.6 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
package main
import (
"os"
"time"
"github.com/linkai-io/am/pkg/webhooks"
"github.com/go-chi/chi"
"github.com/linkai-io/am/am"
"github.com/linkai-io/am/pkg/lb/consul"
"github.com/linkai-io/frontend/api/console/event"
"github.com/linkai-io/frontend/pkg/initializers"
"github.com/linkai-io/frontend/pkg/middleware"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/wirepair/gateway"
)
var eventClient am.EventService
var hooks webhooks.Webhooker
func init() {
zerolog.TimeFieldFormat = ""
log.Logger = log.With().Str("lambda", "Event").Logger()
consulAddr := os.Getenv("CONSUL_HTTP_ADDR")
consul.RegisterDefault(time.Second*5, consulAddr) // Address comes from CONSUL_HTTP_ADDR or from aws metadata
eventClient = initializers.EventClient()
env := os.Getenv("APP_ENV")
region := os.Getenv("APP_REGION")
hooks = webhooks.New(env, region)
if err := hooks.Init(); err != nil {
log.Fatal().Err(err).Msg("failed to initialize webhooks")
}
}
func main() {
r := chi.NewRouter()
r.Use(middleware.UserCtx)
eventHandlers := event.New(eventClient, hooks)
r.Route("/event", func(r chi.Router) {
r.Get("/group/{id}/events", eventHandlers.Get)
r.Patch("/group/{id}/events", eventHandlers.MarkRead)
r.Post("/group/{id}/webhooks", eventHandlers.UpdateWebhooks)
r.Get("/settings", eventHandlers.GetSettings)
r.Patch("/settings", eventHandlers.UpdateSettings)
r.Post("/webhook_test", eventHandlers.SendTestWebhookEvent)
r.Get("/webhook_events", eventHandlers.GetLastWebhookEvents)
})
err := gateway.ListenAndServe(":3000", r)
if err != nil {
log.Fatal().Err(err).Msg("failed to serve")
}
}