From b11c8cbcbf65ed911e8d7bd7d2bf389c37668a2e Mon Sep 17 00:00:00 2001 From: "Urko." Date: Mon, 6 May 2024 17:28:48 +0200 Subject: [PATCH] fix: execute script in background to not block response --- main.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index e6c6251..9b07dce 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,6 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w defer r.Body.Close() authHeader := r.Header.Get("Authorization") - log.Println("authHeader", authHeader) if authHeader != secret { http.Error(w, "Signatures didn't match", http.StatusUnauthorized) return @@ -57,22 +56,17 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w http.Error(w, "not found", http.StatusNotFound) return } - - log.Println("body", body) - // Parse the JSON payload var payload interface{} - err = json.Unmarshal(body, &payload) - if err != nil { + if err = json.Unmarshal(body, &payload); err != nil { http.Error(w, "Failed to parse JSON payload", http.StatusBadRequest) return } - // TODO: Do something with the payload - fmt.Fprintf(w, "I got some JSON: %v", payload) - - if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil { - panic(err) - } + go func() { + if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil { + log.Println(err) + } + }() }) }