- update log

master
李光春 2 years ago
parent c48015018b
commit efefa6d809

@ -10,26 +10,29 @@ import (
// Client 实例
type Client struct {
gormClient *dorm.GormClient // 日志数据库
mongoClient *dorm.MongoClient // 日志数据库
requestClient *gorequest.App // 请求服务
requestClient *gorequest.App // 请求服务
config struct {
clientIp string // 当前Ip
storeId int // 店铺ID
appKey int // key
appSecret string // secret
debug bool // 日志开关
}
log struct {
gorm bool // 日志
gormClient *golog.ApiClient // 日志服务
mongo bool // 日志
mongoClient *golog.ApiClient // 日志服务
gormClient *dorm.GormClient // 日志数据库
gorm bool // 日志开关
logGormClient *golog.ApiClient // 日志服务
mongoClient *dorm.MongoClient // 日志数据库
mongo bool // 日志开关
logMongoClient *golog.ApiClient // 日志服务
}
}
// client *dorm.GormClient
type gormClientFun func() *dorm.GormClient
type mongoClientFun func() (client *dorm.MongoClient, databaseName string)
// client *dorm.MongoClient
// databaseName string
type mongoClientFun func() (*dorm.MongoClient, string)
// NewClient 创建实例化
// storeId 店铺ID
@ -47,8 +50,8 @@ func NewClient(storeId, appKey int, appSecret string, gormClientFun gormClientFu
c.requestClient = gorequest.NewHttp()
gormClient := gormClientFun()
if c.gormClient.Db != nil {
c.log.gormClient, err = golog.NewApiGormClient(func() (client *dorm.GormClient, tableName string) {
if gormClient.Db != nil {
c.log.logGormClient, err = golog.NewApiGormClient(func() (client *dorm.GormClient, tableName string) {
return gormClient, logTable
}, debug)
if err != nil {
@ -56,11 +59,11 @@ func NewClient(storeId, appKey int, appSecret string, gormClientFun gormClientFu
}
c.log.gorm = true
}
c.gormClient = gormClient
c.log.gormClient = gormClient
mongoClient, databaseName := mongoClientFun()
if c.mongoClient.Db != nil {
c.log.mongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) {
if mongoClient.Db != nil {
c.log.logMongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) {
return mongoClient, databaseName, logTable
}, debug)
if err != nil {
@ -68,7 +71,7 @@ func NewClient(storeId, appKey int, appSecret string, gormClientFun gormClientFu
}
c.log.mongo = true
}
c.mongoClient = mongoClient
c.log.mongoClient = mongoClient
xip := goip.GetOutsideIp(context.Background())
if xip != "" && xip != "0.0.0.0" {

@ -12,4 +12,4 @@ const (
logTable = "wikeyun"
)
const Version = "1.0.14"
const Version = "1.0.15"

@ -32,10 +32,10 @@ func (c *Client) request(ctx context.Context, url string, params map[string]inte
// 日志
if c.log.gorm == true {
go c.log.gormClient.GormMiddleware(ctx, request, Version)
go c.log.logGormClient.GormMiddleware(ctx, request, Version)
}
if c.log.mongo == true {
go c.log.mongoClient.GormMiddleware(ctx, request, Version)
go c.log.logMongoClient.MongoMiddleware(ctx, request, Version)
}
return request, err

Loading…
Cancel
Save