Fix compilation error and comment out some code for testing

This commit is contained in:
Hamcha 2016-02-09 08:59:25 +00:00
parent f3186708ef
commit a4bdd6c71f
2 changed files with 22 additions and 12 deletions

View file

@ -2,9 +2,12 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"../tg"
) )
const APIEndpoint = "https://api.telegram.org/" const APIEndpoint = "https://api.telegram.org/"
@ -29,6 +32,12 @@ func (t Telegram) setWebhook(webhook string) {
log.Println("Could not read reply: " + err.Error()) log.Println("Could not read reply: " + err.Error())
return return
} }
if result.Ok {
log.Println("Webhook successfully set!")
} else {
log.Printf("Error setting webhook (errcode %d): %s\n", *(result.ErrCode), *(result.Description))
panic(errors.New("Cannot set webhook"))
}
} }
} }

View file

@ -1,17 +1,16 @@
package main package main
import ( import (
"encoding/json" "io"
"log" "log"
"net/http" "net/http"
"os"
"../tg"
) )
func webhook(rw http.ResponseWriter, req *http.Request) { func webhook(rw http.ResponseWriter, req *http.Request) {
log.Println("Received request! Details follow:") log.Println("Received request! Details follow:")
defer req.Body.Close() defer req.Body.Close()
/*
var update tg.APIUpdate var update tg.APIUpdate
err := json.NewDecoder(req.Body).Decode(&update) err := json.NewDecoder(req.Body).Decode(&update)
@ -22,4 +21,6 @@ func webhook(rw http.ResponseWriter, req *http.Request) {
jenc, _ := json.Marshal(update) jenc, _ := json.Marshal(update)
log.Println(jenc) log.Println(jenc)
*/
io.Copy(os.Stdout, req.Body)
} }