processLog.go 911 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model
  2. import (
  3. "crawler/config"
  4. "crawler/service"
  5. )
  6. type ProcessLogInterface interface {
  7. Save()
  8. }
  9. type ProcessLogModel struct {
  10. ProcessLog
  11. }
  12. type ProcessLog struct {
  13. Path string `json:"path"`
  14. Code int `json:"code"`
  15. Method string `json:"method"`
  16. Response string `json:"response"`
  17. Request string `json:"request"`
  18. RawQuery string `json:"rawQuery"`
  19. CreatedAt string `json:"createdAt"`
  20. }
  21. func (this *ProcessLogModel) Save() {
  22. var (
  23. db = service.DB_CRAWLER
  24. conn = db.SQLDB
  25. )
  26. sql := `
  27. INSERT INTO tb_process_log
  28. SET
  29. path = ?,
  30. code = ?,
  31. method = ?,
  32. response = ?,
  33. request = ?,
  34. raw_query = ?,
  35. created_at = NOW();
  36. `
  37. _, err := conn.Exec(sql, this.Path, this.Code, this.Method, this.Response, this.Request, this.RawQuery)
  38. if err != nil {
  39. db.SetErrorLog(err, sql)
  40. }
  41. db.SetGeneralLog(config.GL_ACTION_WRITE, sql, "insert process log")
  42. }