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

did some commenting

parent 65e231b3
Branches
No related tags found
No related merge requests found
......@@ -63,15 +63,15 @@ func FBRead() {
log.Fatalf("Failed to iterate: %v", err)
}
fmt.Println(doc.Data())
doc.DataTo(&webhook)
tempCount := 0
for i := range webhooks {
if webhooks[i].ID == webhook.ID {
tempCount++
doc.DataTo(&webhook) // sets data in to webhook struct
tempCount := 0 // controll for duplicate
for i := range webhooks { // lopps true webhooks
if webhooks[i].ID == webhook.ID { // cheek it the webhook allready exist
tempCount++ //adds 1
}
}
if tempCount == 0 {
if tempCount == 0 { // if tempCount is 0 it means that there is no duplicats and can add webhook
webhooks = append(webhooks, webhook)
}
......
......@@ -25,16 +25,15 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
err := json.NewDecoder(r.Body).Decode(&webhook)
err := json.NewDecoder(r.Body).Decode(&webhook) //decode to webhook
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
webhook.Time = time.Now()
IDNum++
webhook.Time = time.Now() // sets time stamp
FBSave()
webhooks = append(webhooks, webhook)
FBSave() // saves webhook to firebase
webhooks = append(webhooks, webhook) // saves webhook to webhooks
fmt.Fprintln(w, len(webhooks)-1)
fmt.Println("Webhooks " + webhook.URL + " has been regstrerd")
......@@ -44,19 +43,19 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good
parts := strings.Split(r.URL.Path, "/") //finds url parts
fmt.Println(parts)
if len(parts) == 5 {
if len(parts) == 5 { // this need to be fixed
tempInt, err := strconv.Atoi(parts[4])
tempInt, err := strconv.Atoi(parts[4]) // gets the numid of choosen webhook
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
err = json.NewEncoder(w).Encode(webhooks[tempInt-1])
err = json.NewEncoder(w).Encode(webhooks[tempInt]) // encode choosen webhook
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
} else {
err := json.NewEncoder(w).Encode(webhooks)
} else { // if not choosen any webhooks
err := json.NewEncoder(w).Encode(webhooks) // encode all webhooks
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment