Skip to content
Snippets Groups Projects
Commit 857667d0 authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

traing to make webhooks work

parent 385b0af1
Branches
No related tags found
No related merge requests found
......@@ -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
......
module assignment2
go 1.13
// +heroku goVersion go1.13
......@@ -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"`
}
......@@ -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)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment