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

35 lines
599 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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