|
|
@ -12,7 +12,7 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 模型
|
|
|
|
// 模型
|
|
|
|
type apiPostgresqlLog struct {
|
|
|
|
type apiGormLog struct {
|
|
|
|
LogID int64 `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
|
|
|
|
LogID int64 `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"` //【请求】时间
|
|
|
@ -26,7 +26,6 @@ type apiPostgresqlLog struct {
|
|
|
|
ResponseHeader string `gorm:"comment:【返回】头部" json:"response_header,omitempty"` //【返回】头部
|
|
|
|
ResponseHeader string `gorm:"comment:【返回】头部" json:"response_header,omitempty"` //【返回】头部
|
|
|
|
ResponseStatusCode int `gorm:"index;comment:【返回】状态码" json:"response_status_code,omitempty"` //【返回】状态码
|
|
|
|
ResponseStatusCode int `gorm:"index;comment:【返回】状态码" json:"response_status_code,omitempty"` //【返回】状态码
|
|
|
|
ResponseBody string `gorm:"comment:【返回】数据" json:"response_body,omitempty"` //【返回】数据
|
|
|
|
ResponseBody string `gorm:"comment:【返回】数据" json:"response_body,omitempty"` //【返回】数据
|
|
|
|
ResponseContentLength int64 `gorm:"comment:【返回】大小" json:"response_content_length,omitempty"` //【返回】大小
|
|
|
|
|
|
|
|
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
|
|
|
|
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
|
|
|
|
SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
|
|
|
|
SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
|
|
|
|
SystemInsideIp string `gorm:"default:0.0.0.0;comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
|
|
|
|
SystemInsideIp string `gorm:"default:0.0.0.0;comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
|
|
|
@ -42,14 +41,14 @@ func (ag *ApiGorm) gormAutoMigrate(ctx context.Context) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err := ag.gormClient.Table(ag.gormConfig.tableName).AutoMigrate(&apiPostgresqlLog{})
|
|
|
|
err := ag.gormClient.Table(ag.gormConfig.tableName).AutoMigrate(&apiGormLog{})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("创建模型:%s", err)
|
|
|
|
log.Printf("创建模型:%s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 记录日志
|
|
|
|
// 记录日志
|
|
|
|
func (ag *ApiGorm) gormRecord(ctx context.Context, data apiPostgresqlLog) {
|
|
|
|
func (ag *ApiGorm) gormRecord(ctx context.Context, data apiGormLog) {
|
|
|
|
if ag.gormConfig.stats == false {
|
|
|
|
if ag.gormConfig.stats == false {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,7 +75,7 @@ func (ag *ApiGorm) gormRecord(ctx context.Context, data apiPostgresqlLog) {
|
|
|
|
|
|
|
|
|
|
|
|
// 中间件
|
|
|
|
// 中间件
|
|
|
|
func (ag *ApiGorm) gormMiddleware(ctx context.Context, request gorequest.Response) {
|
|
|
|
func (ag *ApiGorm) gormMiddleware(ctx context.Context, request gorequest.Response) {
|
|
|
|
data := apiPostgresqlLog{
|
|
|
|
data := apiGormLog{
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
@ -86,7 +85,6 @@ func (ag *ApiGorm) gormMiddleware(ctx context.Context, request gorequest.Respons
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
|
|
|
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
@ -100,7 +98,7 @@ func (ag *ApiGorm) gormMiddleware(ctx context.Context, request gorequest.Respons
|
|
|
|
|
|
|
|
|
|
|
|
// 中间件
|
|
|
|
// 中间件
|
|
|
|
func (ag *ApiGorm) gormMiddlewareXml(ctx context.Context, request gorequest.Response) {
|
|
|
|
func (ag *ApiGorm) gormMiddlewareXml(ctx context.Context, request gorequest.Response) {
|
|
|
|
data := apiPostgresqlLog{
|
|
|
|
data := apiGormLog{
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
@ -110,7 +108,6 @@ func (ag *ApiGorm) gormMiddlewareXml(ctx context.Context, request gorequest.Resp
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
|
|
|
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
@ -124,7 +121,7 @@ func (ag *ApiGorm) gormMiddlewareXml(ctx context.Context, request gorequest.Resp
|
|
|
|
|
|
|
|
|
|
|
|
// 中间件
|
|
|
|
// 中间件
|
|
|
|
func (ag *ApiGorm) gormMiddlewareCustom(ctx context.Context, api string, request gorequest.Response) {
|
|
|
|
func (ag *ApiGorm) gormMiddlewareCustom(ctx context.Context, api string, request gorequest.Response) {
|
|
|
|
data := apiPostgresqlLog{
|
|
|
|
data := apiGormLog{
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestTime: request.RequestTime, //【请求】时间
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUri: request.RequestUri, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
|
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
|
|
|
@ -134,7 +131,6 @@ func (ag *ApiGorm) gormMiddlewareCustom(ctx context.Context, api string, request
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
RequestHeader: gojson.JsonEncodeNoError(request.RequestHeader), //【请求】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseHeader: gojson.JsonEncodeNoError(request.ResponseHeader), //【返回】头部
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
|
|
|
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
|
|
|
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
ResponseTime: request.ResponseTime, //【返回】时间
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
|
if !request.HeaderIsImg() {
|
|
|
|