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() }