otmongo

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package otmongo provides mongo client with opentracing. For documentation about redis usage, see https://pkg.go.dev/go.mongodb.org/mongo-driver

Integration

package otmongo exports the configuration in the following format:

mongo:
  default:
    uri:

Add the mongo dependency to core:

var c *core.C = core.New()
c.Provide(otmongo.Providers())

Then you can invoke redis from the application.

c.Invoke(func(client *mongo.Client) {
	client.Connect(context.Background())
})

Sometimes there are valid reasons to connect to more than one mongo server. Inject otmongo.Maker to factory a *mongo.Client with a specific configuration entry.

c.Invoke(function(maker otmongo.Maker) {
	client, err := maker.Make("default")
	// do something with client
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMonitor

func NewMonitor(tracer opentracing.Tracer) *event.CommandMonitor

NewMonitor creates a new mongodb event CommandMonitor.

func Providers added in v0.2.0

func Providers() di.Deps

Providers returns a set of dependency providers. It includes the Maker, the default mongo.Client and exported configs.

Depends On:
	log.Logger
	contract.ConfigAccessor
	MongoConfigInterceptor `optional:"true"`
	opentracing.Tracer     `optional:"true"`
Provides:
	Factory
	Maker
	*mongo.Client

Types

type Factory

type Factory struct {
	*di.Factory
}

Factory is a *di.Factory that creates *mongo.Client using a specific configuration entry.

func (Factory) Make

func (r Factory) Make(name string) (*mongo.Client, error)

Make creates *mongo.Client using a specific configuration entry.

type Maker

type Maker interface {
	Make(name string) (*mongo.Client, error)
}

Maker models Factory

type MongoConfigInterceptor added in v0.2.0

type MongoConfigInterceptor func(name string, clientOptions *options.ClientOptions)

MongoConfigInterceptor is an injection type hint that allows user to make last minute modification to mongo configuration. This is useful when some configuration cannot be easily expressed in a text form. For example, the options.ContextDialer.

Jump to

Keyboard shortcuts

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