Fix some encoding errors
This commit is contained in:
parent
5ffb054dfa
commit
85284e40be
3 changed files with 19 additions and 7 deletions
|
@ -41,7 +41,7 @@ func handleClient(c net.Conn) {
|
|||
var cmd tg.ClientCommand
|
||||
err = json.Unmarshal(bytes, &cmd)
|
||||
if err != nil {
|
||||
log.Printf("Can't parse JSON: %s\r\n", err.Error())
|
||||
log.Printf("[handleClient] Can't parse JSON: %s\r\n", err.Error())
|
||||
continue
|
||||
}
|
||||
executeClientCommand(cmd)
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"../tg"
|
||||
)
|
||||
|
||||
func webhook(rw http.ResponseWriter, req *http.Request) {
|
||||
// Read entire request and broadcast to everyone
|
||||
data, err := ioutil.ReadAll(req.Body)
|
||||
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
|
||||
}
|
||||
defer req.Body.Close()
|
||||
|
||||
broadcast(string(data))
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ func (b *Broker) SendTextMessage(chat *APIChat, text string) {
|
|||
},
|
||||
}
|
||||
// Encode command and send to broker
|
||||
err := json.NewEncoder(b.Socket).Encode(&cmd)
|
||||
data, err := json.Marshal(cmd)
|
||||
if err != nil {
|
||||
log.Printf("[SendTextMessage] JSON Encode error: %s\n", err.Error())
|
||||
}
|
||||
fmt.Fprintf(b.Socket, "\n")
|
||||
fmt.Fprintln(data)
|
||||
}
|
||||
|
|
Reference in a new issue