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 {
logOnError(err, "MQMainReceive : Can't unmarshal")
} 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")
}
func putMsg(m ChatWarsMessage) {
func putMsg(m ChatWarsMessage) error {
stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, date , text)
VALUES (?, ?, ?, FROM_UNIXTIME(?), ?);`)
if err != nil {
log.Fatal(err)
return err
}
defer stmt.Close()
_, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.MsgDate, m.MsgText)
if err != nil {
log.Fatal(err)
return err
}
err = stmt.Close()
if err != nil {
log.Fatal(err)
}
return nil
}