Now compiles

This commit is contained in:
Hamcha 2016-02-08 16:57:27 +00:00
parent cac52711e3
commit bc28a0faa0
7 changed files with 68 additions and 66 deletions

View file

@ -1,4 +1,4 @@
all: broker all: clessy-broker
broker: clessy-broker:
go build -o clessy-broker ./broker go build -o clessy-broker ./broker

View file

@ -1,4 +1,4 @@
package broker package main
import ( import (
"../tg" "../tg"

View file

@ -50,7 +50,7 @@ func handleClient(c net.Conn) {
} }
func removeCon(c net.Conn) { func removeCon(c net.Conn) {
for i, con := range Clients { for i, con := range clients {
if c == con { if c == con {
clients = append(clients[:i], clients[i+1:]...) clients = append(clients[:i], clients[i+1:]...)
} }

View file

@ -21,7 +21,7 @@ func assert(err error) {
} }
} }
var api Telegram var api *Telegram
func main() { func main() {
cfgpath := flag.String("config", "config.json", "Path to configuration file") cfgpath := flag.String("config", "config.json", "Path to configuration file")
@ -39,7 +39,7 @@ func main() {
// Setup webhook handler // Setup webhook handler
go func() { go func() {
http.HandlerFunc(config.Token, webhook) http.HandleFunc(config.Token, webhook)
err := http.ListenAndServe(config.BindServer, nil) err := http.ListenAndServe(config.BindServer, nil)
assert(err) assert(err)
}() }()

View file

@ -30,11 +30,11 @@ func (t Telegram) setWebhook(webhook string) {
} }
} }
func (t Telegram) apiURL(method string) { func (t Telegram) apiURL(method string) string {
return APIEndpoint + "bot" + t.Token + "/" + method return APIEndpoint + "bot" + t.Token + "/" + method
} }
func checkerr(method string, err error) { func checkerr(method string, err error) bool {
if err != nil { if err != nil {
log.Printf("Received error with call to %s: %s\n", method, err.Error()) log.Printf("Received error with call to %s: %s\n", method, err.Error())
return true return true

View file

@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"net/http" "net/http"
"../tg"
) )
func webhook(rw http.ResponseWriter, req *http.Request) { func webhook(rw http.ResponseWriter, req *http.Request) {

View file

@ -19,70 +19,70 @@ const (
type APIChat struct { type APIChat struct {
UserID int `json:"id"` UserID int `json:"id"`
Type ChatType `json:"type"` Type ChatType `json:"type"`
Title string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
Username string `json:"username,omitempty"` Username *string `json:"username,omitempty"`
FirstName string `json:"first_name,omitempty"` FirstName *string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"` LastName *string `json:"last_name,omitempty"`
} }
type APIMessage struct { type APIMessage struct {
MessageID int `json:"message_id"` MessageID int `json:"message_id"`
User APIUser `json:"from"` User APIUser `json:"from"`
Time int `json:"date"` Time int `json:"date"`
Chat APIChat `json:"chat"` Chat *APIChat `json:"chat"`
FwdUser APIUpdate `json:"forward_from,omitempty"` FwdUser *APIUpdate `json:"forward_from,omitempty"`
FwdTime int `json:"forward_date,omitempty"` FwdTime *int `json:"forward_date,omitempty"`
ReplyTo APIMessage `json:"reply_to_message,omitempty"` ReplyTo *APIMessage `json:"reply_to_message,omitempty"`
Text string `json:"text,omitempty"` Text *string `json:"text,omitempty"`
Audio APIAudio `json:"audio,omitempty"` Audio *APIAudio `json:"audio,omitempty"`
Document APIDocument `json:"document,omitempty"` Document *APIDocument `json:"document,omitempty"`
Photo []APIPhotoSize `json:"photo,omitempty"` Photo []APIPhotoSize `json:"photo,omitempty"`
Sticker APISticker `json:"sticker,omitempty"` Sticker *APISticker `json:"sticker,omitempty"`
Video APIVideo `json:"video,omitempty"` Video *APIVideo `json:"video,omitempty"`
Voice APIVoice `json:"voice,omitempty"` Voice *APIVoice `json:"voice,omitempty"`
Caption string `json:"caption,omitempty"` Caption *string `json:"caption,omitempty"`
Contact APIContact `json:"contact,omitempty"` Contact *APIContact `json:"contact,omitempty"`
Location APILocation `json:"location,omitempty"` Location *APILocation `json:"location,omitempty"`
NewUser APIUser `json:"new_chat_partecipant",omitempty"` NewUser *APIUser `json:"new_chat_partecipant",omitempty"`
LeftUser APIUser `json:"left_chat_partecipant,omitempty"` LeftUser *APIUser `json:"left_chat_partecipant,omitempty"`
PhotoDeleted bool `json:"delete_chat_photo,omitempty"` PhotoDeleted *bool `json:"delete_chat_photo,omitempty"`
GroupCreated bool `json:"group_chat_created,omitempty"` GroupCreated *bool `json:"group_chat_created,omitempty"`
SupergroupCreated bool `json:"supergroup_chat_created,omitempty"` SupergroupCreated *bool `json:"supergroup_chat_created,omitempty"`
ChannelCreated bool `json:"channel_chat_created,omitempty"` ChannelCreated *bool `json:"channel_chat_created,omitempty"`
GroupToSuper int `json:"migrate_to_chat_id,omitempty"` GroupToSuper *int `json:"migrate_to_chat_id,omitempty"`
GroupFromSuper int `json:"migrate_from_chat_id,omitempty"` GroupFromSuper *int `json:"migrate_from_chat_id,omitempty"`
} }
type APIPhotoSize struct { type APIPhotoSize struct {
FileID string `json:"file_id"` FileID string `json:"file_id"`
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APIAudio struct { type APIAudio struct {
FileID string `json:"file_id"` FileID string `json:"file_id"`
Duration int `json:"duration"` Duration int `json:"duration"`
Performer string `json:"performer,omitempty"` Performer *string `json:"performer,omitempty"`
Title string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
MimeType string `json:"mime_type,omitempty"` MimeType *string `json:"mime_type,omitempty"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APIDocument struct { type APIDocument struct {
FileID string `json:"file_id"` FileID string `json:"file_id"`
Thumbnail APIPhotoSize `json:"thumb,omitempty"` Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
Filename string `json:"file_name"` Filename string `json:"file_name"`
MimeType string `json:"mime_type,omitempty"` MimeType *string `json:"mime_type,omitempty"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APISticker struct { type APISticker struct {
FileID string `json:"file_id"` FileID string `json:"file_id"`
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
Thumbnail APIPhotoSize `json:"thumb,omitempty"` Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APIVideo struct { type APIVideo struct {
@ -90,23 +90,23 @@ type APIVideo struct {
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
Duration int `json:"duration"` Duration int `json:"duration"`
Thumbnail APIPhotoSize `json:"thumb,omitempty"` Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
MimeType string `json:"mime_type,omitempty"` MimeType *string `json:"mime_type,omitempty"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APIVoice struct { type APIVoice struct {
FileID string `json:"file_id"` FileID string `json:"file_id"`
Duration int `json:"duration"` Duration int `json:"duration"`
MimeType string `json:"mime_type,omitempty"` MimeType *string `json:"mime_type,omitempty"`
FileSize int `json:"file_size,omitempty"` FileSize *int `json:"file_size,omitempty"`
} }
type APIContact struct { type APIContact struct {
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name,omitempty"` LastName *string `json:"last_name,omitempty"`
UserID int `json:"user_id,omitempty"` UserID *int `json:"user_id,omitempty"`
} }
type APILocation struct { type APILocation struct {