diff --git a/utils/golog/api_mongo.go b/utils/golog/api_mongo.go index 73f4bacb..fa181ed7 100644 --- a/utils/golog/api_mongo.go +++ b/utils/golog/api_mongo.go @@ -51,53 +51,53 @@ func (c *ApiClient) MongoQuery() *dorm.MongoClient { // MongoMiddleware 中间件 func (c *ApiClient) MongoMiddleware(request gorequest.Response) { c.mongoRecord(apiMongoLog{ - RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp, //【请求】时间 - RequestUri: request.RequestUri, //【请求】链接 - RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 - RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口 - RequestMethod: request.RequestMethod, //【请求】方式 - RequestParams: request.RequestParams, //【请求】参数 - RequestHeader: request.RequestHeader, //【请求】头部 - ResponseHeader: request.ResponseHeader, //【返回】头部 - ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 - ResponseBody: request.ResponseBody, //【返回】内容 - ResponseContentLength: request.ResponseContentLength, //【返回】大小 - ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp, //【返回】时间 + RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp(), //【请求】时间 + RequestUri: request.RequestUri, //【请求】链接 + RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 + RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口 + RequestMethod: request.RequestMethod, //【请求】方式 + RequestParams: request.RequestParams, //【请求】参数 + RequestHeader: request.RequestHeader, //【请求】头部 + ResponseHeader: request.ResponseHeader, //【返回】头部 + ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 + ResponseBody: request.ResponseBody, //【返回】内容 + ResponseContentLength: request.ResponseContentLength, //【返回】大小 + ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp(), //【返回】时间 }) } // MongoMiddlewareXml 中间件 func (c *ApiClient) MongoMiddlewareXml(request gorequest.Response) { c.mongoRecord(apiMongoLog{ - RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp, //【请求】时间 - RequestUri: request.RequestUri, //【请求】链接 - RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 - RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口 - RequestMethod: request.RequestMethod, //【请求】方式 - RequestParams: request.RequestParams, //【请求】参数 - RequestHeader: request.RequestHeader, //【请求】头部 - ResponseHeader: request.ResponseHeader, //【返回】头部 - ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 - ResponseBody: dorm.XmlDecodeNoError(request.ResponseBody), //【返回】内容 - ResponseContentLength: request.ResponseContentLength, //【返回】大小 - ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp, //【返回】时间 + RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp(), //【请求】时间 + RequestUri: request.RequestUri, //【请求】链接 + RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 + RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口 + RequestMethod: request.RequestMethod, //【请求】方式 + RequestParams: request.RequestParams, //【请求】参数 + RequestHeader: request.RequestHeader, //【请求】头部 + ResponseHeader: request.ResponseHeader, //【返回】头部 + ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 + ResponseBody: dorm.XmlDecodeNoError(request.ResponseBody), //【返回】内容 + ResponseContentLength: request.ResponseContentLength, //【返回】大小 + ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp(), //【返回】时间 }) } // MongoMiddlewareCustom 中间件 func (c *ApiClient) MongoMiddlewareCustom(api string, request gorequest.Response) { c.mongoRecord(apiMongoLog{ - RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp, //【请求】时间 - RequestUri: request.RequestUri, //【请求】链接 - RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 - RequestApi: api, //【请求】接口 - RequestMethod: request.RequestMethod, //【请求】方式 - RequestParams: request.RequestParams, //【请求】参数 - RequestHeader: request.RequestHeader, //【请求】头部 - ResponseHeader: request.ResponseHeader, //【返回】头部 - ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 - ResponseBody: request.ResponseBody, //【返回】内容 - ResponseContentLength: request.ResponseContentLength, //【返回】大小 - ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp, //【返回】时间 + RequestTime: gotime.SetCurrent(request.RequestTime).Timestamp(), //【请求】时间 + RequestUri: request.RequestUri, //【请求】链接 + RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接 + RequestApi: api, //【请求】接口 + RequestMethod: request.RequestMethod, //【请求】方式 + RequestParams: request.RequestParams, //【请求】参数 + RequestHeader: request.RequestHeader, //【请求】头部 + ResponseHeader: request.ResponseHeader, //【返回】头部 + ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码 + ResponseBody: request.ResponseBody, //【返回】内容 + ResponseContentLength: request.ResponseContentLength, //【返回】大小 + ResponseTime: gotime.SetCurrent(request.ResponseTime).Timestamp(), //【返回】时间 }) } diff --git a/utils/golog/gin_mongo.go b/utils/golog/gin_mongo.go index 0475371b..978f664a 100644 --- a/utils/golog/gin_mongo.go +++ b/utils/golog/gin_mongo.go @@ -131,7 +131,7 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc { if len(jsonBody) > 0 { c.mongoRecord(ginMongoLog{ TraceId: ginCtx.MustGet("trace_id").(string), //【系统】链编号 - RequestTime: gotime.SetCurrent(requestTime).Timestamp, //【请求】时间 + RequestTime: gotime.SetCurrent(requestTime).Timestamp(), //【请求】时间 RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接 RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接 RequestApi: gorequest.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口 @@ -148,7 +148,7 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc { RequestIpCity: requestClientIpCity, //【请求】请求客户端城市 RequestIpIsp: requestClientIpIsp, //【请求】请求客户端运营商 RequestHeader: ginCtx.Request.Header, //【请求】请求头 - ResponseTime: gotime.SetCurrent(gotime.Current().Time).Timestamp, //【返回】时间 + ResponseTime: gotime.SetCurrent(gotime.Current().Time).Timestamp(), //【返回】时间 ResponseCode: responseCode, //【返回】状态码 ResponseData: c.jsonUnmarshal(responseBody), //【返回】数据 CostTime: endTime - startTime, //【系统】花费时间 @@ -156,7 +156,7 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc { } else { c.mongoRecord(ginMongoLog{ TraceId: ginCtx.MustGet("trace_id").(string), //【系统】链编号 - RequestTime: gotime.SetCurrent(requestTime).Timestamp, //【请求】时间 + RequestTime: gotime.SetCurrent(requestTime).Timestamp(), //【请求】时间 RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接 RequestUrl: ginCtx.Request.RequestURI, //【请求】请求链接 RequestApi: gorequest.UriFilterExcludeQueryString(ginCtx.Request.RequestURI), //【请求】请求接口 @@ -173,7 +173,7 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc { RequestIpCity: requestClientIpCity, //【请求】请求客户端城市 RequestIpIsp: requestClientIpIsp, //【请求】请求客户端运营商 RequestHeader: ginCtx.Request.Header, //【请求】请求头 - ResponseTime: gotime.SetCurrent(gotime.Current().Time).Timestamp, //【返回】时间 + ResponseTime: gotime.SetCurrent(gotime.Current().Time).Timestamp(), //【返回】时间 ResponseCode: responseCode, //【返回】状态码 ResponseData: c.jsonUnmarshal(responseBody), //【返回】数据 CostTime: endTime - startTime, //【系统】花费时间 diff --git a/utils/gotime/gotime.go b/utils/gotime/gotime.go index 4dc0825b..3bd7dfe0 100644 --- a/utils/gotime/gotime.go +++ b/utils/gotime/gotime.go @@ -23,10 +23,9 @@ const ( // Pro 结构体 type Pro struct { - Time time.Time - Timestamp int64 // Unix - loc *time.Location - Error error + Time time.Time + loc *time.Location + Error error } // NewPro 初始化结构体 diff --git a/utils/gotime/today.go b/utils/gotime/today.go index 4917b999..b1a082ba 100644 --- a/utils/gotime/today.go +++ b/utils/gotime/today.go @@ -22,7 +22,6 @@ func Current() Pro { p.Time = time.Now().In(p.loc) } - p.Timestamp = p.Time.Unix() return p } @@ -33,8 +32,6 @@ func SetCurrent(sTime time.Time) Pro { p.Time = sTime - p.Timestamp = p.Time.Unix() - return p } @@ -72,8 +69,6 @@ func SetCurrentParse(str string) Pro { p.Time = location - p.Timestamp = p.Time.Unix() - return p } @@ -84,11 +79,14 @@ func SetCurrentUnix(ts int64) Pro { p.Time = time.Unix(ts, 0) - p.Timestamp = p.Time.Unix() - return p } +// Timestamp 今天此刻时间戳 +func (p Pro) Timestamp() int64 { + return p.Time.Unix() +} + // Now 今天此刻 func (p Pro) Now() time.Time { return p.Time diff --git a/utils/gotime/tomorrow.go b/utils/gotime/tomorrow.go index 303d135e..bfada328 100644 --- a/utils/gotime/tomorrow.go +++ b/utils/gotime/tomorrow.go @@ -15,6 +15,5 @@ func Tomorrow() Pro { p.Time = time.Now().In(location).AddDate(0, 0, +1) } - p.Timestamp = p.Time.Unix() return p } diff --git a/utils/gotime/yesterday.go b/utils/gotime/yesterday.go index 5bb44a61..de89489a 100644 --- a/utils/gotime/yesterday.go +++ b/utils/gotime/yesterday.go @@ -17,6 +17,5 @@ func Yesterday() Pro { p.Time = time.Now().In(location).AddDate(0, 0, -1) } - p.Timestamp = p.Time.Unix() return p }