-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.go
43 lines (35 loc) · 906 Bytes
/
handler.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
package main
import (
"encoding/json"
"io"
"net/http"
)
func gitHubEventHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json")
se, err := parseGitHubWebHook(r)
if err != nil {
logger.Printf("Error while processing WebHook: %v", err)
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "{}")
return
}
if se.Countable {
err = store(r.Context(), se)
if err != nil {
logger.Printf("Error while storing event: %v", err)
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, "{}")
return
}
}
err = metricsClient.Publish(r.Context(), se.Type, "github-event-counter", int64(1))
if err != nil {
logger.Printf("Error while publishing metrics: %v", err)
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, "{}")
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(se)
return
}