This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/broker/webhook.go
2016-02-09 10:21:37 +00:00

29 lines
536 B
Go

package main
import (
"encoding/json"
"log"
"net/http"
"../tg"
)
func webhook(rw http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
// Re-encode request to ensure conformity
var update tg.APIUpdate
err := json.NewDecoder(req.Body).Decode(&update)
if err != nil {
log.Println("[webhook] Received incorrect request: " + err.Error())
return
}
data, err := json.Marshal(update)
if err != nil {
log.Println("[webhook] Cannot re-encode json (??) : " + err.Error())
return
}
broadcast(string(data))
}