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,25 +1,26 @@
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)
if err != nil {
log.Println("ERR: Not JSON!")
return
}
err := json.NewDecoder(req.Body).Decode(&update) jenc, _ := json.Marshal(update)
if err != nil { log.Println(jenc)
log.Println("ERR: Not JSON!") */
return io.Copy(os.Stdout, req.Body)
}
jenc, _ := json.Marshal(update)
log.Println(jenc)
} }