clientinfra

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package clientinfra provides shared Mongo client setup helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureIndexes

func EnsureIndexes(timeout time.Duration, ensure func(context.Context) error) error

EnsureIndexes runs index initialization with a timeout-bounded background context.

func Ping

func Ping(ctx context.Context, client *mongodriver.Client, normalizeNil bool) error

Ping performs the common primary-read-preference health check.

func ResolveCollectionName added in v1.1.3

func ResolveCollectionName(collection string, defaultCollection string) string

ResolveCollectionName applies the package default when the configured collection is empty.

func ResolveTimeout

func ResolveTimeout(timeout time.Duration, defaultTimeout time.Duration) time.Duration

ResolveTimeout applies the package default when the configured timeout is not positive.

func ValidateCollections added in v1.1.3

func ValidateCollections(message string, collections ...any) error

ValidateCollections checks that test or production collection adapters are present.

func ValidateMongoOptions

func ValidateMongoOptions(client *mongodriver.Client, database string) error

ValidateMongoOptions checks the shared required Mongo constructor inputs.

func WithTimeout

func WithTimeout(ctx context.Context, timeout time.Duration, normalizeNil bool) (context.Context, context.CancelFunc)

WithTimeout wraps the caller context with the configured timeout.

Types

type Collection added in v1.1.3

type Collection struct {
	Coll *mongodriver.Collection
}

Collection adapts mongodriver.Collection to feature-local collection interfaces.

func NewCollection added in v1.1.3

func NewCollection(client *mongodriver.Client, database string, collection string) Collection

NewCollection returns the common adapter for a concrete Mongo collection.

func (Collection) Find added in v1.1.3

func (c Collection) Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (CursorReader, error)

Find forwards to the wrapped Collection.

func (Collection) FindOne added in v1.1.3

FindOne forwards to the wrapped Collection.

func (Collection) Indexes added in v1.1.3

func (c Collection) Indexes() IndexCreator

Indexes forwards to the wrapped Collection.

func (Collection) InsertOne added in v1.1.3

InsertOne forwards to the wrapped Collection.

func (Collection) UpdateOne added in v1.1.3

func (c Collection) UpdateOne(ctx context.Context, filter any, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongodriver.UpdateResult, error)

UpdateOne forwards to the wrapped Collection.

type Cursor added in v1.1.0

type Cursor struct {
	Cur *mongodriver.Cursor
}

Cursor adapts mongodriver.Cursor to a feature-local interface.

func (Cursor) Close added in v1.1.0

func (c Cursor) Close(ctx context.Context) error

Close forwards to the wrapped Cursor.

func (Cursor) Decode added in v1.1.0

func (c Cursor) Decode(val any) error

Decode forwards to the wrapped Cursor.

func (Cursor) Err added in v1.1.0

func (c Cursor) Err() error

Err forwards to the wrapped Cursor.

func (Cursor) Next added in v1.1.0

func (c Cursor) Next(ctx context.Context) bool

Next forwards to the wrapped Cursor.

type CursorReader added in v1.1.3

type CursorReader interface {
	Next(ctx context.Context) bool
	Decode(val any) error
	Err() error
	Close(ctx context.Context) error
}

CursorReader is the common cursor shape used by feature clients.

type FindCollection added in v1.1.3

type FindCollection interface {
	Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (CursorReader, error)
}

FindCollection captures the common Mongo Find operation.

type FindOneCollection added in v1.1.3

type FindOneCollection interface {
	FindOne(ctx context.Context, filter any, opts ...options.Lister[options.FindOneOptions]) SingleResultDecoder
}

FindOneCollection captures the common Mongo FindOne operation.

type IndexCreator added in v1.1.3

type IndexCreator interface {
	CreateOne(ctx context.Context, model mongodriver.IndexModel, opts ...options.Lister[options.CreateIndexesOptions]) (string, error)
}

IndexCreator is the common index creation shape used by feature clients.

type IndexView added in v1.1.0

type IndexView struct {
	View mongodriver.IndexView
}

IndexView adapts mongodriver.IndexView to a feature-local interface.

func (IndexView) CreateOne added in v1.1.0

CreateOne forwards to the wrapped IndexView.

type IndexedCollection added in v1.1.3

type IndexedCollection interface {
	Indexes() IndexCreator
}

IndexedCollection captures access to Mongo index management.

type InsertOneCollection added in v1.1.3

type InsertOneCollection interface {
	InsertOne(ctx context.Context, document any, opts ...options.Lister[options.InsertOneOptions]) (*mongodriver.InsertOneResult, error)
}

InsertOneCollection captures the common Mongo InsertOne operation.

type SingleResult added in v1.1.0

type SingleResult struct {
	Res *mongodriver.SingleResult
}

SingleResult adapts mongodriver.SingleResult to a feature-local interface.

func (SingleResult) Decode added in v1.1.0

func (r SingleResult) Decode(val any) error

Decode forwards to the wrapped SingleResult.

type SingleResultDecoder added in v1.1.3

type SingleResultDecoder interface {
	Decode(val any) error
}

SingleResultDecoder is the common decode-only shape of Mongo single-result reads.

type UpdateOneCollection added in v1.1.3

type UpdateOneCollection interface {
	UpdateOne(ctx context.Context, filter any, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongodriver.UpdateResult, error)
}

UpdateOneCollection captures the common Mongo UpdateOne operation.

Jump to

Keyboard shortcuts

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