logs.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. _ "github.com/go-sql-driver/mysql"
  6. "github.com/go-xorm/xorm"
  7. )
  8. type OperateLogs struct {
  9. Id int `xorm:"int pk autoincr 'id'"`
  10. AdminId int `xorm:"int 'admin_id'"`
  11. SysUserRealName string `xorm:"varchar(1000) 'sys_user_real_name'"`
  12. OperateTime time.Time `xorm:"timestamp null 'operate_time'"`
  13. Request string `xorm:"text null 'request'"`
  14. Response string `xorm:"text null 'response'"`
  15. OperateIp string `xorm:"varchar(1000) null 'operate_ip'"`
  16. Model string `xorm:"varchar(1000) null 'model'"`
  17. }
  18. type OprateTimeLogs struct {
  19. Uid int
  20. OperationTime time.Time
  21. }
  22. var engine *xorm.Engine
  23. func init() {
  24. var err error
  25. log := utils.MYSQL_LOG_URL
  26. engine, err = xorm.NewEngine("mysql", log)
  27. if err != nil {
  28. panic(err.Error())
  29. }
  30. }
  31. // AddLogs insert a new Logs into database and returns
  32. // last inserted Id on success.
  33. func AddLogs(m *OperateLogs) (id int64, err error) {
  34. id, err = engine.InsertOne(m)
  35. return
  36. }