finclip-app-manager/infrastructure/db/repo/mongo/mongo.go

35 lines
599 B
Go
Raw Permalink Normal View History

2023-10-31 14:07:26 +08:00
package mongo
import (
"finclip-app-manager/infrastructure/config"
"fmt"
mgo "gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo"
)
//每次使用的时候copy一个用完之后close
var Dbsession *mgo.Session
//func init() {
// start()
//}
func Start() error {
url := config.GetConfig().MongoURL
var err error
Dbsession, err = mgo.Dial(url)
if err != nil {
panic(err)
}
if Dbsession == nil {
panic("mongo db session is nil!")
}
Dbsession.SetMode(mgo.Strong, true)
fmt.Println("mongo start success ...")
return nil
}
func Copy() *mgo.Session {
return Dbsession.Copy()
}