- update ip

master v1.0.106
dtapps 5 months ago
parent 78c77ff6ad
commit c3f557e7f1

@ -11,5 +11,5 @@
#### 安装 #### 安装
```shell ```shell
go get -v -u go.dtapp.net/golog@v1.0.105 go get -v -u go.dtapp.net/golog@v1.0.106
``` ```

@ -6,7 +6,6 @@ import (
"errors" "errors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.dtapp.net/dorm" "go.dtapp.net/dorm"
"go.dtapp.net/goip"
"go.dtapp.net/gojson" "go.dtapp.net/gojson"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"go.dtapp.net/gotime" "go.dtapp.net/gotime"
@ -17,7 +16,6 @@ import (
// GinGorm 框架日志 // GinGorm 框架日志
type GinGorm struct { type GinGorm struct {
gormClient *dorm.GormClient // 数据库驱动 gormClient *dorm.GormClient // 数据库驱动
ipService *goip.Client // IP服务
config struct { config struct {
systemHostname string // 主机名 systemHostname string // 主机名
systemOs string // 系统类型 systemOs string // 系统类型
@ -43,7 +41,7 @@ type GinGorm struct {
type GinGormFun func() *GinGorm type GinGormFun func() *GinGorm
// NewGinGorm 创建框架实例化 // 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{} gg := &GinGorm{}
@ -53,8 +51,6 @@ func NewGinGorm(ctx context.Context, systemOutsideIp string, ipService *goip.Cli
} }
gg.setConfig(ctx, systemOutsideIp) gg.setConfig(ctx, systemOutsideIp)
gg.ipService = ipService
if gormClient == nil || gormClient.GetDb() == nil { if gormClient == nil || gormClient.GetDb() == nil {
gg.gormConfig.stats = false gg.gormConfig.stats = false
} else { } else {
@ -141,17 +137,12 @@ func (gg *GinGorm) Middleware() gin.HandlerFunc {
go func() { go func() {
clientIp := gorequest.ClientIp(ginCtx.Request) requestIp := gorequest.ClientIp(ginCtx.Request)
var info = goip.AnalyseResult{}
if gg.ipService != nil {
info = gg.ipService.Analyse(clientIp)
}
var traceId = gotrace_id.GetGinTraceId(ginCtx) 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)
}() }()
} }

@ -2,7 +2,7 @@ package golog
import ( import (
"context" "context"
"go.dtapp.net/goip" "go.dtapp.net/gorequest"
"runtime" "runtime"
) )
@ -20,7 +20,7 @@ func (gg *GinGorm) setConfig(ctx context.Context, systemOutsideIp string) {
gg.config.cpuModelName = info.CpuModelName gg.config.cpuModelName = info.CpuModelName
gg.config.cpuMhz = info.CpuMhz gg.config.cpuMhz = info.CpuMhz
gg.config.systemInsideIp = goip.GetInsideIp(ctx) gg.config.systemInsideIp = gorequest.GetInsideIp(ctx)
gg.config.systemOutsideIp = systemOutsideIp gg.config.systemOutsideIp = systemOutsideIp
gg.config.sdkVersion = Version gg.config.sdkVersion = Version

@ -4,7 +4,6 @@ import (
"context" "context"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.dtapp.net/dorm" "go.dtapp.net/dorm"
"go.dtapp.net/goip"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"go.dtapp.net/gotime" "go.dtapp.net/gotime"
"go.dtapp.net/gourl" "go.dtapp.net/gourl"
@ -14,37 +13,31 @@ import (
// 模型 // 模型
type ginPostgresqlLog struct { type ginPostgresqlLog struct {
LogId uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号 LogID uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
TraceId string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号 TraceID string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号
RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间 RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间
RequestUri string `gorm:"comment:【请求】请求链接 域名+路径+参数" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数 RequestUri string `gorm:"comment:【请求】请求链接 域名+路径+参数" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
RequestUrl string `gorm:"comment:【请求】请求链接 域名+路径" json:"request_url,omitempty"` //【请求】请求链接 域名+路径 RequestURL string `gorm:"comment:【请求】请求链接 域名+路径" json:"request_url,omitempty"` //【请求】请求链接 域名+路径
RequestApi string `gorm:"index;comment:【请求】请求接口 路径" json:"request_api,omitempty"` //【请求】请求接口 路径 RequestApi string `gorm:"index;comment:【请求】请求接口 路径" json:"request_api,omitempty"` //【请求】请求接口 路径
RequestMethod string `gorm:"index;comment:【请求】请求方式" json:"request_method,omitempty"` //【请求】请求方式 RequestMethod string `gorm:"index;comment:【请求】请求方式" json:"request_method,omitempty"` //【请求】请求方式
RequestProto string `gorm:"comment:【请求】请求协议" json:"request_proto,omitempty"` //【请求】请求协议 RequestProto string `gorm:"comment:【请求】请求协议" json:"request_proto,omitempty"` //【请求】请求协议
RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer
RequestBody string `gorm:"comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体 RequestBody string `gorm:"comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
RequestUrlQuery string `gorm:"comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数 RequestUrlQuery string `gorm:"comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
RequestIp string `gorm:"index;comment:【请求】请求客户端Ip" json:"request_ip,omitempty"` //【请求】请求客户端Ip RequestIP string `gorm:"index;comment:【请求】请求客户端IP" json:"request_ip,omitempty"` //【请求】请求客户端IP
RequestIpCountry string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_country,omitempty"` //【请求】请求客户端城市 RequestHeader string `gorm:"comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头
RequestIpProvince string `gorm:"index;comment:【请求】请求客户端省份" json:"request_ip_province,omitempty"` //【请求】请求客户端省份 ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
RequestIpCity string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_city,omitempty"` //【请求】请求客户端城市 ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码
RequestIpIsp string `gorm:"index;comment:【请求】请求客户端运营商" json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商 ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述
RequestIpLongitude float64 `gorm:"index;comment:【请求】请求客户端经度" json:"request_ip_longitude,omitempty"` //【请求】请求客户端经度 ResponseData string `gorm:"comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据
RequestIpLatitude float64 `gorm:"index;comment:【请求】请求客户端纬度" json:"request_ip_latitude,omitempty"` //【请求】请求客户端纬度 CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间
RequestHeader string `gorm:"comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头 SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间 SystemInsideIP string `gorm:"comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码 SystemOs string `gorm:"index;comment:【系统】系统类型" json:"system_os,omitempty"` //【系统】系统类型
ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述 SystemArch string `gorm:"index;comment:【系统】系统架构" json:"system_arch,omitempty"` //【系统】系统架构
ResponseData string `gorm:"comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据 GoVersion string `gorm:"comment:【程序】Go版本" json:"go_version,omitempty"` //【程序】Go版本
CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间 SdkVersion string `gorm:"comment:【程序】Sdk版本" json:"sdk_version,omitempty"` //【程序】Sdk版本
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) { func (gg *GinGorm) gormRecord(data ginPostgresqlLog) {
data.SystemHostName = gg.config.systemHostname //【系统】主机名 data.SystemHostName = gg.config.systemHostname //【系统】主机名
data.SystemInsideIp = gg.config.systemInsideIp //【系统】内网ip data.SystemInsideIP = gg.config.systemInsideIp //【系统】内网ip
data.GoVersion = gg.config.goVersion //【程序】Go版本 data.GoVersion = gg.config.goVersion //【程序】Go版本
data.SdkVersion = gg.config.sdkVersion //【程序】Sdk版本 data.SdkVersion = gg.config.sdkVersion //【程序】Sdk版本
data.SystemOs = gg.config.systemOs //【系统】系统类型 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{ data := ginPostgresqlLog{
TraceId: traceId, //【系统】跟踪编号 TraceID: traceId, //【系统】跟踪编号
RequestTime: requestTime, //【请求】时间 RequestTime: requestTime, //【请求】时间
RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接 RequestURL: ginCtx.Request.RequestURI, //【请求】请求链接
RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口 RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
RequestMethod: ginCtx.Request.Method, //【请求】请求方式 RequestMethod: ginCtx.Request.Method, //【请求】请求方式
RequestProto: ginCtx.Request.Proto, //【请求】请求协议 RequestProto: ginCtx.Request.Proto, //【请求】请求协议
RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
RequestBody: dorm.JsonEncodeNoError(requestBody), //【请求】请求主体 RequestBody: dorm.JsonEncodeNoError(requestBody), //【请求】请求主体
RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数 RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数
RequestIp: ipInfo.Ip, //【请求】请求客户端Ip RequestIP: requestIp, //【请求】请求客户端IP
RequestIpCountry: ipInfo.Country, //【请求】请求客户端城市 RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
RequestIpProvince: ipInfo.Province, //【请求】请求客户端省份 ResponseTime: gotime.Current().Time, //【返回】时间
RequestIpCity: ipInfo.City, //【请求】请求客户端城市 ResponseCode: responseCode, //【返回】状态码
RequestIpIsp: ipInfo.Isp, //【请求】请求客户端运营商 ResponseData: responseBody, //【返回】数据
RequestIpLatitude: ipInfo.LocationLatitude, //【请求】请求客户端纬度 CostTime: endTime - startTime, //【系统】花费时间
RequestIpLongitude: ipInfo.LocationLongitude, //【请求】请求客户端经度
RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
ResponseTime: gotime.Current().Time, //【返回】时间
ResponseCode: responseCode, //【返回】状态码
ResponseData: responseBody, //【返回】数据
CostTime: endTime - startTime, //【系统】花费时间
} }
if ginCtx.Request.TLS == nil { if ginCtx.Request.TLS == nil {
data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接 data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.dtapp.net/goip"
"go.dtapp.net/gojson" "go.dtapp.net/gojson"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"go.dtapp.net/gotime" "go.dtapp.net/gotime"
@ -14,8 +13,7 @@ import (
// GinSLog 框架日志 // GinSLog 框架日志
type GinSLog struct { type GinSLog struct {
ipService *goip.Client // IP服务 slog struct {
slog struct {
status bool // 状态 status bool // 状态
client *SLog // 日志服务 client *SLog // 日志服务
} }
@ -25,9 +23,8 @@ type GinSLog struct {
type GinSLogFun func() *GinSLog type GinSLogFun func() *GinSLog
// NewGinSLog 创建框架实例化 // NewGinSLog 创建框架实例化
func NewGinSLog(ctx context.Context, ipService *goip.Client) (*GinSLog, error) { func NewGinSLog(ctx context.Context) (*GinSLog, error) {
c := &GinSLog{} c := &GinSLog{}
c.ipService = ipService
return c, nil return c, nil
} }
@ -96,17 +93,12 @@ func (gl *GinSLog) Middleware() gin.HandlerFunc {
go func() { go func() {
clientIp := gorequest.ClientIp(ginCtx.Request) requestIp := gorequest.ClientIp(ginCtx.Request)
var info = goip.AnalyseResult{}
if gl.ipService != nil {
info = gl.ipService.Analyse(clientIp)
}
var traceId = gotrace_id.GetGinTraceId(ginCtx) 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)
}() }()
} }

@ -2,13 +2,11 @@ package golog
import ( import (
"context" "context"
"go.dtapp.net/goip"
) )
// GinSLogCustom 框架自定义日志 // GinSLogCustom 框架自定义日志
type GinSLogCustom struct { type GinSLogCustom struct {
ipService *goip.Client // IP服务 slog struct {
slog struct {
status bool // 状态 status bool // 状态
client *SLog // 日志服务 client *SLog // 日志服务
} }
@ -18,8 +16,7 @@ type GinSLogCustom struct {
type GinSLogCustomFun func() *GinSLogCustom type GinSLogCustomFun func() *GinSLogCustom
// NewGinSLogCustom 创建框架实例化 // NewGinSLogCustom 创建框架实例化
func NewGinSLogCustom(ctx context.Context, ipService *goip.Client) (*GinSLogCustom, error) { func NewGinSLogCustom(ctx context.Context) (*GinSLogCustom, error) {
c := &GinSLogCustom{} c := &GinSLogCustom{}
c.ipService = ipService
return c, nil return c, nil
} }

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.dtapp.net/dorm" "go.dtapp.net/dorm"
"go.dtapp.net/goip"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"go.dtapp.net/gotrace_id" "go.dtapp.net/gotrace_id"
"go.dtapp.net/gourl" "go.dtapp.net/gourl"
@ -12,31 +11,24 @@ import (
// 结构体 // 结构体
type ginSLogCustom struct { type ginSLogCustom struct {
TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号 TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数 RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径 RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径 RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式 RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议 RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
RequestUrlQuery string `json:"request_url_query,omitempty"` //【请求】请求URL参数 RequestUrlQuery string `json:"request_url_query,omitempty"` //【请求】请求URL参数
RequestHeader string `json:"request_header,omitempty"` //【请求】请求头 RequestHeader string `json:"request_header,omitempty"` //【请求】请求头
RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端Ip RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端IP
RequestIpCountry string `json:"request_ip_country,omitempty"` //【请求】请求客户端城市 CustomID string `json:"custom_id,omitempty"` //【日志】自定义编号
RequestIpProvince string `json:"request_ip_province,omitempty"` //【请求】请求客户端省份 CustomType string `json:"custom_type,omitempty"` //【日志】自定义类型
RequestIpCity string `json:"request_ip_city,omitempty"` //【请求】请求客户端城市 CustomContent string `json:"custom_content,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"` //【日志】自定义内容
} }
type GinCustomClientGinRecordOperation struct { type GinCustomClientGinRecordOperation struct {
slogClient *SLog // 日志服务 slogClient *SLog // 日志服务
ipService *goip.Client // IP服务
data *ginSLogCustom // 数据 data *ginSLogCustom // 数据
} }
@ -44,7 +36,6 @@ type GinCustomClientGinRecordOperation struct {
func (c *GinSLogCustom) GinRecord(ginCtx *gin.Context) *GinCustomClientGinRecordOperation { func (c *GinSLogCustom) GinRecord(ginCtx *gin.Context) *GinCustomClientGinRecordOperation {
operation := &GinCustomClientGinRecordOperation{ operation := &GinCustomClientGinRecordOperation{
slogClient: c.slog.client, slogClient: c.slog.client,
ipService: c.ipService,
} }
operation.data = new(ginSLogCustom) operation.data = new(ginSLogCustom)
operation.data.TraceID = gotrace_id.GetGinTraceId(ginCtx) // 【系统】跟踪编号 operation.data.TraceID = gotrace_id.GetGinTraceId(ginCtx) // 【系统】跟踪编号
@ -84,12 +75,6 @@ func (o *GinCustomClientGinRecordOperation) CreateData() {
"request_url_query", o.data.RequestUrlQuery, "request_url_query", o.data.RequestUrlQuery,
"request_header", o.data.RequestHeader, "request_header", o.data.RequestHeader,
"request_ip", o.data.RequestIP, "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_id", o.data.CustomID,
"custom_type", o.data.CustomType, "custom_type", o.data.CustomType,
"custom_content", o.data.CustomContent, "custom_content", o.data.CustomContent,
@ -108,12 +93,6 @@ func (o *GinCustomClientGinRecordOperation) CreateDataNoError() {
"request_url_query", o.data.RequestUrlQuery, "request_url_query", o.data.RequestUrlQuery,
"request_header", o.data.RequestHeader, "request_header", o.data.RequestHeader,
"request_ip", o.data.RequestIP, "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_id", o.data.CustomID,
"custom_type", o.data.CustomType, "custom_type", o.data.CustomType,
"custom_content", o.data.CustomContent, "custom_content", o.data.CustomContent,

@ -2,7 +2,6 @@ package golog
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.dtapp.net/goip"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"go.dtapp.net/gotime" "go.dtapp.net/gotime"
"go.dtapp.net/gourl" "go.dtapp.net/gourl"
@ -11,31 +10,25 @@ import (
// 结构体 // 结构体
type ginSLog struct { type ginSLog struct {
TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号 TraceID string `json:"trace_id,omitempty"` //【系统】跟踪编号
RequestTime time.Time `json:"request_time,omitempty"` //【请求】时间 RequestTime time.Time `json:"request_time,omitempty"` //【请求】时间
RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数 RequestUri string `json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径 RequestUrl string `json:"request_url,omitempty"` //【请求】请求链接 域名+路径
RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径 RequestApi string `json:"request_api,omitempty"` //【请求】请求接口 路径
RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式 RequestMethod string `json:"request_method,omitempty"` //【请求】请求方式
RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议 RequestProto string `json:"request_proto,omitempty"` //【请求】请求协议
RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA RequestUa string `json:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer RequestReferer string `json:"request_referer,omitempty"` //【请求】请求referer
RequestBody string `json:"request_body,omitempty"` //【请求】请求主体 RequestBody string `json:"request_body,omitempty"` //【请求】请求主体
RequestUrlQuery map[string][]string `json:"request_url_query,omitempty"` //【请求】请求URL参数 RequestUrlQuery map[string][]string `json:"request_url_query,omitempty"` //【请求】请求URL参数
RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端Ip RequestIP string `json:"request_ip,omitempty"` //【请求】请求客户端IP
RequestIpCountry string `json:"request_ip_country,omitempty"` //【请求】请求客户端城市 RequestHeader map[string][]string `json:"request_header,omitempty"` //【请求】请求头
RequestIpProvince string `json:"request_ip_province,omitempty"` //【请求】请求客户端省份 RequestAllContent map[string]interface{} `json:"request_all_content,omitempty"` // 【请求】请求全部内容
RequestIpCity string `json:"request_ip_city,omitempty"` //【请求】请求客户端城市 ResponseTime time.Time `json:"response_time,omitempty"` //【返回】时间
RequestIpIsp string `json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商 ResponseCode int `json:"response_code,omitempty"` //【返回】状态码
RequestIpLongitude float64 `json:"request_ip_longitude,omitempty"` //【请求】请求客户端经度 ResponseMsg string `json:"response_msg,omitempty"` //【返回】描述
RequestIpLatitude float64 `json:"request_ip_latitude,omitempty"` //【请求】请求客户端纬度 ResponseData string `json:"response_data,omitempty"` //【返回】数据
RequestHeader map[string][]string `json:"request_header,omitempty"` //【请求】请求头 CostTime int64 `json:"cost_time,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 记录日志 // record 记录日志
@ -52,12 +45,6 @@ func (gl *GinSLog) record(msg string, data ginSLog) {
"request_body", data.RequestBody, "request_body", data.RequestBody,
"request_url_query", data.RequestUrlQuery, "request_url_query", data.RequestUrlQuery,
"request_ip", data.RequestIP, "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_header", data.RequestHeader,
"request_all_content", data.RequestAllContent, "request_all_content", data.RequestAllContent,
"response_time", data.ResponseTime, "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{ data := ginSLog{
TraceID: traceId, //【系统】跟踪编号 TraceID: traceId, //【系统】跟踪编号
RequestTime: requestTime, //【请求】时间 RequestTime: requestTime, //【请求】时间
RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接 RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接
RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口 RequestApi: gourl.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口
RequestMethod: ginCtx.Request.Method, //【请求】请求方式 RequestMethod: ginCtx.Request.Method, //【请求】请求方式
RequestProto: ginCtx.Request.Proto, //【请求】请求协议 RequestProto: ginCtx.Request.Proto, //【请求】请求协议
RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
RequestUrlQuery: ginCtx.Request.URL.Query(), //【请求】请求URL参数 RequestUrlQuery: ginCtx.Request.URL.Query(), //【请求】请求URL参数
RequestIP: ipInfo.Ip, //【请求】请求客户端Ip RequestIP: requestIp, //【请求】请求客户端IP
RequestIpCountry: ipInfo.Country, //【请求】请求客户端城市 RequestHeader: ginCtx.Request.Header, //【请求】请求头
RequestIpProvince: ipInfo.Province, //【请求】请求客户端省份 RequestAllContent: paramsBody, //【请求】请求全部内容
RequestIpCity: ipInfo.City, //【请求】请求客户端城市 ResponseTime: gotime.Current().Time, //【返回】时间
RequestIpIsp: ipInfo.Isp, //【请求】请求客户端运营商 ResponseCode: responseCode, //【返回】状态码
RequestIpLatitude: ipInfo.LocationLatitude, //【请求】请求客户端纬度 ResponseData: responseBody, //【返回】数据
RequestIpLongitude: ipInfo.LocationLongitude, //【请求】请求客户端经度 CostTime: endTime - startTime, //【系统】花费时间
RequestHeader: ginCtx.Request.Header, //【请求】请求头
RequestAllContent: paramsBody, //【请求】请求全部内容
ResponseTime: gotime.Current().Time, //【返回】时间
ResponseCode: responseCode, //【返回】状态码
ResponseData: responseBody, //【返回】数据
CostTime: endTime - startTime, //【系统】花费时间
} }
if ginCtx.Request.TLS == nil { if ginCtx.Request.TLS == nil {
data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接 data.RequestUri = "http://" + ginCtx.Request.Host + ginCtx.Request.RequestURI //【请求】请求链接

@ -7,9 +7,8 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/shirou/gopsutil v3.21.11+incompatible github.com/shirou/gopsutil v3.21.11+incompatible
go.dtapp.net/dorm v1.0.55 go.dtapp.net/dorm v1.0.55
go.dtapp.net/goip v1.0.43
go.dtapp.net/gojson v1.0.2 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/gotime v1.0.6
go.dtapp.net/gotrace_id v1.0.8 go.dtapp.net/gotrace_id v1.0.8
go.dtapp.net/gourl v1.0.0 go.dtapp.net/gourl v1.0.0
@ -45,8 +44,6 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // 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/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/redis/go-redis/v9 v9.3.1 // indirect github.com/redis/go-redis/v9 v9.3.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect

@ -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/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 h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= 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 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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= 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 h1:Rugp1hvkEViqAqUi1A/zfJIo7r8Mvvwm5WlTlMVOFLU=
go.dtapp.net/dorm v1.0.55/go.mod h1:i0n38FMHLPIL7EXDJI3bMmLEtWOJB/6WaNMcGdnryWg= 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 h1:NjslBOhAK3XvJepkML7LXcJRPtSfp3rDXGK/29VlDBw=
go.dtapp.net/gojson v1.0.2/go.mod h1:U0Vd2iSLKqdyg6oungBJVHxuYswTbeQVjruQC3/JqQ4= 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 h1:08BdcBP/fQiRw2Ii0OXATSTtObwNydlDlqc/j/u5O8Q=
go.dtapp.net/gorandom v1.0.2/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8= 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.42 h1:5089qYomLNodUKOw6ptZe9SM0gtCFFUj6IcjtxunpxU=
go.dtapp.net/gorequest v1.0.41/go.mod h1:iX5s9j4EzQC+6ShOIK3+GPvjjq9fN+7Y/wj6XV8sbQc= 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 h1:Z4R6f9q9arQlkSGNywVQssxxv0LkjHsRjHt/hfwO6/M=
go.dtapp.net/gostring v1.0.13/go.mod h1:qgEjuf0/TFC3ZtvZ9y5tWHBSmV1GmlKiRxhJYJih9uk= go.dtapp.net/gostring v1.0.13/go.mod h1:qgEjuf0/TFC3ZtvZ9y5tWHBSmV1GmlKiRxhJYJih9uk=
go.dtapp.net/gotime v1.0.6 h1:f8YowUxpZtJbYawe5s5PmvGxRj61ydlzxAPYr5Fcetg= go.dtapp.net/gotime v1.0.6 h1:f8YowUxpZtJbYawe5s5PmvGxRj61ydlzxAPYr5Fcetg=

@ -1,5 +1,5 @@
package golog package golog
const ( const (
Version = "1.0.105" Version = "1.0.106"
) )

Loading…
Cancel
Save