-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
54 lines (46 loc) · 1.21 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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type Payload struct {
Action string `json:"action"`
Issue struct {
URL string `json:"url"`
RepositoryURL string `json:"repository_url"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
} `json:"issue"`
Repository struct {
Name string `json:"name"`
} `json:"repository"`
}
func status(res http.ResponseWriter, req *http.Request) {
fmt.Fprintf(res, "Hello!")
}
func handleWebhook(res http.ResponseWriter, req *http.Request) {
var Payload Payload
defer req.Body.Close()
decoder := json.NewDecoder(req.Body)
err := decoder.Decode(&Payload)
if err != nil {
http.Error(res, "bad request: "+err.Error(), 400)
log.Printf("bad request: %v", err.Error())
return
}
log.Printf("%#v\n", Payload.Repository.Name)
log.Printf("%#v\n", Payload.Issue.URL)
log.Printf("%#v\n", Payload.Issue.Title)
log.Printf("%#v\n", Payload.Issue.Body)
log.Printf("%#v\n", Payload.Issue.Number)
log.Printf("%#v\n", Payload.Issue.RepositoryURL)
}
func main() {
log.Println("Issuer")
http.HandleFunc("/", status)
http.HandleFunc("/webhook", handleWebhook)
http.ListenAndServe(":3000", nil)
}