Mercurial > lbo > hg > goe_bot
changeset 32:511fd45de3ea
Move from uint64 to int64; use srvStatus for DB stats
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 10 Dec 2016 13:42:59 +0100 |
parents | 107e7aef325c |
children | 5f515c91737f |
files | api_schema.go handler_todo.go handlers.go http.go main.go pull.go sql/storage.go sql/todo.go |
diffstat | 8 files changed, 24 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/api_schema.go Sat Dec 10 13:35:18 2016 +0100 +++ b/api_schema.go Sat Dec 10 13:42:59 2016 +0100 @@ -1,14 +1,14 @@ package main type user struct { - ID uint64 + ID int64 First_Name string Last_Name string Username string } type chat struct { - ID uint64 + ID int64 Type string Title string First_Name string @@ -16,9 +16,9 @@ } type message struct { - Message_ID uint64 + Message_ID int64 From user - Date uint64 + Date int64 Chat chat Text string // original sender @@ -37,7 +37,7 @@ } type update struct { - Update_ID uint64 + Update_ID int64 Message message Channel_Post message Callback_Query callbackQuery @@ -57,17 +57,17 @@ type webhookInfo struct { URL string - Pending_Update_Count uint64 - Last_Error_Date uint64 + Pending_Update_Count int64 + Last_Error_Date int64 Last_Error_Message string } // Body type for sendMessage and webhook reply type sendMessage struct { - Chat_ID uint64 `json:"chat_id"` + Chat_ID int64 `json:"chat_id"` Text string `json:"text"` Parse_Mode string `json:"parse_mode"` // either Markdown or HTML - Reply_To_message_Id uint64 `json:"reply_to_message_id"` + Reply_To_message_Id int64 `json:"reply_to_message_id"` Reply_Markup inlineKeyboardMarkup `json:"reply_markup"` // Used for replying from a webhook; usually set to "sendMessage" @@ -75,8 +75,8 @@ } type getUpdates struct { - Offset uint64 `json:"offset"` - Timeout uint64 `json:"timeout"` + Offset int64 `json:"offset"` + Timeout int64 `json:"timeout"` } type setWebhook struct {
--- a/handler_todo.go Sat Dec 10 13:35:18 2016 +0100 +++ b/handler_todo.go Sat Dec 10 13:42:59 2016 +0100 @@ -73,7 +73,7 @@ return replyContent{text: "_Falsches Format; Zahl erwartet_ (" + token + ")"}, err } - affected, err := todo.MarkTodoDone(id) + affected, err := todo.MarkTodoDone(int64(id)) if err != nil { return replyContent{text: "_Aktion fehlgeschlagen:_ " + err.Error()}, err
--- a/handlers.go Sat Dec 10 13:35:18 2016 +0100 +++ b/handlers.go Sat Dec 10 13:42:59 2016 +0100 @@ -84,7 +84,7 @@ func dispatch(ctx context.Context, upd update) (sendMessage, error) { var rp replyContent var err error - var chatID uint64 + var chatID int64 if upd.Message.Message_ID > 0 { srvStatus.commands++
--- a/http.go Sat Dec 10 13:35:18 2016 +0100 +++ b/http.go Sat Dec 10 13:42:59 2016 +0100 @@ -56,7 +56,7 @@ debugUser := user{First_Name: "debug", Username: "debug", ID: 1} debugChat := chat{ID: 1, Type: "private", Title: "__debug", First_Name: "debug"} - msg := message{Chat: debugChat, From: debugUser, Message_ID: 1, Date: uint64(time.Now().Unix()), Text: string(body)} + msg := message{Chat: debugChat, From: debugUser, Message_ID: 1, Date: int64(time.Now().Unix()), Text: string(body)} srvStatus.commands++
--- a/main.go Sat Dec 10 13:35:18 2016 +0100 +++ b/main.go Sat Dec 10 13:42:59 2016 +0100 @@ -39,6 +39,8 @@ if err == nil { backend = db + srvStatus.dbConnected = true + srvStatus.database = *flagDatabase } return err @@ -72,7 +74,7 @@ if *flagUsePull { go http.ListenAndServe(*flagListenAddr, mux) - st := uint64(1) + st := int64(1) for { st, _ = pullUpdates(st)
--- a/pull.go Sat Dec 10 13:35:18 2016 +0100 +++ b/pull.go Sat Dec 10 13:42:59 2016 +0100 @@ -12,11 +12,11 @@ // After the webhook is called, it should process the request, respond with http.StatusOK (if appropriate), // and then call the sendMessage method. -func pullUpdates(off uint64) (uint64, error) { +func pullUpdates(off int64) (int64, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Duration(*flagDeadline)*time.Second) defer cancel() - gU := getUpdates{Offset: off, Timeout: uint64(*flagDeadline)} + gU := getUpdates{Offset: off, Timeout: int64(*flagDeadline)} body, err := json.Marshal(gU) if err != nil {
--- a/sql/storage.go Sat Dec 10 13:35:18 2016 +0100 +++ b/sql/storage.go Sat Dec 10 13:42:59 2016 +0100 @@ -35,7 +35,7 @@ return &Storage{db: db, prepared: make(map[string]*sql.Stmt)}, nil } -func (s *Storage) Todo(chatID uint64) (Todo, error) { +func (s *Storage) Todo(chatID int64) (Todo, error) { return newTodo(s, chatID) }
--- a/sql/todo.go Sat Dec 10 13:35:18 2016 +0100 +++ b/sql/todo.go Sat Dec 10 13:42:59 2016 +0100 @@ -20,11 +20,11 @@ // Data access object for todo lists type Todo struct { - chatID uint64 + chatID int64 db *Storage } -func newTodo(s *Storage, chat uint64) (Todo, error) { +func newTodo(s *Storage, chat int64) (Todo, error) { t := Todo{chatID: chat, db: s} return t, t.prewarm() @@ -73,7 +73,7 @@ type OpenTodo struct { // to be used as callback data - ID uint64 + ID int64 Text string Owner string } @@ -111,7 +111,7 @@ } // Mark todo item as done. Returns number of affected items (0 if the item was already marked as done) -func (td Todo) MarkTodoDone(id uint64) (int, error) { +func (td Todo) MarkTodoDone(id int64) (int, error) { if stmt, ok := td.db.prepared[markTodoDone]; ok { result, err := stmt.Exec(id)