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

fixed the read func for fb so i dident create duplicate to webhooks slice. And...

fixed the read func for fb so i dident create duplicate to webhooks slice. And working on get comand for webhooks
parent f3cd7b0b
Branches
No related tags found
No related merge requests found
...@@ -64,6 +64,16 @@ func FBRead() { ...@@ -64,6 +64,16 @@ func FBRead() {
} }
fmt.Println(doc.Data()) fmt.Println(doc.Data())
doc.DataTo(&webhook) doc.DataTo(&webhook)
webhooks = append(webhooks, webhook) tempCount := 0
for i := range webhooks {
if webhooks[i].ID == webhook.ID {
tempCount++
}
}
if tempCount == 0 {
webhooks = append(webhooks, webhook)
}
} }
} }
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
) )
...@@ -40,11 +41,26 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) { ...@@ -40,11 +41,26 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
case http.MethodGet: case http.MethodGet:
FBRead() FBRead()
err := json.NewEncoder(w).Encode(webhooks) http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good
if err != nil { parts := strings.Split(r.URL.Path, "/") //finds url parts
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError) fmt.Println(parts)
if len(parts) == 5 {
tempInt, err := strconv.Atoi(parts[4])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
err = json.NewEncoder(w).Encode(webhooks[tempInt-1])
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
} else {
err := json.NewEncoder(w).Encode(webhooks)
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
} }
//FBRead()
default: default:
http.Error(w, "Method is invalid "+r.Method, http.StatusBadRequest) 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