conn

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 12 Imported by: 4

Documentation

Index

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) GetDb

func (mc *MongoConf) GetDb() string

func (*MongoConf) GetUri

func (mc *MongoConf) GetUri() string

func (*MongoConf) NewDbConn

func (mc *MongoConf) NewDbConn(ctx context.Context, db string) (MongoDBConn, error)

func (*MongoConf) NewDbConnWithOpts

func (mc *MongoConf) NewDbConnWithOpts(ctx context.Context, db string) (MongoDBConn, error)

func (*MongoConf) NewDefaultDbConn

func (mc *MongoConf) NewDefaultDbConn(ctx context.Context) (MongoDBConn, error)

func (*MongoConf) NewDefaultDbConnWithOpts

func (mc *MongoConf) NewDefaultDbConnWithOpts(ctx context.Context) (MongoDBConn, error)

func (*MongoConf) SetAuth

func (mc *MongoConf) SetAuth(user, pwd string)

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 MongoDI

type MongoDI interface {
	NewDefaultDbConn(ctx context.Context) (MongoDBConn, error)
	NewDbConn(ctx context.Context, db string) (MongoDBConn, error)
	SetAuth(user, pwd string)
	GetUri() string
	GetDb() string
}

type MongoOptsDI

type MongoOptsDI interface {
	NewDefaultDbConnWithOpts(ctx context.Context) (MongoDBConn, error)
	NewDbConnWithOpts(ctx context.Context, db string) (MongoDBConn, error)
	SetAuth(user, pwd string)
	GetUri() string
	GetDb() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL