12345678910111213141516171819202122232425262728 |
- package services
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/utils"
- "fmt"
- )
- // the service for log
- func AutoInsertLogToDB() {
- defer func() {
- if err := recover(); err != nil {
- fmt.Println("[AutoInsertLogToDB]", err)
- }
- }()
- for {
- utils.Rc.Brpop(utils.CACHE_KEY_LOGS, func(b []byte) {
- var log models.OperateLogs
- if err := json.Unmarshal(b, &log); err != nil {
- fmt.Println("json unmarshal wrong!")
- }
- if _, err := models.AddLogs(&log); err != nil {
- fmt.Println("AddLogs:", err.Error(), log)
- }
- })
- }
- }
|