.
This commit is contained in:
parent
bc0950bd00
commit
a4c7e18230
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ListenAddr = "[::1]:8002"
|
||||
ListenAddrDef = "[::1]:8002"
|
||||
AppName = "rabbitmq-forwarder"
|
||||
)
|
||||
|
||||
@ -31,7 +31,10 @@ func connectToRabbitMQ() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var listenAddr string
|
||||
|
||||
flag.BoolVar(&DebugMode, "debug", false, "enables debugging messages")
|
||||
flag.StringVar(&listenAddr, "listen", ListenAddrDef, "HTTP listen socket address for webhook events")
|
||||
flag.Parse()
|
||||
|
||||
connectToRabbitMQ()
|
||||
@ -55,14 +58,20 @@ func main() {
|
||||
return
|
||||
}
|
||||
reqType := hdr[0]
|
||||
err := PublicMessage(reqType, req.PathValue("Org"), req.Body)
|
||||
err := PublishMessage(reqType, req.PathValue("Org"), req.Body)
|
||||
if err != nil {
|
||||
log.Printf("hook (%s) processing error: %v\n", reqType, err)
|
||||
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 {
|
||||
res.WriteHeader(http.StatusOK)
|
||||
}
|
||||
})
|
||||
|
||||
log.Fatal(http.ListenAndServe(ListenAddr, nil))
|
||||
log.Fatal(http.ListenAndServe(listenAddr, nil))
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ type Message struct {
|
||||
|
||||
var messageQueue chan Message
|
||||
|
||||
func PublicMessage(giteaWebhookType, giteaOrg string, msgBody io.Reader) error {
|
||||
func PublishMessage(giteaWebhookType, giteaOrg string, msgBody io.Reader) error {
|
||||
if messageQueue == nil {
|
||||
return fmt.Errorf("Queue not initialized")
|
||||
}
|
||||
@ -110,7 +110,7 @@ func ConnectToExchangeForPublish(host, username, password string) {
|
||||
if ch.IsClosed() || connection.IsClosed() {
|
||||
select {
|
||||
case messageQueue <- msg:
|
||||
log.Println("requed ...")
|
||||
log.Println("requeued ...")
|
||||
default:
|
||||
log.Println("queue full... message lost")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user