- update log

master v1.0.9
李光春 2 years ago
parent b92d1f0b3b
commit e477b71b71

@ -6,6 +6,28 @@ import (
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
) )
// client *dorm.GormClient
type gormClientFun func() *dorm.GormClient
// client *dorm.MongoClient
// databaseName string
type mongoClientFun func() (*dorm.MongoClient, string)
// ClientConfig 实例配置
type ClientConfig struct {
SpAppid string // 服务商应用ID
SpMchId string // 服务商户号
ApiV2 string // APIv2密钥
ApiV3 string // APIv3密钥
SerialNo string // 序列号
MchSslSerialNo string // pem 证书号
MchSslCer string // pem 内容
MchSslKey string // pem key 内容
GormClientFun gormClientFun // 日志配置
MongoClientFun mongoClientFun // 日志配置
Debug bool // 日志开关
}
// Client 实例 // Client 实例
type Client struct { type Client struct {
requestClient *gorequest.App // 请求服务 requestClient *gorequest.App // 请求服务
@ -31,43 +53,28 @@ type Client struct {
} }
} }
// client *dorm.GormClient
type gormClientFun func() *dorm.GormClient
// client *dorm.MongoClient
// databaseName string
type mongoClientFun func() (*dorm.MongoClient, string)
// NewClient 创建实例化 // NewClient 创建实例化
// spAppid 服务商应用ID func NewClient(config *ClientConfig) (*Client, error) {
// spMchId 服务商户号
// apiV2 APIv2密钥
// apiV3 APIv3密钥
// serialNo 序列号
// mchSslSerialNo pem 证书号
// mchSslCer pem 内容
// mchSslKey pem key 内容
func NewClient(spAppid, spMchId, apiV2, apiV3, serialNo, mchSslSerialNo, mchSslCer, mchSslKey string, gormClientFun gormClientFun, mongoClientFun mongoClientFun, debug bool) (*Client, error) {
var err error var err error
c := &Client{} c := &Client{}
c.config.spAppid = spAppid c.config.spAppid = config.SpAppid
c.config.spMchId = spMchId c.config.spMchId = config.SpMchId
c.config.apiV2 = apiV2 c.config.apiV2 = config.ApiV2
c.config.apiV3 = apiV3 c.config.apiV3 = config.ApiV3
c.config.serialNo = serialNo c.config.serialNo = config.SerialNo
c.config.mchSslSerialNo = mchSslSerialNo c.config.mchSslSerialNo = config.MchSslSerialNo
c.config.mchSslCer = mchSslCer c.config.mchSslCer = config.MchSslCer
c.config.mchSslKey = mchSslKey c.config.mchSslKey = config.MchSslKey
c.requestClient = gorequest.NewHttp() c.requestClient = gorequest.NewHttp()
gormClient := gormClientFun() gormClient := config.GormClientFun()
if gormClient.Db != nil { if gormClient.Db != nil {
c.log.logGormClient, err = golog.NewApiGormClient(func() (*dorm.GormClient, string) { c.log.logGormClient, err = golog.NewApiGormClient(func() (*dorm.GormClient, string) {
return gormClient, logTable return gormClient, logTable
}, debug) }, config.Debug)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -75,11 +82,11 @@ func NewClient(spAppid, spMchId, apiV2, apiV3, serialNo, mchSslSerialNo, mchSslC
} }
c.log.gormClient = gormClient c.log.gormClient = gormClient
mongoClient, databaseName := mongoClientFun() mongoClient, databaseName := config.MongoClientFun()
if mongoClient.Db != nil { if mongoClient.Db != nil {
c.log.logMongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) { c.log.logMongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) {
return mongoClient, databaseName, logTable return mongoClient, databaseName, logTable
}, debug) }, config.Debug)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -14,7 +14,7 @@ const (
// SDK 相关信息 // SDK 相关信息
const ( const (
Version = "1.0.8" // SDK 版本 Version = "1.0.9" // SDK 版本
UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息 UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息
) )

Loading…
Cancel
Save