diff --git a/assignment2/commit.go b/assignment2/commit.go index 2fc9bd3c7a8e67c3d03aa7211295275b6ef40e1d..82e7b2226b6f74464452fcdc2eda65b156f21a7b 100644 --- a/assignment2/commit.go +++ b/assignment2/commit.go @@ -7,6 +7,7 @@ import ( "net/http" "sort" "strconv" + "time" ) func HandlerCommits(w http.ResponseWriter, r *http.Request) { @@ -119,8 +120,12 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) { http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good + // Webhooks********************** + Payload := &WebhooksInvocation{} Payload.Event = "Commits" + Payload.Time = time.Now() + Payload.Params = "Limit = " + limit + "and Auth = " + auth json.NewEncoder(w).Encode(C) // encode C diff --git a/assignment2/go.mod b/assignment2/go.mod index 4f590dcf844845cb3c8f2fbbe49568e18f463b35..f87a213ff17858e10f2409a59aa196998ea58108 100644 --- a/assignment2/go.mod +++ b/assignment2/go.mod @@ -1,5 +1,3 @@ module assignment2 go 1.13 - -// +heroku goVersion go1.13 diff --git a/assignment2/structs.go b/assignment2/structs.go index 290d5a2a25b2e6c0079caf1e1f3723b19cc4f955..a81c5f4c128fb3f0a5ed63111b5e4ab3aad19f80 100644 --- a/assignment2/structs.go +++ b/assignment2/structs.go @@ -56,15 +56,15 @@ type WebhookRegistration struct { Time time.Time `json:"time"` } -type Webhooks struct { - ID int `json:"id"` - Event string `json:"Event"` - URL string `json:"url"` - Time float64 `json:"time"` -} +// 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"` + Event string `json:"event"` + Params string `json:"params"` + Time time.Time `json:"time"` } diff --git a/assignment2/webhook.go b/assignment2/webhook.go index 1ca23272aac26d331dcca67577c2ca6c2d6fe4c2..22f04bd7bda766d7e1af5626d8161c85db1bd7ed 100644 --- a/assignment2/webhook.go +++ b/assignment2/webhook.go @@ -13,6 +13,11 @@ import ( var webhooks []WebhookRegistration //Webhook DB var IDNum = 1 +/* + Handles webhook registration (POST) and lookup (GET) requests. + Expects WebhookRegistration struct body in request. +*/ + func WebhookHandeler(w http.ResponseWriter, r *http.Request) { switch r.Method { @@ -44,6 +49,10 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) { } +/* + Invokes the web service to trigger event. Currently only responds to POST requests. +*/ + func ServiceHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { @@ -57,6 +66,10 @@ func ServiceHandler(w http.ResponseWriter, r *http.Request) { } } +/* + Calls given URL with given content and awaits response (status and body). +*/ + func CallUrl(url string, content string) { fmt.Println("Attempting invocation of url " + url + "...") res, err := http.Post(url, "string", bytes.NewReader([]byte(content)))