Documentation ¶
Overview ¶
Package mongo extends the functionality of mongo by adding tracing, logging, and implementing Shutdown and HealthCheck hooks.
Index ¶
- Constants
- func GetDefaultConfig(moduleName string, t Tracer, logger log.Log) *options.ClientOptions
- func NewCustomBsonRegistry() *bsoncodec.Registry
- type BaseMongoDocument
- type BaseMongoModel
- type Collection
- type Database
- type Mongo
- func (m *Mongo) Database(name string, opts ...*options.DatabaseOptions) *Database
- func (m *Mongo) GetClient() *mongo.Client
- func (m *Mongo) GetLogger() log.Log
- func (m *Mongo) HealthCheck(ctx context.Context) error
- func (m *Mongo) Name(ctx context.Context) string
- func (m *Mongo) SetModuleName(name string)
- func (m *Mongo) Shutdown(ctx context.Context) error
- type MongoLogger
- type Tracer
Constants ¶
const ModuleName = "MongoClient"
Variables ¶
This section is empty.
Functions ¶
func GetDefaultConfig ¶
GetDefaultConfig returns the default MongoDB client options including connection settings, application name, pool size, compression, read preference, write concern, logging, and monitoring.
func NewCustomBsonRegistry ¶
NewCustomBsonRegistry returns the custom BSON registry configured to handle decimal.Decimal types.
Types ¶
type BaseMongoDocument ¶
type BaseMongoDocument struct { CreatedAt *time.Time `json:"createdAt,omitempty" bson:"createdAt,omitempty"` // Time when the document was created. UpdatedAt *time.Time `json:"updatedAt,omitempty" bson:"updatedAt,omitempty"` // Time when the document was last updated. CreatedBy *string `json:"createdBy,omitempty" bson:"createdBy,omitempty"` // Identifier of the user who created the document. UpdatedBy *string `json:"updatedBy,omitempty" bson:"updatedBy,omitempty"` // Identifier of the user who last updated the document. }
BaseMongoDocument defines a basic structure for a MongoDB document.
func (*BaseMongoDocument) SetCreateParam ¶
func (b *BaseMongoDocument) SetCreateParam(actionBy string)
SetCreateParam sets the creation parameters for the document.
func (*BaseMongoDocument) SetUpdateParam ¶
func (b *BaseMongoDocument) SetUpdateParam(actionBy string)
SetUpdateParam sets the update parameters for the document.
type BaseMongoModel ¶
type BaseMongoModel struct { ID *primitive.ObjectID `json:"-" bson:"_id,omitempty"` // Unique identifier of the MongoDB document. *BaseMongoDocument `bson:",inline"` // Embedded BaseMongoDocument. }
BaseMongoModel extends BaseMongoDocument with an ObjectId.
func (*BaseMongoModel) SetCreateParam ¶
func (b *BaseMongoModel) SetCreateParam(actionBy string)
SetCreateParam sets the creation parameters for the model.
func (*BaseMongoModel) SetUpdateParam ¶
func (b *BaseMongoModel) SetUpdateParam(actionBy string)
SetUpdateParam sets the update parameters for the model.
type Collection ¶
type Collection struct { *mongo.Collection // contains filtered or unexported fields }
Collection extends mongo.Collection by adding support for encoding and decoding decimal types.
type Database ¶
Database extends mongo.Database by incorporating enhanced logging functionality.
func (*Database) Collection ¶
func (d *Database) Collection(name string, opts ...*options.CollectionOptions) *Collection
Collection returns a Collection with a custom BSON registry and enhanced logging. It prepends the custom registry option to any other collection options provided.
type Mongo ¶
Mongo enhances mongo.Client with default option settings and logging capabilities.
func New ¶
New creates a new Mongo client with the provided client options and initializes the connection.
func NewWithDefaultOptions ¶
func NewWithDefaultOptions(logger log.Log, t Tracer, opts ...*options.ClientOptions) (*Mongo, error)
NewWithDefaultOptions creates a new Mongo client with the default configuration options, incorporating additional options provided by the caller.
func (*Mongo) Database ¶
func (m *Mongo) Database(name string, opts ...*options.DatabaseOptions) *Database
Database returns a wrapped mongo.Database with enhanced logging.
func (*Mongo) HealthCheck ¶
HealthCheck performs a health check by pinging the MongoDB server.
func (*Mongo) SetModuleName ¶
SetModuleName sets the module name and updates the logger.
type MongoLogger ¶
type MongoLogger struct {
// contains filtered or unexported fields
}
MongoLogger is used for logging MongoDB events.
func (*MongoLogger) Error ¶
func (m *MongoLogger) Error(err error, message string, keysAndValues ...interface{})
Error logs error messages.
func (*MongoLogger) Info ¶
func (m *MongoLogger) Info(level int, message string, keysAndValues ...interface{})
Info logs informational messages.
func (*MongoLogger) PoolEvent ¶
func (m *MongoLogger) PoolEvent(e *event.PoolEvent)
PoolEvent logs MongoDB pool events.
type Tracer ¶
type Tracer interface {
MongoDB() *event.CommandMonitor
}
Tracer interface defines a method for obtaining a MongoDB command monitor.
Directories ¶
Path | Synopsis |
---|---|
Package csfle implements boilerplate code for creating a MongoDB client with Client-Side Field Level Encryption (CSFLE) capabilities.
|
Package csfle implements boilerplate code for creating a MongoDB client with Client-Side Field Level Encryption (CSFLE) capabilities. |