From 216598bc9d28c1050c7c3137cb712128b9a8cc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 1 Sep 2022 14:42:24 +0800 Subject: [PATCH] - update gorm - update mongo --- api.go | 8 ++++++++ api_gorm.go | 2 ++ api_mongo.go | 18 +++++++++++++++--- const.go | 2 +- gin.go | 8 ++++++++ gin_gorm.go | 2 ++ gin_mongo.go | 18 +++++++++++++++--- 7 files changed, 51 insertions(+), 7 deletions(-) diff --git a/api.go b/api.go index 1c2e3d8..79d19da 100644 --- a/api.go +++ b/api.go @@ -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 diff --git a/api_gorm.go b/api_gorm.go index 4936ca3..d6633b7 100644 --- a/api_gorm.go +++ b/api_gorm.go @@ -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 } diff --git a/api_mongo.go b/api_mongo.go index 6c807e8..742f3fc 100644 --- a/api_mongo.go +++ b/api_mongo.go @@ -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 } // 模型结构体 diff --git a/const.go b/const.go index 740c6c0..6c4ab49 100644 --- a/const.go +++ b/const.go @@ -1,5 +1,5 @@ package golog const ( - Version = "1.0.47" + Version = "1.0.48" ) diff --git a/gin.go b/gin.go index f34dae3..eb45f59 100644 --- a/gin.go +++ b/gin.go @@ -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 diff --git a/gin_gorm.go b/gin_gorm.go index 9242372..f15dc4f 100644 --- a/gin_gorm.go +++ b/gin_gorm.go @@ -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 } diff --git a/gin_mongo.go b/gin_mongo.go index 228d53a..1ac9c48 100644 --- a/gin_mongo.go +++ b/gin_mongo.go @@ -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 } // 模型结构体