- update gorm

- update mongo
master v1.0.48
李光春 2 years ago
parent e6c2c7668b
commit 216598bc9d

@ -94,6 +94,7 @@ func NewApiClient(config *ApiClientConfig) (*ApiClient, error) {
c.gormConfig.goVersion = runtime.Version()
c.log.gorm = true
}
if mongoClient != nil || mongoClient.Db != nil {
@ -117,6 +118,13 @@ func NewApiClient(config *ApiClientConfig) (*ApiClient, error) {
c.mongoConfig.goVersion = runtime.Version()
c.log.mongo = true
// 创建时间序列集合
c.mongoCreateCollection()
// 创建索引
c.mongoCreateIndexes()
}
return c, nil

@ -58,6 +58,8 @@ func NewApiGormClient(config *ApiGormClientConfig) (*ApiClient, error) {
c.gormConfig.insideIp = goip.GetInsideIp(ctx)
c.gormConfig.goVersion = runtime.Version()
c.log.gorm = true
return c, nil
}

@ -59,7 +59,19 @@ func NewApiMongoClient(config *ApiMongoClientConfig) (*ApiClient, error) {
c.mongoConfig.insideIp = goip.GetInsideIp(ctx)
c.mongoConfig.goVersion = runtime.Version()
c.log.mongo = true
// 创建时间序列集合
c.mongoCreateCollection()
// 创建索引
c.mongoCreateIndexes()
return c, nil
}
// 创建时间序列集合
func (c *ApiClient) mongoCreateCollection() {
var commandResult bson.M
commandErr := c.mongoClient.Db.Database(c.mongoConfig.databaseName).RunCommand(context.TODO(), bson.D{{
"listCollections", 1,
@ -72,8 +84,10 @@ func NewApiMongoClient(config *ApiMongoClientConfig) (*ApiClient, error) {
log.Println("创建时间序列集合:", err)
}
}
}
// 创建索引
// 创建索引
func (c *ApiClient) mongoCreateIndexes() {
log.Println(c.mongoClient.Db.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).Indexes().CreateOne(context.TODO(), mongo.IndexModel{Keys: bson.D{
{"trace_id", 1},
}}))
@ -101,8 +115,6 @@ func NewApiMongoClient(config *ApiMongoClientConfig) (*ApiClient, error) {
log.Println(c.mongoClient.Db.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).Indexes().CreateOne(context.TODO(), mongo.IndexModel{Keys: bson.D{
{"sdk_version", -1},
}}))
return c, nil
}
// 模型结构体

@ -1,5 +1,5 @@
package golog
const (
Version = "1.0.47"
Version = "1.0.48"
)

@ -103,6 +103,7 @@ func NewGinClient(config *GinClientConfig) (*GinClient, error) {
c.gormConfig.goVersion = runtime.Version()
c.log.gorm = true
}
if mongoClient != nil || mongoClient.Db != nil {
@ -128,6 +129,13 @@ func NewGinClient(config *GinClientConfig) (*GinClient, error) {
c.mongoConfig.goVersion = runtime.Version()
c.log.mongo = true
// 创建时间序列集合
c.mongoCreateCollection()
// 创建索引
c.mongoCreateIndexes()
}
return c, nil

@ -68,6 +68,8 @@ func NewGinGormClient(config *GinGormClientConfig) (*GinClient, error) {
c.gormConfig.insideIp = goip.GetInsideIp(ctx)
c.gormConfig.goVersion = runtime.Version()
c.log.gorm = true
return c, nil
}

@ -71,7 +71,19 @@ func NewGinMongoClient(config *GinMongoClientConfig) (*GinClient, error) {
c.mongoConfig.insideIp = goip.GetInsideIp(ctx)
c.mongoConfig.goVersion = runtime.Version()
c.log.mongo = true
// 创建时间序列集合
c.mongoCreateCollection()
// 创建索引
c.mongoCreateIndexes()
return c, nil
}
// 创建时间序列集合
func (c *GinClient) mongoCreateCollection() {
var commandResult bson.M
commandErr := c.mongoClient.Db.Database(c.mongoConfig.databaseName).RunCommand(context.TODO(), bson.D{{
"listCollections", 1,
@ -84,8 +96,10 @@ func NewGinMongoClient(config *GinMongoClientConfig) (*GinClient, error) {
log.Println("创建时间序列集合:", err)
}
}
}
// 创建索引
// 创建索引
func (c *GinClient) mongoCreateIndexes() {
log.Println(c.mongoClient.Db.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).Indexes().CreateOne(context.TODO(), mongo.IndexModel{
Keys: bson.D{
{"trace_id", 1},
@ -150,8 +164,6 @@ func NewGinMongoClient(config *GinMongoClientConfig) (*GinClient, error) {
Keys: bson.D{
{"sdk_version", -1},
}}))
return c, nil
}
// 模型结构体

Loading…
Cancel
Save