feat(log): 添加QQWry IP数据库支持并实现IP地址解析功能
This commit is contained in:
@@ -2,12 +2,14 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"fmt"
|
||||
|
||||
"blazing/modules/base/model"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
)
|
||||
|
||||
type BaseSysLogService struct {
|
||||
@@ -44,7 +46,19 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
|
||||
baseSysLog.UserID = admin.UserId
|
||||
baseSysLog.Action = r.Method + ":" + r.URL.Path
|
||||
baseSysLog.IP = r.GetClientIp()
|
||||
baseSysLog.IPAddr = r.GetClientIp()
|
||||
// 从内存或缓存查询IP
|
||||
location, err := qqwry.QueryIP("119.29.29.29")
|
||||
if err != nil {
|
||||
fmt.Printf("错误:%v\n", err)
|
||||
return
|
||||
}
|
||||
baseSysLog.IPAddr = fmt.Sprintf("国家:%s,省份:%s,城市:%s,区县:%s,运营商:%s\n",
|
||||
location.Country,
|
||||
location.Province,
|
||||
location.City,
|
||||
location.District,
|
||||
location.ISP,
|
||||
)
|
||||
baseSysLog.Params = r.GetBodyString()
|
||||
m := cool.DBM(s.Model)
|
||||
m.Insert(g.Map{
|
||||
@@ -68,3 +82,11 @@ func (s *BaseSysLogService) Clear(isAll bool) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 从文件加载IP数据库
|
||||
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user