From 0132c299bd6799fcc05dde45c477033dbc659c23 Mon Sep 17 00:00:00 2001 From: Hans Kristian Hoel <hanskhoe@stud.ntnu.no> Date: Thu, 31 Oct 2019 13:20:08 +0100 Subject: [PATCH] createt structs for webhooks --- assignment2/cmd/main.go | 2 +- assignment2/language.go | 1 - assignment2/structs.go | 13 +++++++++++++ assignment2/webhook.go | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/assignment2/cmd/main.go b/assignment2/cmd/main.go index 20225de..4db0c41 100644 --- a/assignment2/cmd/main.go +++ b/assignment2/cmd/main.go @@ -23,7 +23,7 @@ func main() { http.HandleFunc("/repocheck/v1/commits", assignment2.HandlerCommits) // runs handelr function http.HandleFunc("/repocheck/v1/languages", assignment2.HandlerLanguages) // runs handelr function http.HandleFunc("/repocheck/v1/status", assignment2.HandlerStatus) // runs handelr function - // http.HandleFunc("/repocheck/v1/webhooks", assignment2.HandlerWebhooks) // runs handelr function + http.HandleFunc("/repocheck/v1/webhooks", assignment2.WebhookHandeler) // runs handelr function fmt.Println("Listening on port " + port) log.Fatal(http.ListenAndServe(":"+port, nil)) } diff --git a/assignment2/language.go b/assignment2/language.go index 4597513..a38bc12 100644 --- a/assignment2/language.go +++ b/assignment2/language.go @@ -11,7 +11,6 @@ import ( func Counter(S []string) map[string]int { - //List := strings.Fields(S) count := make(map[string]int) for _, Lang := range S { _, ok := count[Lang] diff --git a/assignment2/structs.go b/assignment2/structs.go index b9f44a5..9e703bb 100644 --- a/assignment2/structs.go +++ b/assignment2/structs.go @@ -51,3 +51,16 @@ type WebhookRegistration struct { Event string `json:"event"` URL string `json:"urk2` } + +type Webhooks struct { + ID int `json:"id"` + Event string `json:"Event"` + URL string `json:"url"` + Time float64 `json:"time"` +} + +type WebhooksInvocation struct { + Event string `json:"event"` + Params []string `json:"params"` + Time float64 `json:"time"` +} diff --git a/assignment2/webhook.go b/assignment2/webhook.go index 2eb2298..b963bdb 100644 --- a/assignment2/webhook.go +++ b/assignment2/webhook.go @@ -50,6 +50,7 @@ func ServiceHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Method is invalid "+r.Method, http.StatusBadRequest) } } + func CallUrl(url string, content string) { fmt.Println("Attempting invocation of url " + url + "...") res, err := http.Post(url, "string", bytes.NewReader([]byte(content))) -- GitLab