This commit is contained in:
Adam Majer 2024-08-26 13:56:33 +02:00
parent 57af3812c0
commit ff877cc987

View File

@ -292,7 +292,7 @@ func main() {
connectToRabbitMQ()
http.HandleFunc("POST /test", func(res http.ResponseWriter, req *http.Request) {
http.HandleFunc("POST /rabbitmq-forwarder", func(res http.ResponseWriter, req *http.Request) {
if len(req.Header.Get("Content-Type")) == 0 ||
req.Header["Content-Type"][0] != "application/json" ||
req.Method != "POST" {
@ -337,31 +337,29 @@ func main() {
if DebugMode {
dumpUnhandledData(reqType, data)
}
// return
return
}
// err = PublishMessage(repo.Owner.Username, reqType, data)
// write to file for review
id++
os.WriteFile("test_data."+fmt.Sprint(id), data, 0644)
if org != nil {
log.Println(id, org.Username, reqType, extraAction)
if org == nil {
res.WriteHeader(http.StatusBadRequest)
log.Printf("no `org` for message... type: %s", reqType)
if DebugMode {
dumpUnhandledData(reqType, data)
}
}
/*
err = PublishMessage(org.Name, reqType, extraAction, data)
if err != nil {
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
res.Header().Add("Content-Type", "plain/text")
res.Write([]byte(errorStr))
res.WriteHeader(http.StatusBadRequest)
err = PublishActionMessage(org.Username, reqType, extraAction, data)
if err != nil {
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
res.Header().Add("Content-Type", "plain/text")
res.Write([]byte(errorStr))
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
log.Println(errorStr)
}
} else {*/
if DebugMode {
log.Println(errorStr)
}
}
res.WriteHeader(http.StatusOK)
// }
})
http.HandleFunc("POST /rabbitmq-forwarder/{Org}", func(res http.ResponseWriter, req *http.Request) {