|
|
@ -1,6 +1,7 @@ |
|
|
|
package db |
|
|
|
|
|
|
|
import ( |
|
|
|
"LAPP_ETL/global" |
|
|
|
"LAPP_ETL/infra/config" |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
@ -14,7 +15,9 @@ var AppMongo *mongo.Client |
|
|
|
func InitMongo() error { |
|
|
|
//1.建立链接
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) |
|
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%d", config.AppConfig.Mongo.Host, config.AppConfig.Mongo.Port))) |
|
|
|
dsn := fmt.Sprintf("mongodb://%s:%d", config.AppConfig.Mongo.Host, config.AppConfig.Mongo.Port) |
|
|
|
global.MongoDsn = dsn |
|
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(dsn)) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|