46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
)
|
|
|
|
const (
|
|
ListenAddr = "[::1]:8001"
|
|
RabbitForwarderPath = "rabbitmq-forwarder"
|
|
)
|
|
|
|
func main() {
|
|
common.RequireGiteaSecretToken()
|
|
|
|
http.HandleFunc("/"+RabbitForwarderPath, 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" {
|
|
|
|
res.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
hdr := req.Header[common.GiteaRequestHeader]
|
|
if len(hdr) != 1 {
|
|
// h.LogError("Unsupported number of %s headers: %d: %#v\n", GiteaRequestHeader, len(hdr), hdr)
|
|
// h.WriteError()
|
|
res.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
reqType := hdr[0]
|
|
err := PublicMessage(reqType, req.Body)
|
|
if err != nil {
|
|
log.Printf("hook (%s) processing error: %v\n", reqType, err)
|
|
res.WriteHeader(http.StatusBadRequest)
|
|
} else {
|
|
res.WriteHeader(http.StatusOK)
|
|
}
|
|
})
|
|
|
|
log.Fatal(http.ListenAndServe(ListenAddr, nil))
|
|
}
|