mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-12 16:44:43 +00:00
Merge pull request #319 from Htbaa/issue-313
Replaced fmt.Frpintf calls with fmt.Fprint when there's no formatting…
This commit is contained in:
commit
42b72b028b
1 changed files with 8 additions and 8 deletions
16
webhook.go
16
webhook.go
|
@ -186,7 +186,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
router.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
router.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
fmt.Fprintf(w, "OK")
|
fmt.Fprint(w, "OK")
|
||||||
})
|
})
|
||||||
|
|
||||||
router.HandleFunc(hooksURL, hookHandler)
|
router.HandleFunc(hooksURL, hookHandler)
|
||||||
|
@ -273,7 +273,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
msg := fmt.Sprintf("[%s] error evaluating hook: %s", rid, err)
|
msg := fmt.Sprintf("[%s] error evaluating hook: %s", rid, err)
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Error occurred while evaluating hook rules.")
|
fmt.Fprint(w, "Error occurred while evaluating hook rules.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,17 +291,17 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
if matchedHook.CaptureCommandOutputOnError {
|
if matchedHook.CaptureCommandOutputOnError {
|
||||||
fmt.Fprintf(w, response)
|
fmt.Fprint(w, response)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
fmt.Fprintf(w, "Error occurred while executing the hook's command. Please check your logs for more details.")
|
fmt.Fprint(w, "Error occurred while executing the hook's command. Please check your logs for more details.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if a success return code is configured for the hook
|
// Check if a success return code is configured for the hook
|
||||||
if matchedHook.SuccessHttpResponseCode != 0 {
|
if matchedHook.SuccessHttpResponseCode != 0 {
|
||||||
writeHttpResponseCode(w, rid, matchedHook.ID, matchedHook.SuccessHttpResponseCode)
|
writeHttpResponseCode(w, rid, matchedHook.ID, matchedHook.SuccessHttpResponseCode)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, response)
|
fmt.Fprint(w, response)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
go handleHook(matchedHook, rid, &headers, &query, &payload, &body)
|
go handleHook(matchedHook, rid, &headers, &query, &payload, &body)
|
||||||
|
@ -311,7 +311,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
writeHttpResponseCode(w, rid, matchedHook.ID, matchedHook.SuccessHttpResponseCode)
|
writeHttpResponseCode(w, rid, matchedHook.ID, matchedHook.SuccessHttpResponseCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, matchedHook.ResponseMessage)
|
fmt.Fprint(w, matchedHook.ResponseMessage)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -324,10 +324,10 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// if none of the hooks got triggered
|
// if none of the hooks got triggered
|
||||||
log.Printf("[%s] %s got matched, but didn't get triggered because the trigger rules were not satisfied\n", rid, matchedHook.ID)
|
log.Printf("[%s] %s got matched, but didn't get triggered because the trigger rules were not satisfied\n", rid, matchedHook.ID)
|
||||||
|
|
||||||
fmt.Fprintf(w, "Hook rules were not satisfied.")
|
fmt.Fprint(w, "Hook rules were not satisfied.")
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
fmt.Fprintf(w, "Hook not found.")
|
fmt.Fprint(w, "Hook not found.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue