Clean up code

This commit is contained in:
Akbar Rahman 2021-07-29 07:30:19 +01:00
parent 242ae06cad
commit c0f0cc6c60

11
main.go
View File

@ -40,10 +40,6 @@ func main() {
} }
func webhook(w http.ResponseWriter, r *http.Request) { func webhook(w http.ResponseWriter, r *http.Request) {
// TODO run any specified tests before running script
service_name := mux.Vars(r)["service"]
payload := "" payload := ""
if p, err := ioutil.ReadAll(r.Body); err != nil { if p, err := ioutil.ReadAll(r.Body); err != nil {
writeResponse(w, 500, "Internal Server Error: Could not read payload") writeResponse(w, 500, "Internal Server Error: Could not read payload")
@ -60,12 +56,11 @@ func webhook(w http.ResponseWriter, r *http.Request) {
config := Config{} config := Config{}
json.Unmarshal(raw_config, &config) json.Unmarshal(raw_config, &config)
var service = Service{} // check what service is specified in URL (/webhook/{service}) and if it exists
if val, ok := config.Services[string(service_name)]; !ok { service, ok := config.Services[string(mux.Vars(r)["service"])]
if !ok {
writeResponse(w, 404, "Service Not Found") writeResponse(w, 404, "Service Not Found")
return return
} else {
service = val
} }
// Verify that signature provided matches signature calculated using secretsss // Verify that signature provided matches signature calculated using secretsss