mongo

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedReadInputFile = errors.New("could not read the input file")
)

Functions

func ErrWriteFileToDatabase

func ErrWriteFileToDatabase(fileName string) error

func Get added in v0.4.1

func Get(ctx context.Context) (db.Provider, error)

func GetEnity added in v0.4.1

func GetEnity(ctx context.Context, enityName string) (interface{}, error)

func Registrate added in v0.4.1

func Registrate(ctx context.Context) (context.Context, error)

func RegistrateEnity added in v0.4.1

func RegistrateEnity(ctx context.Context, enityName string, options interface{}) (context.Context, error)

Types

type Config

type Config struct {
	// DSN is a connection string in form of DSN. Example:
	// mongodb://user:password@host:port/dbname.
	// Default: "mongodb://db:db@localhost:27017/db"
	DSN string `envconfig:"optional"`
	// Options is a string with additional options that will be passed
	// to connection. Default: "maxPoolSize=30&minPoolSize=10&maxIdleTimeMS=5000&ssl=false".
	Options string `envconfig:"optional"`
	// StartWatcher indicates to connection controller that it should
	// also start asynchronous connection watcher.
	StartWatcher bool `envconfig:"optional"`
	// Timeout is a timeout in seconds for connection checking. Every
	// this count of seconds database connection will be checked for
	// aliveness and, if it dies, attempt to reestablish connection
	// will be made. Default timeout is 10 seconds.
	Timeout time.Duration `envconfig:"optional"`
}

Config represents configuration structure for every connection.

func (*Config) ComposeDSN

func (c *Config) ComposeDSN() string

ComposeDSN compose DSN

func (*Config) GetDBName

func (c *Config) GetDBName() string

GetDBName return database name from DSN

func (*Config) SetDefault

func (c *Config) SetDefault() *Config

SetDefault checks connection config. If required field is empty - it will be filled with some default value. Returns a copy of config.

type Enity

type Enity struct {
	// Metrics
	stats.Service

	// Connection to database
	Conn *mongo.Client
	// contains filtered or unexported fields
}

Enity is a connection controlling structure. It controls connection, asynchronous queue and everything that related to specified connection.

func GetEnityTypeCast added in v0.4.1

func GetEnityTypeCast(ctx context.Context, enityName string) (*Enity, error)

func NewEnity

func NewEnity(ctx context.Context, name string, cfg interface{}) (*Enity, error)

NewEnity create new enity.

func (*Enity) DeleteFile added in v0.5.0

func (c *Enity) DeleteFile(fileID string) error

func (*Enity) GetFile

func (c *Enity) GetFile(fileID string) (*bytes.Buffer, int64, error)

func (*Enity) GetFileByName added in v0.5.0

func (c *Enity) GetFileByName(fileName, fileprefix string) (*bytes.Buffer, int64, error)

func (*Enity) GetMetrics

func (c *Enity) GetMetrics(prefix string) stats.MapMetricsOptions

GetMetrics return map of the metrics from database connection

func (*Enity) GetReadyHandlers

func (c *Enity) GetReadyHandlers(prefix string) stats.MapCheckFunc

GetReadyHandlers return array of the readyHandlers from database connection

func (*Enity) RenameFile added in v0.5.0

func (c *Enity) RenameFile(fileID, newFilename string) error

func (*Enity) Shutdown

func (c *Enity) Shutdown() error

Shutdown shutdowns queue worker and connection watcher. Later will also close connection to database. This is a blocking call.

func (*Enity) Start

func (c *Enity) Start() error

Start starts connection workers and connection procedure itself.

func (*Enity) UpdateFile added in v0.5.0

func (c *Enity) UpdateFile(fileID, fileprefix string, multipartForm *multipart.Form) error

func (*Enity) WaitForEstablishing

func (c *Enity) WaitForEstablishing()

WaitForEstablishing will block execution until connection will be successfully established and database migrations will be applied (or rolled back).

func (*Enity) WriteMultipart

func (c *Enity) WriteMultipart(fileprefix string, multipartForm *multipart.Form) (ObjectIDFileName, error)

type ObjectIDFileName added in v0.5.0

type ObjectIDFileName map[string]string

ObjectIDFileName is a map between objectID and file name

type Provider

type Provider struct {
	*providerwithmetrics.Provider
}

Provider for database mongo

func NewProvider

func NewProvider(ctx context.Context) *Provider

NewProvider creates new provider.

func (*Provider) CreateEnity

func (p *Provider) CreateEnity(enityName string, options interface{}) error

CreateEnity should create enity using passed parameters.

func (*Provider) GetEnity

func (p *Provider) GetEnity(connectionName string) (interface{}, error)

GetEnity should return pointer to connection structure to caller.

Jump to

Keyboard shortcuts

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