actionLog.go 523 B

123456789101112131415161718192021222324252627
  1. package service
  2. import (
  3. "designs/global"
  4. "designs/model"
  5. "encoding/json"
  6. "time"
  7. )
  8. func SetActionLog(action string, userId int, object string, data interface{}) error {
  9. dataString, _ := json.Marshal(data)
  10. err := global.App.DB.Table(model.TableActionLog).Create(&model.ActionLog{
  11. Action: action,
  12. UserId: userId,
  13. Object: object,
  14. Data: string(dataString),
  15. CreatedAt: model.XTime{Time: time.Now()},
  16. }).Error
  17. if err != nil {
  18. global.App.Log.Error(err.Error())
  19. return err
  20. }
  21. return nil
  22. }