commit
c094d19c0c
1 changed files with 7 additions and 2 deletions
9
main.go
9
main.go
|
@ -26,7 +26,12 @@ func insertMessage(db *sql.DB, data map[string]interface{}) error {
|
||||||
// id := data["message_id"].(float64)
|
// id := data["message_id"].(float64)
|
||||||
post_type := data["post_type"].(string)
|
post_type := data["post_type"].(string)
|
||||||
message_type := data["message_type"].(string)
|
message_type := data["message_type"].(string)
|
||||||
message_time := (time.Unix(int64(data["time"].(float64)), 0).UTC()).Format("2006-01-02 15:04:05")
|
// 设置东八区时间
|
||||||
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
message_time := (time.Unix(int64(data["time"].(float64)), 0).In(loc)).Format("2006-01-02 15:04:05")
|
||||||
group_id := data["group_id"].(float64)
|
group_id := data["group_id"].(float64)
|
||||||
message_id := data["message_id"].(float64)
|
message_id := data["message_id"].(float64)
|
||||||
raw_message := data["raw_message"].(string)
|
raw_message := data["raw_message"].(string)
|
||||||
|
@ -40,7 +45,7 @@ func insertMessage(db *sql.DB, data map[string]interface{}) error {
|
||||||
sender_role := sender["role"].(string)
|
sender_role := sender["role"].(string)
|
||||||
fmt.Println(post_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role)
|
fmt.Println(post_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role)
|
||||||
// Insert data into database
|
// Insert data into database
|
||||||
_, err := db.Exec("INSERT INTO messages ( post_type, message_type, time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = db.Exec("INSERT INTO messages ( post_type, message_type, time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
post_type, message_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role)
|
post_type, message_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role)
|
||||||
fmt.Println("Data inserted successfully!")
|
fmt.Println("Data inserted successfully!")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue