From faa2bc05831a16e45cd6a508c1885aed2da13fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Fri, 26 Aug 2022 15:45:02 +0800 Subject: [PATCH] - update log --- client.go | 12 ++++++------ const.go | 2 +- request.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 8d3a617..caae5d8 100644 --- a/client.go +++ b/client.go @@ -35,11 +35,11 @@ type Client struct { appSecret string // secret } log struct { - gormClient *dorm.GormClient // 日志数据库 gorm bool // 日志开关 + gormClient *dorm.GormClient // 日志数据库 logGormClient *golog.ApiClient // 日志服务 - mongoClient *dorm.MongoClient // 日志数据库 mongo bool // 日志开关 + mongoClient *dorm.MongoClient // 日志数据库 logMongoClient *golog.ApiClient // 日志服务 } } @@ -57,7 +57,7 @@ func NewClient(config *ClientConfig) (*Client, error) { c.requestClient = gorequest.NewHttp() gormClient := config.GormClientFun() - if gormClient.Db != nil { + if gormClient != nil && gormClient.Db != nil { c.log.logGormClient, err = golog.NewApiGormClient(func() (*dorm.GormClient, string) { return gormClient, logTable }, config.Debug) @@ -65,11 +65,11 @@ func NewClient(config *ClientConfig) (*Client, error) { return nil, err } c.log.gorm = true + c.log.gormClient = gormClient } - c.log.gormClient = gormClient mongoClient, databaseName := config.MongoClientFun() - if mongoClient.Db != nil { + if mongoClient != nil && mongoClient.Db != nil { c.log.logMongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) { return mongoClient, databaseName, logTable }, config.Debug) @@ -77,8 +77,8 @@ func NewClient(config *ClientConfig) (*Client, error) { return nil, err } c.log.mongo = true + c.log.mongoClient = mongoClient } - c.log.mongoClient = mongoClient xip := goip.GetOutsideIp(context.Background()) if xip != "" && xip != "0.0.0.0" { diff --git a/const.go b/const.go index cd78bcd..934e54d 100644 --- a/const.go +++ b/const.go @@ -12,4 +12,4 @@ const ( logTable = "wikeyun" ) -const Version = "1.0.17" +const Version = "1.0.18" diff --git a/request.go b/request.go index 9f79534..fd95d44 100644 --- a/request.go +++ b/request.go @@ -31,10 +31,10 @@ func (c *Client) request(ctx context.Context, url string, params map[string]inte } // 日志 - if c.log.gorm == true { + if c.log.gorm { go c.log.logGormClient.GormMiddleware(ctx, request, Version) } - if c.log.mongo == true { + if c.log.mongo { go c.log.logMongoClient.MongoMiddleware(ctx, request, Version) }