parent
60c920467c
commit
bc71e2ab0f
@ -0,0 +1,24 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package douyin
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(api string, request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package kashangwl
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package pinduoduo
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(api string, request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package sendcloud
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(api string, request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseXml string `json:"response_xml" bson:"response_xml"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "wechatpayapiv2"
|
||||
}
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
_, _ = c.config.MongoDb.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: gomongo.XmlDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseXml: string(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatpayopen
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatqy
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wechatunion
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package weishi
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package wikeyun
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) mongoLog(request gorequest.Response) {
|
||||
c.log.MongoRecord(golog.ApiMongoLog{
|
||||
RequestTime: dorm.BsonTime(request.RequestTime), //【请求】时间
|
||||
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: dorm.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dorm
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// Begin 开始事务,不需要创建 Session 对象
|
||||
func (c *GormClient) Begin() *gorm.DB {
|
||||
return c.Db.Begin()
|
||||
}
|
||||
|
||||
// Rollback 回滚事务
|
||||
func (c *GormClient) Rollback() *gorm.DB {
|
||||
return c.Db.Rollback()
|
||||
}
|
||||
|
||||
// Commit 提交事务
|
||||
func (c *GormClient) Commit() *gorm.DB {
|
||||
return c.Db.Commit()
|
||||
}
|
@ -0,0 +1 @@
|
||||
package dorm
|
@ -0,0 +1,43 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
type MongoTransaction struct {
|
||||
startSession mongo.Session
|
||||
Session mongo.SessionContext
|
||||
}
|
||||
|
||||
// Begin 开始事务,会同时创建开始会话需要在退出时关闭会话
|
||||
func (c *MongoClient) Begin() (ms MongoTransaction, err error) {
|
||||
|
||||
// 开始会话
|
||||
ms.startSession, err = c.Db.StartSession()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 会话上下文
|
||||
ms.Session = mongo.NewSessionContext(context.Background(), ms.startSession)
|
||||
|
||||
// 会话开启事务
|
||||
err = ms.startSession.StartTransaction()
|
||||
return ms, err
|
||||
}
|
||||
|
||||
// Close 关闭会话
|
||||
func (ms *MongoTransaction) Close() {
|
||||
ms.startSession.EndSession(context.TODO())
|
||||
}
|
||||
|
||||
// Rollback 回滚事务
|
||||
func (ms *MongoTransaction) Rollback() error {
|
||||
return ms.startSession.AbortTransaction(context.Background())
|
||||
}
|
||||
|
||||
// Commit 提交事务
|
||||
func (ms *MongoTransaction) Commit() error {
|
||||
return ms.startSession.CommitTransaction(context.Background())
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type ConfigXormClient struct {
|
||||
Dns string // 地址
|
||||
}
|
||||
|
||||
type XormClient struct {
|
||||
Db *xorm.Engine // 驱动
|
||||
config *ConfigXormClient // 配置
|
||||
}
|
||||
|
||||
func NewXormMysqlClient(config *ConfigXormClient) (*XormClient, error) {
|
||||
|
||||
var err error
|
||||
c := &XormClient{config: config}
|
||||
|
||||
c.Db, err = xorm.NewEngine("mysql", c.config.Dns)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// XormClientSession https://xorm.io/zh/docs/chapter-10/readme/
|
||||
type XormClientSession struct {
|
||||
*xorm.Session
|
||||
}
|
||||
|
||||
// Begin 开始事务,需要创建 Session 对象
|
||||
//func (c *XormClient) Begin() (*XormClientSession, error) {
|
||||
// session := c.Db.NewSession()
|
||||
// defer session.Close()
|
||||
// return &session, session.Begin()
|
||||
//}
|
||||
|
||||
// Rollback 回滚事务
|
||||
//func (c *XormClientSession) Rollback() error {
|
||||
// return c.Rollback()
|
||||
//}
|
||||
|
||||
// Commit 提交事务
|
||||
//func (c *XormClientSession) Commit() error {
|
||||
// return c.Commit()
|
||||
//}
|
@ -0,0 +1,23 @@
|
||||
package golog
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
// ApiPostgresqlLog 结构体
|
||||
type ApiPostgresqlLog struct {
|
||||
LogId uint `gorm:"primaryKey" json:"log_id"` //【记录】编号
|
||||
RequestTime TimeString `gorm:"index" json:"request_time,omitempty"` //【请求】时间
|
||||
RequestUri string `gorm:"type:text" json:"request_uri,omitempty"` //【请求】链接
|
||||
RequestUrl string `gorm:"type:text" json:"request_url,omitempty"` //【请求】链接
|
||||
RequestApi string `gorm:"type:text;index" json:"request_api,omitempty"` //【请求】接口
|
||||
RequestMethod string `gorm:"type:text;index" json:"request_method,omitempty"` //【请求】方式
|
||||
RequestParams datatypes.JSON `gorm:"type:jsonb" json:"request_params,omitempty"` //【请求】参数
|
||||
RequestHeader datatypes.JSON `gorm:"type:jsonb" json:"request_header,omitempty"` //【请求】头部
|
||||
ResponseHeader datatypes.JSON `gorm:"type:jsonb" json:"response_header,omitempty"` //【返回】头部
|
||||
ResponseStatusCode int `gorm:"type:bigint" json:"response_status_code,omitempty"` //【返回】状态码
|
||||
ResponseBody datatypes.JSON `gorm:"type:jsonb" json:"response_body,omitempty"` //【返回】内容
|
||||
ResponseContentLength int64 `gorm:"type:bigint" json:"response_content_length,omitempty"` //【返回】大小
|
||||
ResponseTime TimeString `gorm:"index" json:"response_time,omitempty"` //【返回】时间
|
||||
SystemHostName string `gorm:"type:text" json:"system_host_name,omitempty"` //【系统】主机名
|
||||
SystemInsideIp string `gorm:"type:text" json:"system_inside_ip,omitempty"` //【系统】内网ip
|
||||
GoVersion string `gorm:"type:text" json:"go_version,omitempty"` //【程序】Go版本
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package golog
|
||||
|
||||
import (
|
||||
"github.com/siddontang/go/bson"
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
)
|
||||
|
||||
// ApiMongoLog 结构体
|
||||
type ApiMongoLog struct {
|
||||
LogId bson.ObjectId `json:"log_id" bson:"log_id"` //【记录】编号
|
||||
RequestTime dorm.BsonTime `json:"request_time,omitempty" bson:"request_time,omitempty"` //【请求】时间
|
||||
RequestUri string `json:"request_uri,omitempty" bson:"request_uri,omitempty"` //【请求】链接
|
||||
RequestUrl string `json:"request_url,omitempty" bson:"request_url,omitempty"` //【请求】链接
|
||||
RequestApi string `json:"request_api,omitempty" bson:"request_api,omitempty"` //【请求】接口
|
||||
RequestMethod string `json:"request_method,omitempty" bson:"request_method,omitempty"` //【请求】方式
|
||||
RequestParams map[string]interface{} `json:"request_params,omitempty" bson:"request_params,omitempty"` //【请求】参数
|
||||
RequestHeader map[string]string `json:"request_header,omitempty" bson:"request_header,omitempty"` //【请求】头部
|
||||
ResponseHeader map[string][]string `json:"response_header,omitempty" bson:"response_header,omitempty"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code,omitempty" bson:"response_status_code,omitempty"` //【返回】状态码
|
||||
ResponseBody interface{} `json:"response_body,omitempty" bson:"response_body,omitempty"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length,omitempty" bson:"response_content_length,omitempty"` //【返回】大小
|
||||
ResponseTime dorm.BsonTime `json:"response_time,omitempty" bson:"response_time,omitempty"` //【返回】时间
|
||||
SystemHostName string `json:"system_host_name,omitempty" bson:"system_host_name,omitempty"` //【系统】主机名
|
||||
SystemInsideIp string `json:"system_inside_ip,omitempty" bson:"system_inside_ip,omitempty"` //【系统】内网ip
|
||||
GoVersion string `json:"go_version,omitempty" bson:"go_version,omitempty"` //【程序】Go版本
|
||||
}
|
@ -1,97 +1,115 @@
|
||||
package golog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/siddontang/go/bson"
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"go.dtapp.net/library/utils/goip"
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ConfigGinClient struct {
|
||||
Db *gorm.DB // 驱动
|
||||
TableName string // 表名
|
||||
}
|
||||
|
||||
// GinClient 框架
|
||||
type GinClient struct {
|
||||
db *gorm.DB // pgsql数据库
|
||||
tableName string // 日志表名
|
||||
insideIp string // 内网ip
|
||||
hostname string // 主机名
|
||||
goVersion string // go版本
|
||||
gormClient *gorm.DB // 驱动
|
||||
mongoCollectionClient *dorm.MongoClient // 驱动(温馨提示:需要已选择库)
|
||||
config *struct {
|
||||
logType string // 日志类型
|
||||
tableName string // 表名
|
||||
insideIp string // 内网ip
|
||||
hostname string // 主机名
|
||||
goVersion string // go版本
|
||||
} // 配置
|
||||
}
|
||||
|
||||
// NewGinClient 创建框架实例化
|
||||
func NewGinClient(config *ConfigGinClient) (*GinClient, error) {
|
||||
func NewGinClient(attrs ...*OperationAttr) (*GinClient, error) {
|
||||
|
||||
c := &GinClient{}
|
||||
if config.Db == nil {
|
||||
return nil, errors.New("驱动不正常")
|
||||
for _, attr := range attrs {
|
||||
c.gormClient = attr.gormClient
|
||||
c.mongoCollectionClient = attr.mongoCollectionClient
|
||||
c.config.logType = attr.logType
|
||||
c.config.tableName = attr.tableName
|
||||
}
|
||||
if config.TableName == "" {
|
||||
return nil, errors.New("表名不能为空")
|
||||
|
||||
switch c.config.logType {
|
||||
case logTypeGorm:
|
||||
|
||||
if c.gormClient == nil {
|
||||
return nil, errors.New("驱动不能为空")
|
||||
}
|
||||
|
||||
if c.config.tableName == "" {
|
||||
return nil, errors.New("表名不能为空")
|
||||
}
|
||||
|
||||
err := c.gormClient.Table(c.config.tableName).AutoMigrate(&ApiPostgresqlLog{})
|
||||
if err != nil {
|
||||
return nil, errors.New("创建表失败:" + err.Error())
|
||||
}
|
||||
|
||||
case logTypeMongo:
|
||||
|
||||
if c.mongoCollectionClient.Db == nil {
|
||||
return nil, errors.New("驱动不能为空")
|
||||
}
|
||||
|
||||
if c.config.tableName == "" {
|
||||
return nil, errors.New("表名不能为空")
|
||||
}
|
||||
|
||||
c.mongoCollectionClient = c.mongoCollectionClient.Collection(c.config.tableName)
|
||||
|
||||
default:
|
||||
return nil, errors.New("驱动为空")
|
||||
}
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
|
||||
c.db = config.Db
|
||||
c.tableName = config.TableName
|
||||
c.hostname = hostname
|
||||
c.insideIp = goip.GetInsideIp()
|
||||
c.goVersion = strings.TrimPrefix(runtime.Version(), "go")
|
||||
c.config.hostname = hostname
|
||||
c.config.insideIp = goip.GetInsideIp()
|
||||
c.config.goVersion = strings.TrimPrefix(runtime.Version(), "go")
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// GormRecord 记录日志
|
||||
func (c *GinClient) GormRecord(postgresqlLog GinPostgresqlLog) error {
|
||||
|
||||
err := c.db.Table(c.tableName).AutoMigrate(&GinPostgresqlLog{})
|
||||
if err != nil {
|
||||
return nil, errors.New("创建表失败:" + err.Error())
|
||||
postgresqlLog.SystemHostName = c.config.hostname
|
||||
if postgresqlLog.SystemInsideIp == "" {
|
||||
postgresqlLog.SystemInsideIp = c.config.insideIp
|
||||
}
|
||||
postgresqlLog.GoVersion = c.config.goVersion
|
||||
|
||||
return c, nil
|
||||
return c.gormClient.Table(c.config.tableName).Create(&postgresqlLog).Error
|
||||
}
|
||||
|
||||
// GinPostgresqlLog 结构体
|
||||
type GinPostgresqlLog struct {
|
||||
LogId uint `gorm:"primaryKey" json:"log_id"` //【记录】编号
|
||||
TraceId string `gorm:"type:text" json:"trace_id"` //【系统】链编号
|
||||
RequestTime TimeString `gorm:"index" json:"request_time"` //【请求】时间
|
||||
RequestUri string `gorm:"type:text" json:"request_uri"` //【请求】请求链接 域名+路径+参数
|
||||
RequestUrl string `gorm:"type:text" json:"request_url"` //【请求】请求链接 域名+路径
|
||||
RequestApi string `gorm:"type:text;index" json:"request_api"` //【请求】请求接口 路径
|
||||
RequestMethod string `gorm:"type:text;index" json:"request_method"` //【请求】请求方式
|
||||
RequestProto string `gorm:"type:text" json:"request_proto"` //【请求】请求协议
|
||||
RequestUa string `gorm:"type:text" json:"request_ua"` //【请求】请求UA
|
||||
RequestReferer string `gorm:"type:text" json:"request_referer"` //【请求】请求referer
|
||||
RequestBody datatypes.JSON `gorm:"type:jsonb" json:"request_body"` //【请求】请求主体
|
||||
RequestUrlQuery datatypes.JSON `gorm:"type:jsonb" json:"request_url_query"` //【请求】请求URL参数
|
||||
RequestIp string `gorm:"type:text" json:"request_ip"` //【请求】请求客户端Ip
|
||||
RequestIpCountry string `gorm:"type:text" json:"request_ip_country"` //【请求】请求客户端城市
|
||||
RequestIpRegion string `gorm:"type:text" json:"request_ip_region"` //【请求】请求客户端区域
|
||||
RequestIpProvince string `gorm:"type:text" json:"request_ip_province"` //【请求】请求客户端省份
|
||||
RequestIpCity string `gorm:"type:text" json:"request_ip_city"` //【请求】请求客户端城市
|
||||
RequestIpIsp string `gorm:"type:text" json:"request_ip_isp"` //【请求】请求客户端运营商
|
||||
RequestHeader datatypes.JSON `gorm:"type:jsonb" json:"request_header"` //【请求】请求头
|
||||
ResponseTime TimeString `gorm:"index" json:"response_time"` //【返回】时间
|
||||
ResponseCode int `gorm:"type:bigint" json:"response_code"` //【返回】状态码
|
||||
ResponseMsg string `gorm:"type:text" json:"response_msg"` //【返回】描述
|
||||
ResponseData datatypes.JSON `gorm:"type:jsonb" json:"response_data"` //【返回】数据
|
||||
CostTime int64 `gorm:"type:bigint" json:"cost_time"` //【系统】花费时间
|
||||
SystemHostName string `gorm:"type:text" json:"system_host_name"` //【系统】主机名
|
||||
SystemInsideIp string `gorm:"type:text" json:"system_inside_ip"` //【系统】内网ip
|
||||
GoVersion string `gorm:"type:text" json:"go_version"` //【程序】Go版本
|
||||
// GormQuery 查询
|
||||
func (c *GinClient) GormQuery() *gorm.DB {
|
||||
return c.gormClient.Table(c.config.tableName)
|
||||
}
|
||||
|
||||
// Record 记录日志
|
||||
func (c *GinClient) Record(content GinPostgresqlLog) *gorm.DB {
|
||||
content.SystemHostName = c.hostname
|
||||
if content.SystemInsideIp == "" {
|
||||
content.SystemInsideIp = c.insideIp
|
||||
// MongoRecord 记录日志
|
||||
func (c *GinClient) MongoRecord(mongoLog GinMongoLog) error {
|
||||
|
||||
mongoLog.SystemHostName = c.config.hostname
|
||||
if mongoLog.SystemInsideIp == "" {
|
||||
mongoLog.SystemInsideIp = c.config.insideIp
|
||||
}
|
||||
content.GoVersion = c.goVersion
|
||||
return c.db.Table(c.tableName).Create(&content)
|
||||
mongoLog.GoVersion = c.config.goVersion
|
||||
|
||||
mongoLog.LogId = bson.NewObjectId()
|
||||
|
||||
_, err := c.mongoCollectionClient.InsertOne(context.Background(), mongoLog)
|
||||
return err
|
||||
}
|
||||
|
||||
// Query 查询
|
||||
func (c *GinClient) Query() *gorm.DB {
|
||||
return c.db.Table(c.tableName)
|
||||
// MongoQuery 查询
|
||||
func (c *GinClient) MongoQuery() *dorm.MongoClient {
|
||||
return c.mongoCollectionClient
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package golog
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
// GinPostgresqlLog 结构体
|
||||
type GinPostgresqlLog struct {
|
||||
LogId uint `gorm:"primaryKey" json:"log_id"` //【记录】编号
|
||||
TraceId string `gorm:"type:text" json:"trace_id,omitempty"` //【系统】链编号
|
||||
RequestTime TimeString `gorm:"index" json:"request_time,omitempty"` //【请求】时间
|
||||
RequestUri string `gorm:"type:text" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
|
||||
RequestUrl string `gorm:"type:text" json:"request_url,omitempty"` //【请求】请求链接 域名+路径
|
||||
RequestApi string `gorm:"type:text;index" json:"request_api,omitempty"` //【请求】请求接口 路径
|
||||
RequestMethod string `gorm:"type:text;index" json:"request_method,omitempty"` //【请求】请求方式
|
||||
RequestProto string `gorm:"type:text" json:"request_proto,omitempty"` //【请求】请求协议
|
||||
RequestUa string `gorm:"type:text" json:"request_ua,omitempty"` //【请求】请求UA
|
||||
RequestReferer string `gorm:"type:text" json:"request_referer,omitempty"` //【请求】请求referer
|
||||
RequestBody datatypes.JSON `gorm:"type:jsonb" json:"request_body,omitempty"` //【请求】请求主体
|
||||
RequestUrlQuery datatypes.JSON `gorm:"type:jsonb" json:"request_url_query,omitempty"` //【请求】请求URL参数
|
||||
RequestIp string `gorm:"type:text" json:"request_ip,omitempty"` //【请求】请求客户端Ip
|
||||
RequestIpCountry string `gorm:"type:text" json:"request_ip_country,omitempty"` //【请求】请求客户端城市
|
||||
RequestIpRegion string `gorm:"type:text" json:"request_ip_region,omitempty"` //【请求】请求客户端区域
|
||||
RequestIpProvince string `gorm:"type:text" json:"request_ip_province,omitempty"` //【请求】请求客户端省份
|
||||
RequestIpCity string `gorm:"type:text" json:"request_ip_city,omitempty"` //【请求】请求客户端城市
|
||||
RequestIpIsp string `gorm:"type:text" json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
|
||||
RequestHeader datatypes.JSON `gorm:"type:jsonb" json:"request_header,omitempty"` //【请求】请求头
|
||||
ResponseTime TimeString `gorm:"index" json:"response_time,omitempty"` //【返回】时间
|
||||
ResponseCode int `gorm:"type:bigint" json:"response_code,omitempty"` //【返回】状态码
|
||||
ResponseMsg string `gorm:"type:text" json:"response_msg,omitempty"` //【返回】描述
|
||||
ResponseData datatypes.JSON `gorm:"type:jsonb" json:"response_data,omitempty"` //【返回】数据
|
||||
CostTime int64 `gorm:"type:bigint" json:"cost_time,omitempty"` //【系统】花费时间
|
||||
SystemHostName string `gorm:"type:text" json:"system_host_name,omitempty"` //【系统】主机名
|
||||
SystemInsideIp string `gorm:"type:text" json:"system_inside_ip,omitempty"` //【系统】内网ip
|
||||
GoVersion string `gorm:"type:text" json:"go_version,omitempty"` //【程序】Go版本
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package golog
|
||||
|
||||
import (
|
||||
"github.com/siddontang/go/bson"
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
)
|
||||
|
||||
// GinMongoLog 结构体
|
||||
type GinMongoLog struct {
|
||||
LogId bson.ObjectId `json:"log_id" bson:"log_id"` //【记录】编号
|
||||
TraceId string `json:"trace_id,omitempty" bson:"trace_id,omitempty"` //【系统】链编号
|
||||
RequestTime dorm.BsonTime `json:"request_time,omitempty" bson:"request_time,omitempty"` //【请求】时间
|
||||
RequestUri string `json:"request_uri,omitempty" bson:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
|
||||
RequestUrl string `json:"request_url,omitempty" bson:"request_url,omitempty"` //【请求】请求链接 域名+路径
|
||||
RequestApi string `json:"request_api,omitempty" bson:"request_api,omitempty"` //【请求】请求接口 路径
|
||||
RequestMethod string `json:"request_method,omitempty" bson:"request_method,omitempty"` //【请求】请求方式
|
||||
RequestProto string `json:"request_proto,omitempty" bson:"request_proto,omitempty"` //【请求】请求协议
|
||||
RequestUa string `json:"request_ua,omitempty" bson:"request_ua,omitempty"` //【请求】请求UA
|
||||
RequestReferer string `json:"request_referer,omitempty" bson:"request_referer,omitempty"` //【请求】请求referer
|
||||
RequestBody interface{} `json:"request_body,omitempty" bson:"request_body,omitempty"` //【请求】请求主体
|
||||
RequestUrlQuery interface{} `json:"request_url_query,omitempty" bson:"request_url_query,omitempty"` //【请求】请求URL参数
|
||||
RequestIp string `json:"request_ip,omitempty" bson:"request_ip,omitempty"` //【请求】请求客户端Ip
|
||||
RequestIpCountry string `json:"request_ip_country,omitempty" bson:"request_ip_country,omitempty"` //【请求】请求客户端城市
|
||||
RequestIpRegion string `json:"request_ip_region,omitempty" bson:"request_ip_region,omitempty"` //【请求】请求客户端区域
|
||||
RequestIpProvince string `json:"request_ip_province,omitempty" bson:"request_ip_province,omitempty"` //【请求】请求客户端省份
|
||||
RequestIpCity string `json:"request_ip_city,omitempty" bson:"request_ip_city,omitempty"` //【请求】请求客户端城市
|
||||
RequestIpIsp string `json:"request_ip_isp,omitempty" bson:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
|
||||
RequestHeader interface{} `json:"request_header,omitempty" bson:"request_header,omitempty"` //【请求】请求头
|
||||
ResponseTime dorm.BsonTime `json:"response_time,omitempty" bson:"response_time,omitempty"` //【返回】时间
|
||||
ResponseCode int `json:"response_code,omitempty" bson:"response_code,omitempty"` //【返回】状态码
|
||||
ResponseMsg string `json:"response_msg,omitempty" bson:"response_msg,omitempty"` //【返回】描述
|
||||
ResponseData interface{} `json:"response_data,omitempty" bson:"response_data,omitempty"` //【返回】数据
|
||||
CostTime int64 `json:"cost_time,omitempty" bson:"cost_time,omitempty"` //【系统】花费时间
|
||||
SystemHostName string `json:"system_host_name,omitempty" bson:"system_host_name,omitempty"` //【系统】主机名
|
||||
SystemInsideIp string `json:"system_inside_ip,omitempty" bson:"system_inside_ip,omitempty"` //【系统】内网ip
|
||||
GoVersion string `json:"go_version,omitempty" bson:"go_version,omitempty"` //【程序】Go版本
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package golog
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/dorm"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
logTypeGorm = "gorm"
|
||||
logTypeMongo = "mongo"
|
||||
)
|
||||
|
||||
// OperationAttr 操作属性
|
||||
type OperationAttr struct {
|
||||
gormClient *gorm.DB // 驱动
|
||||
mongoCollectionClient *dorm.MongoClient // 驱动
|
||||
logType string // 类型
|
||||
tableName string // 表名
|
||||
}
|
||||
|
||||
// WithGormClient 数据库驱动
|
||||
func WithGormClient(client *gorm.DB) *OperationAttr {
|
||||
return &OperationAttr{gormClient: client, logType: logTypeGorm}
|
||||
}
|
||||
|
||||
// WithMongoCollectionClient 数据库驱动(温馨提示:需要已选择库)
|
||||
func WithMongoCollectionClient(client *dorm.MongoClient) *OperationAttr {
|
||||
return &OperationAttr{mongoCollectionClient: client, logType: logTypeMongo}
|
||||
}
|
||||
|
||||
// WithTableName 表名
|
||||
func WithTableName(tableName string) *OperationAttr {
|
||||
return &OperationAttr{tableName: tableName}
|
||||
}
|
Loading…
Reference in new issue