-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
49 lines (37 loc) · 945 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
package main
import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
ev "github.com/mchmarny/gcputil/env"
mt "github.com/mchmarny/gcputil/metric"
pj "github.com/mchmarny/gcputil/project"
)
var (
logger = log.New(os.Stdout, "", 0)
projectID = pj.GetIDOrFail()
port = ev.MustGetEnvVar("PORT", "8080")
topicName = ev.MustGetEnvVar("TOPIC", "preprocessd")
webHookSecret = ev.MustGetEnvVar("HOOK_SECRET", "")
metricsClient *mt.Client
)
func main() {
ctx := context.Background()
m, err := mt.NewClient(ctx)
if err != nil {
logger.Fatalf("Error creating metrics client : %v", err)
}
metricsClient = m
initQueue(ctx)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "ok")
})
http.HandleFunc("/v1/github", gitHubEventHandler)
hostPort := net.JoinHostPort("0.0.0.0", port)
if err := http.ListenAndServe(hostPort, nil); err != nil {
logger.Fatal(err)
}
}