Documentation ¶
Overview ¶
Package conn is not for public use.
The API for packages in the 'private' directory have no stability guarantee.
The packages within the 'private' directory would normally be put into an 'internal' directory to prohibit their use outside the 'mongo' directory. However, some MongoDB tools require very low-level access to the building blocks of a driver, so we have placed them under 'private' to allow these packages to be imported by projects that need them.
These package APIs may be modified in backwards-incompatible ways at any time.
You are strongly discouraged from directly using any packages under 'private'.
Index ¶
- Variables
- func ExecuteCommand(ctx context.Context, c Connection, request msg.Request) (bson.Reader, error)
- func ExecuteCommands(ctx context.Context, c Connection, requests []msg.Request) ([]bson.Reader, error)
- func IsCommandNotFound(err error) bool
- func IsNsNotFound(err error) bool
- type CommandError
- type CommandFailureError
- type CommandResponseError
- type Connection
- type Dialer
- type Error
- type Opener
- type Option
- func WithAppName(name string) Option
- func WithCodec(codec msg.Codec) Option
- func WithConnectTimeout(timeout time.Duration) Option
- func WithDialer(dialer Dialer) Option
- func WithIdleTimeout(timeout time.Duration) Option
- func WithLifeTimeout(timeout time.Duration) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithTLSConfig(tlsDefault *TLSConfig) Option
- func WithWrappedDialer(wrapper func(dialer Dialer) Dialer) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type Pool
- type Provider
- type TLSConfig
- type TrackedConnection
- func (tc *TrackedConnection) Alive() bool
- func (tc *TrackedConnection) Close() error
- func (tc *TrackedConnection) Expired() bool
- func (tc *TrackedConnection) Inc()
- func (tc *TrackedConnection) Model() *model.Conn
- func (tc *TrackedConnection) Read(ctx context.Context, responseTo int32) (msg.Response, error)
- func (tc *TrackedConnection) Write(ctx context.Context, reqs ...msg.Request) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownCommandFailure occurs when a command fails for an unknown reason. ErrUnknownCommandFailure = errors.New("unknown command failure") // ErrNoCommandResponse occurs when the server sent no response document to a command. ErrNoCommandResponse = errors.New("no command response document") // ErrMultiDocCommandResponse occurs when the server sent multiple documents in response to a command. ErrMultiDocCommandResponse = errors.New("command returned multiple documents") // ErrNoDocCommandResponse occurs when the server indicated a response existed, but none was found. ErrNoDocCommandResponse = errors.New("command returned no documents") )
var ErrPoolClosed = errors.New("pool is closed")
ErrPoolClosed is an error that occurs when attempting to use a pool that is closed.
Functions ¶
func ExecuteCommand ¶
ExecuteCommand executes the message on the channel.
func ExecuteCommands ¶
func ExecuteCommands(ctx context.Context, c Connection, requests []msg.Request) ([]bson.Reader, error)
ExecuteCommands executes the messages on the connection.
func IsCommandNotFound ¶
IsCommandNotFound indicates if the error is about a command not being found.
func IsNsNotFound ¶
IsNsNotFound indicates if the error is about a namespace not being found.
Types ¶
type CommandError ¶
CommandError is an error in the execution of a command.
func (*CommandError) Error ¶
func (e *CommandError) Error() string
type CommandFailureError ¶
CommandFailureError is an error with a failure response as a document.
func (*CommandFailureError) Error ¶
func (e *CommandFailureError) Error() string
func (*CommandFailureError) Message ¶
func (e *CommandFailureError) Message() string
Message retrieves the message of the error.
type CommandResponseError ¶
type CommandResponseError struct {
Message string
}
CommandResponseError is an error in the response to a command.
func NewCommandResponseError ¶
func NewCommandResponseError(msg string) *CommandResponseError
NewCommandResponseError creates a new CommandResponseError.
func (*CommandResponseError) Error ¶
func (e *CommandResponseError) Error() string
type Connection ¶
type Connection interface { // Alive indicates if the connection is still alive. Alive() bool // Close closes the connection. Close() error // CloseIgnoreError closes the connection and ignores any error that occurs. CloseIgnoreError() // MarkDead forces a connection to close. MarkDead() // Model gets a description of the connection. Model() *model.Conn // Expired indicates if the connection has expired. Expired() bool // LocalAddr returns the local address of the connection. LocalAddr() net.Addr // Read reads a message from the connection. Read(context.Context, int32) (msg.Response, error) // Write writes a number of messages to the connection. Write(context.Context, ...msg.Request) error }
Connection is responsible for reading and writing messages.
type Dialer ¶
type Dialer func(ctx context.Context, dialer *net.Dialer, network, address string) (net.Conn, error)
Dialer dials a server according to the network and address.
type Error ¶
type Error struct { ConnectionID string // contains filtered or unexported fields }
Error represents an error that in the connection package.
type Option ¶
type Option func(*config) error
Option configures a connection.
func WithAppName ¶
WithAppName sets the application name which gets sent to MongoDB on first connection.
func WithConnectTimeout ¶
WithConnectTimeout configures the maximum amount of time a dial will wait for a connect to complete. The default is 30 seconds.
func WithDialer ¶
WithDialer defines the dialer for endpoints.
func WithIdleTimeout ¶
WithIdleTimeout configures the maximum idle time to allow for a connection.
func WithLifeTimeout ¶
WithLifeTimeout configures the maximum life of a connection.
func WithReadTimeout ¶
WithReadTimeout configures the maximum read time for a connection.
func WithTLSConfig ¶
WithTLSConfig configures the SSL options for a connection.
func WithWrappedDialer ¶
WithWrappedDialer wraps the current dialer.
func WithWriteTimeout ¶
WithWriteTimeout configures the maximum read time for a connection.
type Pool ¶
type Pool interface { // Clear drains the pool. Clear() // Close closes the pool, making it unusable. Close() error // Get gets a connection from the pool. To return the connection // to the pool, close it. Get(context.Context) (Connection, error) }
Pool holds connections such that they can be checked out and reused.
type Provider ¶
type Provider func(context.Context) (Connection, error)
Provider gets a connection.
func CappedProvider ¶
CappedProvider returns a Provider that is constrained by a resource limit.
type TLSConfig ¶
type TLSConfig struct {
// contains filtered or unexported fields
}
TLSConfig contains options for configuring an SSL connection to the server.
func (*TLSConfig) AddCaCertFromFile ¶
AddCaCertFromFile adds a root CA certificate to the configuration given a path to the containing file.
func (*TLSConfig) AddClientCertFromFile ¶ added in v0.0.2
AddClientCertFromFile adds a client certificate to the configuration given a path to the containing file and returns the certificate's subject name.
func (*TLSConfig) MakeConfig ¶ added in v0.0.2
MakeConfig constructs a new tls.Config from the configuration specified.
func (*TLSConfig) SetInsecure ¶
SetInsecure sets whether the client should verify the server's certificate chain and hostnames.
type TrackedConnection ¶
type TrackedConnection struct {
// contains filtered or unexported fields
}
TrackedConnection is a connection that only closes once it's usage count is 0.
func (*TrackedConnection) Alive ¶
func (tc *TrackedConnection) Alive() bool
Alive indicates if the connection is still alive.
func (*TrackedConnection) Close ¶
func (tc *TrackedConnection) Close() error
Close closes the connection.
func (*TrackedConnection) Expired ¶
func (tc *TrackedConnection) Expired() bool
Expired indicates if the connection has expired.
func (*TrackedConnection) Model ¶
func (tc *TrackedConnection) Model() *model.Conn
Model gets a description of the connection.