From c3f557e7f1d89002bb12db6f4386c471f6ab82c9 Mon Sep 17 00:00:00 2001
From: dtapps
Date: Sat, 30 Dec 2023 21:40:06 +0800
Subject: [PATCH] - update ip
---
README.md | 2 +-
gin_gorm.go | 15 ++----
gin_gorm_config.go | 4 +-
gin_gorm_record.go | 99 +++++++++++++++++----------------------
gin_slog.go | 16 ++-----
gin_slog_custom.go | 7 +--
gin_slog_custom_record.go | 49 ++++++-------------
gin_slog_record.go | 91 ++++++++++++++---------------------
go.mod | 5 +-
go.sum | 12 ++---
version.go | 2 +-
11 files changed, 111 insertions(+), 191 deletions(-)
diff --git a/README.md b/README.md
index 05db4a3..209d45d 100644
--- a/README.md
+++ b/README.md
@@ -11,5 +11,5 @@
#### 安装
```shell
-go get -v -u go.dtapp.net/golog@v1.0.105
+go get -v -u go.dtapp.net/golog@v1.0.106
```
diff --git a/gin_gorm.go b/gin_gorm.go
index cda3500..1577a02 100644
--- a/gin_gorm.go
+++ b/gin_gorm.go
@@ -6,7 +6,6 @@ import (
"errors"
"github.com/gin-gonic/gin"
"go.dtapp.net/dorm"
- "go.dtapp.net/goip"
"go.dtapp.net/gojson"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
@@ -17,7 +16,6 @@ import (
// GinGorm 框架日志
type GinGorm struct {
gormClient *dorm.GormClient // 数据库驱动
- ipService *goip.Client // IP服务
config struct {
systemHostname string // 主机名
systemOs string // 系统类型
@@ -43,7 +41,7 @@ type GinGorm struct {
type GinGormFun func() *GinGorm
// NewGinGorm 创建框架实例化
-func NewGinGorm(ctx context.Context, systemOutsideIp string, ipService *goip.Client, gormClient *dorm.GormClient, gormTableName string) (*GinGorm, error) {
+func NewGinGorm(ctx context.Context, systemOutsideIp string, gormClient *dorm.GormClient, gormTableName string) (*GinGorm, error) {
gg := &GinGorm{}
@@ -53,8 +51,6 @@ func NewGinGorm(ctx context.Context, systemOutsideIp string, ipService *goip.Cli
}
gg.setConfig(ctx, systemOutsideIp)
- gg.ipService = ipService
-
if gormClient == nil || gormClient.GetDb() == nil {
gg.gormConfig.stats = false
} else {
@@ -141,17 +137,12 @@ func (gg *GinGorm) Middleware() gin.HandlerFunc {
go func() {
- clientIp := gorequest.ClientIp(ginCtx.Request)
- var info = goip.AnalyseResult{}
-
- if gg.ipService != nil {
- info = gg.ipService.Analyse(clientIp)
- }
+ requestIp := gorequest.ClientIp(ginCtx.Request)
var traceId = gotrace_id.GetGinTraceId(ginCtx)
// 记录
- gg.recordJson(ginCtx, traceId, requestTime, paramsBody, responseCode, responseBody, startTime, endTime, info)
+ gg.recordJson(ginCtx, traceId, requestTime, paramsBody, responseCode, responseBody, startTime, endTime, requestIp)
}()
}
diff --git a/gin_gorm_config.go b/gin_gorm_config.go
index d56c1e0..10f8ba2 100644
--- a/gin_gorm_config.go
+++ b/gin_gorm_config.go
@@ -2,7 +2,7 @@ package golog
import (
"context"
- "go.dtapp.net/goip"
+ "go.dtapp.net/gorequest"
"runtime"
)
@@ -20,7 +20,7 @@ func (gg *GinGorm) setConfig(ctx context.Context, systemOutsideIp string) {
gg.config.cpuModelName = info.CpuModelName
gg.config.cpuMhz = info.CpuMhz
- gg.config.systemInsideIp = goip.GetInsideIp(ctx)
+ gg.config.systemInsideIp = gorequest.GetInsideIp(ctx)
gg.config.systemOutsideIp = systemOutsideIp
gg.config.sdkVersion = Version
diff --git a/gin_gorm_record.go b/gin_gorm_record.go
index c04038a..db4edce 100644
--- a/gin_gorm_record.go
+++ b/gin_gorm_record.go
@@ -4,7 +4,6 @@ import (
"context"
"github.com/gin-gonic/gin"
"go.dtapp.net/dorm"
- "go.dtapp.net/goip"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
"go.dtapp.net/gourl"
@@ -14,37 +13,31 @@ import (
// 模型
type ginPostgresqlLog struct {
- LogId uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
- TraceId string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号
- RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间
- RequestUri string `gorm:"comment:【请求】请求链接 域名+路径+参数" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
- RequestUrl string `gorm:"comment:【请求】请求链接 域名+路径" json:"request_url,omitempty"` //【请求】请求链接 域名+路径
- RequestApi string `gorm:"index;comment:【请求】请求接口 路径" json:"request_api,omitempty"` //【请求】请求接口 路径
- RequestMethod string `gorm:"index;comment:【请求】请求方式" json:"request_method,omitempty"` //【请求】请求方式
- RequestProto string `gorm:"comment:【请求】请求协议" json:"request_proto,omitempty"` //【请求】请求协议
- RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA
- RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer
- RequestBody string `gorm:"comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
- RequestUrlQuery string `gorm:"comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
- RequestIp string `gorm:"index;comment:【请求】请求客户端Ip" json:"request_ip,omitempty"` //【请求】请求客户端Ip
- RequestIpCountry string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_country,omitempty"` //【请求】请求客户端城市
- RequestIpProvince string `gorm:"index;comment:【请求】请求客户端省份" json:"request_ip_province,omitempty"` //【请求】请求客户端省份
- RequestIpCity string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_city,omitempty"` //【请求】请求客户端城市
- RequestIpIsp string `gorm:"index;comment:【请求】请求客户端运营商" json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
- RequestIpLongitude float64 `gorm:"index;comment:【请求】请求客户端经度" json:"request_ip_longitude,omitempty"` //【请求】请求客户端经度
- RequestIpLatitude float64 `gorm:"index;comment:【请求】请求客户端纬度" json:"request_ip_latitude,omitempty"` //【请求】请求客户端纬度
- RequestHeader string `gorm:"comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头
- ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
- ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码
- ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述
- ResponseData string `gorm:"comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据
- CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间
- SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
- SystemInsideIp string `gorm:"comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
- SystemOs string `gorm:"index;comment:【系统】系统类型" json:"system_os,omitempty"` //【系统】系统类型
- SystemArch string `gorm:"index;comment:【系统】系统架构" json:"system_arch,omitempty"` //【系统】系统架构
- GoVersion string `gorm:"comment:【程序】Go版本" json:"go_version,omitempty"` //【程序】Go版本
- SdkVersion string `gorm:"comment:【程序】Sdk版本" json:"sdk_version,omitempty"` //【程序】Sdk版本
+ LogID uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
+ TraceID string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号
+ RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间
+ RequestUri string `gorm:"comment:【请求】请求链接 域名+路径+参数" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
+ RequestURL string `gorm:"comment:【请求】请求链接 域名+路径" json:"request_url,omitempty"` //【请求】请求链接 域名+路径
+ RequestApi string `gorm:"index;comment:【请求】请求接口 路径" json:"request_api,omitempty"` //【请求】请求接口 路径
+ RequestMethod string `gorm:"index;comment:【请求】请求方式" json:"request_method,omitempty"` //【请求】请求方式
+ RequestProto string `gorm:"comment:【请求】请求协议" json:"request_proto,omitempty"` //【请求】请求协议
+ RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA
+ RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer
+ RequestBody string `gorm:"comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
+ RequestUrlQuery string `gorm:"comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
+ RequestIP string `gorm:"index;comment:【请求】请求客户端IP" json:"request_ip,omitempty"` //【请求】请求客户端IP
+ RequestHeader string `gorm:"comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头
+ ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
+ ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码
+ ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述
+ ResponseData string `gorm:"comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据
+ CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间
+ SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
+ SystemInsideIP string `gorm:"comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
+ SystemOs string `gorm:"index;comment:【系统】系统类型" json:"system_os,omitempty"` //【系统】系统类型
+ SystemArch string `gorm:"index;comment:【系统】系统架构" json:"system_arch,omitempty"` //【系统】系统架构
+ GoVersion string `gorm:"comment:【程序】Go版本" json:"go_version,omitempty"` //【程序】Go版本
+ SdkVersion string `gorm:"comment:【程序】Sdk版本" json:"sdk_version,omitempty"` //【程序】Sdk版本
}
// 创建模型
@@ -59,7 +52,7 @@ func (gg *GinGorm) gormAutoMigrate(ctx context.Context) {
func (gg *GinGorm) gormRecord(data ginPostgresqlLog) {
data.SystemHostName = gg.config.systemHostname //【系统】主机名
- data.SystemInsideIp = gg.config.systemInsideIp //【系统】内网ip
+ data.SystemInsideIP = gg.config.systemInsideIp //【系统】内网ip
data.GoVersion = gg.config.goVersion //【程序】Go版本
data.SdkVersion = gg.config.sdkVersion //【程序】Sdk版本
data.SystemOs = gg.config.systemOs //【系统】系统类型
@@ -72,31 +65,25 @@ func (gg *GinGorm) gormRecord(data ginPostgresqlLog) {
}
}
-func (gg *GinGorm) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, requestBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
+func (gg *GinGorm) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, requestBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, requestIp string) {
data := ginPostgresqlLog{
- TraceId: traceId, //【系统】跟踪编号
- RequestTime: requestTime, //【请求】时间
- RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接
- RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
- RequestMethod: ginCtx.Request.Method, //【请求】请求方式
- RequestProto: ginCtx.Request.Proto, //【请求】请求协议
- RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
- RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
- RequestBody: dorm.JsonEncodeNoError(requestBody), //【请求】请求主体
- RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数
- RequestIp: ipInfo.Ip, //【请求】请求客户端Ip
- RequestIpCountry: ipInfo.Country, //【请求】请求客户端城市
- RequestIpProvince: ipInfo.Province, //【请求】请求客户端省份
- RequestIpCity: ipInfo.City, //【请求】请求客户端城市
- RequestIpIsp: ipInfo.Isp, //【请求】请求客户端运营商
- RequestIpLatitude: ipInfo.LocationLatitude, //【请求】请求客户端纬度
- RequestIpLongitude: ipInfo.LocationLongitude, //【请求】请求客户端经度
- RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
- ResponseTime: gotime.Current().Time, //【返回】时间
- ResponseCode: responseCode, //【返回】状态码
- ResponseData: responseBody, //【返回】数据
- CostTime: endTime - startTime, //【系统】花费时间
+ TraceID: traceId, //【系统】跟踪编号
+ RequestTime: requestTime, //【请求】时间
+ RequestURL: ginCtx.Request.RequestURI, //【请求】请求链接
+ RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
+ RequestMethod: ginCtx.Request.Method, //【请求】请求方式
+ RequestProto: ginCtx.Request.Proto, //【请求】请求协议
+ RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
+ RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
+ RequestBody: dorm.JsonEncodeNoError(requestBody), //【请求】请求主体
+ RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数
+ RequestIP: requestIp, //【请求】请求客户端IP
+ RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
+ ResponseTime: gotime.Current().Time, //【返回】时间
+ ResponseCode: responseCode, //【返回】状态码
+ ResponseData: responseBody, //【返回】数据
+ CostTime: endTime - startTime, //【系统】花费时间
}
if ginCtx.Request.TLS == nil {
data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接
diff --git a/gin_slog.go b/gin_slog.go
index 76c4a61..94a3438 100644
--- a/gin_slog.go
+++ b/gin_slog.go
@@ -4,7 +4,6 @@ import (
"bytes"
"context"
"github.com/gin-gonic/gin"
- "go.dtapp.net/goip"
"go.dtapp.net/gojson"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
@@ -14,8 +13,7 @@ import (
// GinSLog 框架日志
type GinSLog struct {
- ipService *goip.Client // IP服务
- slog struct {
+ slog struct {
status bool // 状态
client *SLog // 日志服务
}
@@ -25,9 +23,8 @@ type GinSLog struct {
type GinSLogFun func() *GinSLog
// NewGinSLog 创建框架实例化
-func NewGinSLog(ctx context.Context, ipService *goip.Client) (*GinSLog, error) {
+func NewGinSLog(ctx context.Context) (*GinSLog, error) {
c := &GinSLog{}
- c.ipService = ipService
return c, nil
}
@@ -96,17 +93,12 @@ func (gl *GinSLog) Middleware() gin.HandlerFunc {
go func() {
- clientIp := gorequest.ClientIp(ginCtx.Request)
- var info = goip.AnalyseResult{}
-
- if gl.ipService != nil {
- info = gl.ipService.Analyse(clientIp)
- }
+ requestIp := gorequest.ClientIp(ginCtx.Request)
var traceId = gotrace_id.GetGinTraceId(ginCtx)
// 记录
- gl.recordJson(ginCtx, traceId, requestTime, paramsBody, responseCode, responseBody, startTime, endTime, info)
+ gl.recordJson(ginCtx, traceId, requestTime, paramsBody, responseCode, responseBody, startTime, endTime, requestIp)
}()
}
diff --git a/gin_slog_custom.go b/gin_slog_custom.go
index 02e459f..5f3158c 100644
--- a/gin_slog_custom.go
+++ b/gin_slog_custom.go
@@ -2,13 +2,11 @@ package golog
import (
"context"
- "go.dtapp.net/goip"
)
// GinSLogCustom 框架自定义日志
type GinSLogCustom struct {
- ipService *goip.Client // IP服务
- slog struct {
+ slog struct {
status bool // 状态
client *SLog // 日志服务
}
@@ -18,8 +16,7 @@ type GinSLogCustom struct {
type GinSLogCustomFun func() *GinSLogCustom
// NewGinSLogCustom 创建框架实例化
-func NewGinSLogCustom(ctx context.Context, ipService *goip.Client) (*GinSLogCustom, error) {
+func NewGinSLogCustom(ctx context.Context) (*GinSLogCustom, error) {
c := &GinSLogCustom{}
- c.ipService = ipService
return c, nil
}
diff --git a/gin_slog_custom_record.go b/gin_slog_custom_record.go
index b00e5be..6eeefc8 100644
--- a/gin_slog_custom_record.go
+++ b/gin_slog_custom_record.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"go.dtapp.net/dorm"
- "go.dtapp.net/goip"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotrace_id"
"go.dtapp.net/gourl"
@@ -12,31 +11,24 @@ import (
// 结构体
type ginSLogCustom struct {
- TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
- RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
- RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
- RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
- RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
- RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
- RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
- RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
- RequestUrlQuery string `json:"request_url_query,omitempty"` //【请求】请求URL参数
- RequestHeader string `json:"request_header,omitempty"` //【请求】请求头
- RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端Ip
- RequestIpCountry string `json:"request_ip_country,omitempty"` //【请求】请求客户端城市
- RequestIpProvince string `json:"request_ip_province,omitempty"` //【请求】请求客户端省份
- RequestIpCity string `json:"request_ip_city,omitempty"` //【请求】请求客户端城市
- RequestIpIsp string `json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
- RequestIpLongitude float64 `json:"request_ip_longitude,omitempty"` //【请求】请求客户端经度
- RequestIpLatitude float64 `json:"request_ip_latitude,omitempty"` //【请求】请求客户端纬度
- CustomID string `json:"custom_id,omitempty"` //【日志】自定义编号
- CustomType string `json:"custom_type,omitempty"` //【日志】自定义类型
- CustomContent string `json:"custom_content,omitempty"` //【日志】自定义内容
+ TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
+ RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
+ RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
+ RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
+ RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
+ RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
+ RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
+ RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
+ RequestUrlQuery string `json:"request_url_query,omitempty"` //【请求】请求URL参数
+ RequestHeader string `json:"request_header,omitempty"` //【请求】请求头
+ RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端IP
+ CustomID string `json:"custom_id,omitempty"` //【日志】自定义编号
+ CustomType string `json:"custom_type,omitempty"` //【日志】自定义类型
+ CustomContent string `json:"custom_content,omitempty"` //【日志】自定义内容
}
type GinCustomClientGinRecordOperation struct {
slogClient *SLog // 日志服务
- ipService *goip.Client // IP服务
data *ginSLogCustom // 数据
}
@@ -44,7 +36,6 @@ type GinCustomClientGinRecordOperation struct {
func (c *GinSLogCustom) GinRecord(ginCtx *gin.Context) *GinCustomClientGinRecordOperation {
operation := &GinCustomClientGinRecordOperation{
slogClient: c.slog.client,
- ipService: c.ipService,
}
operation.data = new(ginSLogCustom)
operation.data.TraceID = gotrace_id.GetGinTraceId(ginCtx) // 【系统】跟踪编号
@@ -84,12 +75,6 @@ func (o *GinCustomClientGinRecordOperation) CreateData() {
"request_url_query", o.data.RequestUrlQuery,
"request_header", o.data.RequestHeader,
"request_ip", o.data.RequestIP,
- "request_ip_country", o.data.RequestIpCountry,
- "request_ip_province", o.data.RequestIpProvince,
- "request_ip_city", o.data.RequestIpCity,
- "request_ip_isp", o.data.RequestIpIsp,
- "request_ip_longitude", o.data.RequestIpLongitude,
- "request_ip_latitude", o.data.RequestIpLatitude,
"custom_id", o.data.CustomID,
"custom_type", o.data.CustomType,
"custom_content", o.data.CustomContent,
@@ -108,12 +93,6 @@ func (o *GinCustomClientGinRecordOperation) CreateDataNoError() {
"request_url_query", o.data.RequestUrlQuery,
"request_header", o.data.RequestHeader,
"request_ip", o.data.RequestIP,
- "request_ip_country", o.data.RequestIpCountry,
- "request_ip_province", o.data.RequestIpProvince,
- "request_ip_city", o.data.RequestIpCity,
- "request_ip_isp", o.data.RequestIpIsp,
- "request_ip_longitude", o.data.RequestIpLongitude,
- "request_ip_latitude", o.data.RequestIpLatitude,
"custom_id", o.data.CustomID,
"custom_type", o.data.CustomType,
"custom_content", o.data.CustomContent,
diff --git a/gin_slog_record.go b/gin_slog_record.go
index e067258..778310f 100644
--- a/gin_slog_record.go
+++ b/gin_slog_record.go
@@ -2,7 +2,6 @@ package golog
import (
"github.com/gin-gonic/gin"
- "go.dtapp.net/goip"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
"go.dtapp.net/gourl"
@@ -11,31 +10,25 @@ import (
// 结构体
type ginSLog struct {
- TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
- RequestTime time.Time `json:"request_time,omitempty"` //【请求】时间
- RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
- RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
- RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
- RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
- RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
- RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
- RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
- RequestBody string `json:"request_body,omitempty"` //【请求】请求主体
- RequestUrlQuery map[string][]string `json:"request_url_query,omitempty"` //【请求】请求URL参数
- RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端Ip
- RequestIpCountry string `json:"request_ip_country,omitempty"` //【请求】请求客户端城市
- RequestIpProvince string `json:"request_ip_province,omitempty"` //【请求】请求客户端省份
- RequestIpCity string `json:"request_ip_city,omitempty"` //【请求】请求客户端城市
- RequestIpIsp string `json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
- RequestIpLongitude float64 `json:"request_ip_longitude,omitempty"` //【请求】请求客户端经度
- RequestIpLatitude float64 `json:"request_ip_latitude,omitempty"` //【请求】请求客户端纬度
- RequestHeader map[string][]string `json:"request_header,omitempty"` //【请求】请求头
- RequestAllContent map[string]interface{} `json:"request_all_content,omitempty"` // 【请求】请求全部内容
- ResponseTime time.Time `json:"response_time,omitempty"` //【返回】时间
- ResponseCode int `json:"response_code,omitempty"` //【返回】状态码
- ResponseMsg string `json:"response_msg,omitempty"` //【返回】描述
- ResponseData string `json:"response_data,omitempty"` //【返回】数据
- CostTime int64 `json:"cost_time,omitempty"` //【系统】花费时间
+ TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
+ RequestTime time.Time `json:"request_time,omitempty"` //【请求】时间
+ RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
+ RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
+ RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
+ RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
+ RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
+ RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
+ RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
+ RequestBody string `json:"request_body,omitempty"` //【请求】请求主体
+ RequestUrlQuery map[string][]string `json:"request_url_query,omitempty"` //【请求】请求URL参数
+ RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端IP
+ RequestHeader map[string][]string `json:"request_header,omitempty"` //【请求】请求头
+ RequestAllContent map[string]interface{} `json:"request_all_content,omitempty"` // 【请求】请求全部内容
+ ResponseTime time.Time `json:"response_time,omitempty"` //【返回】时间
+ ResponseCode int `json:"response_code,omitempty"` //【返回】状态码
+ ResponseMsg string `json:"response_msg,omitempty"` //【返回】描述
+ ResponseData string `json:"response_data,omitempty"` //【返回】数据
+ CostTime int64 `json:"cost_time,omitempty"` //【系统】花费时间
}
// record 记录日志
@@ -52,12 +45,6 @@ func (gl *GinSLog) record(msg string, data ginSLog) {
"request_body", data.RequestBody,
"request_url_query", data.RequestUrlQuery,
"request_ip", data.RequestIP,
- "request_ip_country", data.RequestIpCountry,
- "request_ip_province", data.RequestIpProvince,
- "request_ip_city", data.RequestIpCity,
- "request_ip_isp", data.RequestIpIsp,
- "request_ip_longitude", data.RequestIpLongitude,
- "request_ip_latitude", data.RequestIpLatitude,
"request_header", data.RequestHeader,
"request_all_content", data.RequestAllContent,
"response_time", data.ResponseTime,
@@ -68,30 +55,24 @@ func (gl *GinSLog) record(msg string, data ginSLog) {
)
}
-func (gl *GinSLog) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
+func (gl *GinSLog) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, requestIp string) {
data := ginSLog{
- TraceID: traceId, //【系统】跟踪编号
- RequestTime: requestTime, //【请求】时间
- RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接
- RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
- RequestMethod: ginCtx.Request.Method, //【请求】请求方式
- RequestProto: ginCtx.Request.Proto, //【请求】请求协议
- RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
- RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
- RequestUrlQuery: ginCtx.Request.URL.Query(), //【请求】请求URL参数
- RequestIP: ipInfo.Ip, //【请求】请求客户端Ip
- RequestIpCountry: ipInfo.Country, //【请求】请求客户端城市
- RequestIpProvince: ipInfo.Province, //【请求】请求客户端省份
- RequestIpCity: ipInfo.City, //【请求】请求客户端城市
- RequestIpIsp: ipInfo.Isp, //【请求】请求客户端运营商
- RequestIpLatitude: ipInfo.LocationLatitude, //【请求】请求客户端纬度
- RequestIpLongitude: ipInfo.LocationLongitude, //【请求】请求客户端经度
- RequestHeader: ginCtx.Request.Header, //【请求】请求头
- RequestAllContent: paramsBody, //【请求】请求全部内容
- ResponseTime: gotime.Current().Time, //【返回】时间
- ResponseCode: responseCode, //【返回】状态码
- ResponseData: responseBody, //【返回】数据
- CostTime: endTime - startTime, //【系统】花费时间
+ TraceID: traceId, //【系统】跟踪编号
+ RequestTime: requestTime, //【请求】时间
+ RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接
+ RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
+ RequestMethod: ginCtx.Request.Method, //【请求】请求方式
+ RequestProto: ginCtx.Request.Proto, //【请求】请求协议
+ RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
+ RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
+ RequestUrlQuery: ginCtx.Request.URL.Query(), //【请求】请求URL参数
+ RequestIP: requestIp, //【请求】请求客户端IP
+ RequestHeader: ginCtx.Request.Header, //【请求】请求头
+ RequestAllContent: paramsBody, //【请求】请求全部内容
+ ResponseTime: gotime.Current().Time, //【返回】时间
+ ResponseCode: responseCode, //【返回】状态码
+ ResponseData: responseBody, //【返回】数据
+ CostTime: endTime - startTime, //【系统】花费时间
}
if ginCtx.Request.TLS == nil {
data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接
diff --git a/go.mod b/go.mod
index f038b80..37882dd 100644
--- a/go.mod
+++ b/go.mod
@@ -7,9 +7,8 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/shirou/gopsutil v3.21.11+incompatible
go.dtapp.net/dorm v1.0.55
- go.dtapp.net/goip v1.0.43
go.dtapp.net/gojson v1.0.2
- go.dtapp.net/gorequest v1.0.41
+ go.dtapp.net/gorequest v1.0.43
go.dtapp.net/gotime v1.0.6
go.dtapp.net/gotrace_id v1.0.8
go.dtapp.net/gourl v1.0.0
@@ -45,8 +44,6 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
- github.com/oschwald/geoip2-golang v1.9.0 // indirect
- github.com/oschwald/maxminddb-golang v1.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/redis/go-redis/v9 v9.3.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
diff --git a/go.sum b/go.sum
index 5ef69f0..a5977e3 100644
--- a/go.sum
+++ b/go.sum
@@ -98,10 +98,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
-github.com/oschwald/geoip2-golang v1.9.0 h1:uvD3O6fXAXs+usU+UGExshpdP13GAqp4GBrzN7IgKZc=
-github.com/oschwald/geoip2-golang v1.9.0/go.mod h1:BHK6TvDyATVQhKNbQBdrj9eAvuwOMi2zSFXizL3K81Y=
-github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
-github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -137,14 +133,14 @@ github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFi
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.dtapp.net/dorm v1.0.55 h1:Rugp1hvkEViqAqUi1A/zfJIo7r8Mvvwm5WlTlMVOFLU=
go.dtapp.net/dorm v1.0.55/go.mod h1:i0n38FMHLPIL7EXDJI3bMmLEtWOJB/6WaNMcGdnryWg=
-go.dtapp.net/goip v1.0.43 h1:yMNY3rO3UIAQrU5hmW6iOA5BjFe8KdO9tpxLss4GE1Y=
-go.dtapp.net/goip v1.0.43/go.mod h1:TKeAxhyauVFgX+lPNbD4Ek1/4g2EELz17IH9TCXoolI=
go.dtapp.net/gojson v1.0.2 h1:NjslBOhAK3XvJepkML7LXcJRPtSfp3rDXGK/29VlDBw=
go.dtapp.net/gojson v1.0.2/go.mod h1:U0Vd2iSLKqdyg6oungBJVHxuYswTbeQVjruQC3/JqQ4=
go.dtapp.net/gorandom v1.0.2 h1:08BdcBP/fQiRw2Ii0OXATSTtObwNydlDlqc/j/u5O8Q=
go.dtapp.net/gorandom v1.0.2/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
-go.dtapp.net/gorequest v1.0.41 h1:IaWPZ4oYEGsFQdnZrJseY+ytxyAcqtrOmwRsm+g5K2s=
-go.dtapp.net/gorequest v1.0.41/go.mod h1:iX5s9j4EzQC+6ShOIK3+GPvjjq9fN+7Y/wj6XV8sbQc=
+go.dtapp.net/gorequest v1.0.42 h1:5089qYomLNodUKOw6ptZe9SM0gtCFFUj6IcjtxunpxU=
+go.dtapp.net/gorequest v1.0.42/go.mod h1:iX5s9j4EzQC+6ShOIK3+GPvjjq9fN+7Y/wj6XV8sbQc=
+go.dtapp.net/gorequest v1.0.43 h1:+kBct5BSXhrQXm/pj9Wg1u+7Mc2kwsK8Jms5zK3MvWc=
+go.dtapp.net/gorequest v1.0.43/go.mod h1:iX5s9j4EzQC+6ShOIK3+GPvjjq9fN+7Y/wj6XV8sbQc=
go.dtapp.net/gostring v1.0.13 h1:Z4R6f9q9arQlkSGNywVQssxxv0LkjHsRjHt/hfwO6/M=
go.dtapp.net/gostring v1.0.13/go.mod h1:qgEjuf0/TFC3ZtvZ9y5tWHBSmV1GmlKiRxhJYJih9uk=
go.dtapp.net/gotime v1.0.6 h1:f8YowUxpZtJbYawe5s5PmvGxRj61ydlzxAPYr5Fcetg=
diff --git a/version.go b/version.go
index 648c560..c7c3137 100644
--- a/version.go
+++ b/version.go
@@ -1,5 +1,5 @@
package golog
const (
- Version = "1.0.105"
+ Version = "1.0.106"
)