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

created WebhookHandler func

parent 2590a0fa
No related branches found
No related tags found
No related merge requests found
package assignment2
import (
"encoding/json"
"fmt"
"net/http"
)
var webhooks []WebhookRegistration //Webhook DB
func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
webhook := WebhookRegistration{}
err := json.NewDecoder(r.Body).Decode(&webhook)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
webhooks = append(webhooks, webhook)
fmt.Fprintln(w, len(webhooks)-1)
fmt.Println("Webhooks " + webhook.URL + " has been regstrerd")
case http.MethodGet:
err := json.NewEncoder(w).Encode(webhooks)
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
default:
http.Error(w, "Method is invalid "+r.Method, http.StatusBadRequest)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment