Will continue @ home

This commit is contained in:
Hamcha 2016-02-08 17:05:46 +00:00
parent bc28a0faa0
commit f3186708ef
4 changed files with 18 additions and 3 deletions

View file

@ -2,3 +2,6 @@ all: clessy-broker
clessy-broker: clessy-broker:
go build -o clessy-broker ./broker go build -o clessy-broker ./broker
clean:
rm -f clessy-broker

View file

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag" "flag"
"log"
"net/http" "net/http"
"os" "os"
) )
@ -39,14 +40,17 @@ func main() {
// Setup webhook handler // Setup webhook handler
go func() { go func() {
log.Println("Starting webserver..")
http.HandleFunc(config.Token, webhook) http.HandleFunc(config.Token, webhook)
err := http.ListenAndServe(config.BindServer, nil) err := http.ListenAndServe(config.BindServer, nil)
assert(err) assert(err)
}() }()
// Register webhook @ Telegram // Register webhook @ Telegram
log.Println("Registering webhook..")
api.setWebhook(config.BaseURL + config.WebhookURL) api.setWebhook(config.BaseURL + config.WebhookURL)
// Create server for clients // Create server for clients
log.Println("Starting clients server..")
startClientsServer(config.BindClients) startClientsServer(config.BindClients)
} }

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"io/ioutil" "encoding/json"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -23,9 +23,11 @@ func (t Telegram) setWebhook(webhook string) {
resp, err := http.PostForm(t.apiURL("setWebhook"), url.Values{"url": {webhook}}) resp, err := http.PostForm(t.apiURL("setWebhook"), url.Values{"url": {webhook}})
if !checkerr("setWebhook", err) { if !checkerr("setWebhook", err) {
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) var result tg.APIResponse
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil { if err != nil {
log.Printf("setWebhook result: %s\n", string(data)) log.Println("Could not read reply: " + err.Error())
return
} }
} }
} }

View file

@ -118,3 +118,9 @@ type APIUpdate struct {
UpdateID int `json:"update_id"` UpdateID int `json:"update_id"`
Message APIMessage `json:"message"` Message APIMessage `json:"message"`
} }
type APIResponse struct {
Ok bool `json:"ok"`
ErrCode *int `json:"error_code,omitempty"`
Description *string `json:"description,omitempty"`
}