kopia lustrzana https://github.com/tmsmr/xmpp-webhook
gofmt
rodzic
8ec6f82ae6
commit
8024037666
13
handler.go
13
handler.go
|
@ -11,7 +11,7 @@ type Response struct {
|
||||||
Code int
|
Code int
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorResponse() (Response) {
|
func errorResponse() Response {
|
||||||
return Response{"", http.StatusInternalServerError}
|
return Response{"", http.StatusInternalServerError}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func (h *messageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// send message to xmpp client
|
// send message to xmpp client
|
||||||
h.messages <- m
|
h.messages <- m
|
||||||
w.WriteHeader(response.Code)
|
w.WriteHeader(response.Code)
|
||||||
w.Write( []byte(response.Message) )
|
w.Write([]byte(response.Message))
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns new handler with a given parser function
|
// returns new handler with a given parser function
|
||||||
|
@ -98,12 +98,12 @@ type SlackAttachment struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func nonemptyAppendNewline(message string) (string) {
|
func nonemptyAppendNewline(message string) string {
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
return message+"\n"
|
return message + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func slackParserFunc(r *http.Request) (string, error, Response) {
|
func slackParserFunc(r *http.Request) (string, error, Response) {
|
||||||
|
@ -131,11 +131,10 @@ func slackParserFunc(r *http.Request) (string, error, Response) {
|
||||||
|
|
||||||
for _, attachment := range alert.Attachments {
|
for _, attachment := range alert.Attachments {
|
||||||
message = nonemptyAppendNewline(message)
|
message = nonemptyAppendNewline(message)
|
||||||
message += attachment.Title+"\n"
|
message += attachment.Title + "\n"
|
||||||
message += attachment.TitleLink+"\n\n"
|
message += attachment.TitleLink + "\n\n"
|
||||||
message += attachment.Text
|
message += attachment.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return message, nil, Response{"ok", http.StatusOK}
|
return message, nil, Response{"ok", http.StatusOK}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue