This commit is contained in:
shoopea 2019-05-04 00:08:38 +08:00
parent c8df84a00f
commit f6d3bef2cd
2 changed files with 9 additions and 8 deletions

5
mq.go
View File

@ -47,7 +47,10 @@ func MQMainReceive() {
if err = json.Unmarshal(d.Body, &m); err != nil { if err = json.Unmarshal(d.Body, &m); err != nil {
logOnError(err, "MQMainReceive : Can't unmarshal") logOnError(err, "MQMainReceive : Can't unmarshal")
} else { } else {
putMsg(m) err = putMsg(m)
if err != nil {
logOnError(err, "MQMainReceive")
}
} }
} }
}() }()

12
sql.go
View File

@ -79,20 +79,18 @@ func initDB() {
log.Println("Database set up") log.Println("Database set up")
} }
func putMsg(m ChatWarsMessage) { func putMsg(m ChatWarsMessage) error {
stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, date , text) stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, date , text)
VALUES (?, ?, ?, FROM_UNIXTIME(?), ?);`) VALUES (?, ?, ?, FROM_UNIXTIME(?), ?);`)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer stmt.Close()
_, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.MsgDate, m.MsgText) _, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.MsgDate, m.MsgText)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
err = stmt.Close() return nil
if err != nil {
log.Fatal(err)
}
} }