Documentation ¶
Index ¶
- Constants
- Variables
- func SetMgoDbConnToCtx(ctx context.Context, clt MongoDBConn) context.Context
- func SetMgoDbConnToGin(c *gin.Context, clt MongoDBConn) *gin.Context
- func SetMgoDbConnToReq(req *http.Request, clt MongoDBConn) *http.Request
- type MongoConf
- func (mc *MongoConf) GetDb() string
- func (mc *MongoConf) GetUri() string
- func (mc *MongoConf) NewDbConn(ctx context.Context, db string) (MongoDBConn, error)
- func (mc *MongoConf) NewDbConnWithOpts(ctx context.Context, db string) (MongoDBConn, error)
- func (mc *MongoConf) NewDefaultDbConn(ctx context.Context) (MongoDBConn, error)
- func (mc *MongoConf) NewDefaultDbConnWithOpts(ctx context.Context) (MongoDBConn, error)
- func (mc *MongoConf) SetAuth(user, pwd string)
- type MongoDBConn
- type MongoDI
- type MongoOptsDI
Constants ¶
View Source
const (
CtxMongoKey = ctxKey(_CTX_KEY_MONGO)
)
Variables ¶
View Source
var (
MongoOpsQueued = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "mongo_connection",
Help: "Number of MongoDB connection.",
})
)
Functions ¶
func SetMgoDbConnToCtx ¶
func SetMgoDbConnToCtx(ctx context.Context, clt MongoDBConn) context.Context
func SetMgoDbConnToGin ¶
func SetMgoDbConnToGin(c *gin.Context, clt MongoDBConn) *gin.Context
func SetMgoDbConnToReq ¶
func SetMgoDbConnToReq(req *http.Request, clt MongoDBConn) *http.Request
Types ¶
type MongoConf ¶
type MongoConf struct { Uri string `yaml:"uri"` User string `yaml:"user"` Pass string `yaml:"pass"` DefaultDB string `yaml:"defaul"` // contains filtered or unexported fields }
func (*MongoConf) NewDbConnWithOpts ¶
func (*MongoConf) NewDefaultDbConn ¶
func (mc *MongoConf) NewDefaultDbConn(ctx context.Context) (MongoDBConn, error)
func (*MongoConf) NewDefaultDbConnWithOpts ¶
func (mc *MongoConf) NewDefaultDbConnWithOpts(ctx context.Context) (MongoDBConn, error)
type MongoDBConn ¶
type MongoDBConn interface { GetDbConn() *mongo.Database WithSession(f func(sc mongo.SessionContext) error) error AbortTransaction(sc mongo.SessionContext) error CommitTransaction(sc mongo.SessionContext) error Close() error Ping() error }
func GetMgoDbConnFromCtx ¶
func GetMgoDbConnFromCtx(ctx context.Context) MongoDBConn
func GetMgoDbConnFromGin ¶
func GetMgoDbConnFromGin(c *gin.Context) MongoDBConn
func GetMgoDbConnFromReq ¶
func GetMgoDbConnFromReq(req *http.Request) MongoDBConn
type MongoOptsDI ¶
Click to show internal directories.
Click to hide internal directories.