2021-08-20 14:59:13 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
2021-08-22 00:13:00 +08:00
|
|
|
"goweb/global"
|
|
|
|
"goweb/model"
|
2021-08-20 14:59:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type requestLogRepository struct{}
|
|
|
|
|
|
|
|
type RequestLogRepository interface {
|
|
|
|
SaveLog(log *model.RequestLog)
|
|
|
|
Migrate() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRequestLogRepository 新建实例
|
|
|
|
func NewRequestLogRepository() RequestLogRepository {
|
|
|
|
return requestLogRepository{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveLog 保存接口访问记录
|
|
|
|
func (r requestLogRepository) SaveLog(log *model.RequestLog) {
|
|
|
|
if err := global.MySQLConn.Create(log).Error; err != nil {
|
|
|
|
global.Log.Errorf("接口访问记录保存错误: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Migrate 初始化数据库结构
|
|
|
|
func (r requestLogRepository) Migrate() error {
|
|
|
|
return global.MySQLConn.AutoMigrate(&model.RequestLog{})
|
|
|
|
}
|