Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadPreferenceFromString ¶
func ReadPreferenceFromString(src ConnectionReadPreference) *readpref.ReadPref
func StringifyBSON ¶
func StringifyBSON(val interface{}) string
StringifyBSON converts arbitrary BSON to json-like string. it returns empty string on any error.
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
// mongodb://user:password@host:port/dbname?options
// https://www.mongodb.com/docs/manual/reference/connection-string/
URI string `mapstructure:"uri"`
// Query log config
QueryLog *QueryLoggingConfig `mapstructure:"query_log"`
}
func (*ConnectionConfig) Validate ¶
func (c *ConnectionConfig) Validate() error
type ConnectionReadPreference ¶
type ConnectionReadPreference string
const ( ReadPreferencePrimary ConnectionReadPreference = "primary" ReadPreferencePrimaryPreferred ConnectionReadPreference = "primary preferred" ReadPreferenceSecondaryPreferred ConnectionReadPreference = "secondary preferred" ReadPreferenceSecondary ConnectionReadPreference = "secondary" ReadPreferenceNearest ConnectionReadPreference = "nearest" )
type ConnectionsConfig ¶
type ConnectionsConfig map[string]*ConnectionConfig
func (*ConnectionsConfig) Validate ¶
func (c *ConnectionsConfig) Validate() error
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a simple container for holding named mongo connections. It's a helper for sharing same connection between several components.
func Init ¶ added in v1.11.0
func Init(wg *sync.WaitGroup, appName string, cfg ConnectionsConfig) *Container
Init creates a container and connects every connection from the config in background. appName is reported to the mongo server as the client application name. The caller must wait on the wait group before using the returned container. Connection failures are fatal.
func NewContainer ¶
func NewContainer() *Container
type QueryLoggingConfig ¶
type QueryLoggingConfig struct {
// Whether to log all queries
All bool `mapstructure:"all"`
// Whether to log slow queries
Slow bool `mapstructure:"slow"`
// Queries that were executed longer than that time will appear in slow log
SlowThreshold time.Duration `mapstructure:"slow_threshold"`
}
func (*QueryLoggingConfig) Validate ¶
func (c *QueryLoggingConfig) Validate() error
Click to show internal directories.
Click to hide internal directories.