- update api
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

- update gin
master v1.0.22
李光春 2 years ago
parent 0105a46f00
commit c0fde6aa14

@ -1,8 +1,10 @@
package golog
import (
"context"
"go.dtapp.net/dorm"
"go.dtapp.net/gojson"
"go.dtapp.net/golog/gin_middleware"
"go.dtapp.net/gorequest"
"gorm.io/datatypes"
"gorm.io/gorm"
@ -33,7 +35,7 @@ type apiPostgresqlLog struct {
}
// 记录日志
func (c *ApiClient) gormRecord(postgresqlLog apiPostgresqlLog) error {
func (c *ApiClient) gormRecord(ctx context.Context, postgresqlLog apiPostgresqlLog) error {
if utf8.ValidString(string(postgresqlLog.ResponseBody)) == false {
postgresqlLog.ResponseBody = datatypes.JSON("")
@ -44,6 +46,7 @@ func (c *ApiClient) gormRecord(postgresqlLog apiPostgresqlLog) error {
postgresqlLog.SystemInsideIp = c.config.insideIp
}
postgresqlLog.GoVersion = c.config.goVersion
postgresqlLog.TraceId = gin_middleware.GetTraceIdContext(ctx)
return c.gormClient.Table(c.config.tableName).Create(&postgresqlLog).Error
}
@ -54,11 +57,11 @@ func (c *ApiClient) GormQuery() *gorm.DB {
}
// GormMiddleware 中间件
func (c *ApiClient) GormMiddleware(request gorequest.Response, sdkVersion string) {
func (c *ApiClient) GormMiddleware(ctx context.Context, request gorequest.Response, sdkVersion string) {
if request.ResponseHeader.Get("Content-Type") == "image/jpeg" || request.ResponseHeader.Get("Content-Type") == "image/png" {
return
}
c.gormRecord(apiPostgresqlLog{
c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
@ -76,8 +79,8 @@ func (c *ApiClient) GormMiddleware(request gorequest.Response, sdkVersion string
}
// GormMiddlewareXml 中间件
func (c *ApiClient) GormMiddlewareXml(request gorequest.Response, sdkVersion string) {
c.gormRecord(apiPostgresqlLog{
func (c *ApiClient) GormMiddlewareXml(ctx context.Context, request gorequest.Response, sdkVersion string) {
c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
@ -95,8 +98,8 @@ func (c *ApiClient) GormMiddlewareXml(request gorequest.Response, sdkVersion str
}
// GormMiddlewareCustom 中间件
func (c *ApiClient) GormMiddlewareCustom(api string, request gorequest.Response, sdkVersion string) {
c.gormRecord(apiPostgresqlLog{
func (c *ApiClient) GormMiddlewareCustom(ctx context.Context, api string, request gorequest.Response, sdkVersion string) {
c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接

@ -5,6 +5,7 @@ import (
"encoding/json"
"github.com/gin-gonic/gin"
"go.dtapp.net/gojson"
"go.dtapp.net/golog/gin_middleware"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
"go.dtapp.net/goxml"
@ -131,7 +132,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
}
if len(jsonBody) > 0 {
c.gormRecord(ginPostgresqlLog{
TraceId: ginCtx.MustGet("trace_id").(string), //【系统】链编号
TraceId: gin_middleware.GetTraceId(ginCtx), //【系统】链编号
RequestTime: requestTime, //【请求】时间
RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接
RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接
@ -156,7 +157,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
})
} else {
c.gormRecord(ginPostgresqlLog{
TraceId: ginCtx.MustGet("trace_id").(string), //【系统】链编号
TraceId: gin_middleware.GetTraceId(ginCtx), //【系统】链编号
RequestTime: requestTime, //【请求】时间
RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接
RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接

Loading…
Cancel
Save