优化架构

This commit is contained in:
huangxiaolei
2022-11-23 18:05:11 +08:00
parent 3efed3defe
commit 43403202b5
6760 changed files with 33748 additions and 554768 deletions

34
dispatch/dao/dao.go Normal file
View File

@@ -0,0 +1,34 @@
package dao
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"hk4e/common/config"
"hk4e/logger"
)
type Dao struct {
client *mongo.Client
db *mongo.Database
}
func NewDao() (r *Dao) {
r = new(Dao)
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url)
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
logger.LOG.Error("mongo connect error: %v", err)
return nil
}
r.client = client
r.db = client.Database("gate_hk4e")
return r
}
func (d *Dao) CloseDao() {
err := d.client.Disconnect(context.TODO())
if err != nil {
logger.LOG.Error("mongo close error: %v", err)
}
}