models

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Connection settings
	URI      string // MongoDB connection URI (required)
	Database string // Default database name (required)

	// Connection pool settings
	MaxPoolSize uint64 // Maximum number of connections in the pool
	MinPoolSize uint64 // Minimum number of connections in the pool

	// Timeout settings
	ConnectTimeout         time.Duration // Timeout for establishing connection
	ServerSelectionTimeout time.Duration // Timeout for selecting server
	SocketTimeout          time.Duration // Timeout for socket operations
	Timeout                time.Duration // Default timeout for operations

	// Additional settings
	Debug             bool          // Enable debug logging
	RetryWrites       bool          // Enable automatic retry of write operations
	RetryReads        bool          // Enable automatic retry of read operations
	AppName           string        // Application name for MongoDB logs
	DirectConnection  bool          // Whether to connect directly to a single host
	ReplicaSet        string        // Replica set name (optional)
	ReadPreference    string        // Read preference mode (primary, secondary, etc.)
	MaxConnIdleTime   time.Duration // Maximum idle time for connection
	HeartbeatInterval time.Duration // Interval between server heartbeats
}

func DefaultConfig

func DefaultConfig() Config

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type Option

type Option func(*Config)

func WithAppName

func WithAppName(appName string) Option

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

func WithDatabase

func WithDatabase(database string) Option

func WithDebug

func WithDebug(debug bool) Option

func WithDirectConnection

func WithDirectConnection(direct bool) Option

func WithHeartbeatInterval

func WithHeartbeatInterval(interval time.Duration) Option

func WithMaxConnIdleTime

func WithMaxConnIdleTime(duration time.Duration) Option

func WithMaxPoolSize

func WithMaxPoolSize(size uint64) Option

func WithMinPoolSize

func WithMinPoolSize(size uint64) Option

func WithReadPreference

func WithReadPreference(preference string) Option

func WithReplicaSet

func WithReplicaSet(replicaSet string) Option

func WithRetryReads

func WithRetryReads(retry bool) Option

func WithRetryWrites

func WithRetryWrites(retry bool) Option

func WithServerSelectionTimeout

func WithServerSelectionTimeout(timeout time.Duration) Option

func WithSocketTimeout

func WithSocketTimeout(timeout time.Duration) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

func WithURI

func WithURI(uri string) Option

Jump to

Keyboard shortcuts

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