otmongo

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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:

redis:
  default:
    uri:

Add the mongo dependency to core:

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

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 otredis.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.

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 MongoIn

type MongoIn struct {
	dig.In

	Logger log.Logger
	Conf   contract.ConfigAccessor
	Tracer opentracing.Tracer `optional:"true"`
}

MongoIn is the injection parameter for Provide.

type MongoOut

type MongoOut struct {
	dig.Out

	Factory        Factory
	Maker          Maker
	Client         *mongo.Client
	ExportedConfig []config.ExportedConfig `group:"config,flatten"`
}

MongoOut is the result of Provide. The official mongo package doesn't provide a proper interface type. It is up to the users to define their own mongodb repository interface.

func Provide

func Provide(p MongoIn) (MongoOut, func())

Provide creates Factory and *mongo.Client. It is a valid dependency for package core.

Jump to

Keyboard shortcuts

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