conn

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

func ExecuteCommand(ctx context.Context, c Connection, request msg.Request) (bson.Reader, error)

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

func IsCommandNotFound(err error) bool

IsCommandNotFound indicates if the error is about a command not being found.

func IsNsNotFound

func IsNsNotFound(err error) bool

IsNsNotFound indicates if the error is about a namespace not being found.

Types

type CommandError

type CommandError struct {
	Code    int32
	Message string
	Name    string
}

CommandError is an error in the execution of a command.

func (*CommandError) Error

func (e *CommandError) Error() string

type CommandFailureError

type CommandFailureError struct {
	Msg      string
	Response bson.Reader
}

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.

func New

func New(ctx context.Context, addr model.Addr, opts ...Option) (Connection, error)

New opens a connection to a server.

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.

func (*Error) Error

func (e *Error) Error() string

Error gets a rolled-up error message.

func (*Error) Inner

func (e *Error) Inner() error

Inner gets the inner error if one exists.

func (*Error) Message

func (e *Error) Message() string

Message gets the basic error message.

type Opener

type Opener func(context.Context, model.Addr, ...Option) (Connection, error)

Opener opens a connection.

type Option

type Option func(*config) error

Option configures a connection.

func WithAppName

func WithAppName(name string) Option

WithAppName sets the application name which gets sent to MongoDB on first connection.

func WithCodec

func WithCodec(codec msg.Codec) Option

WithCodec sets the codec to use to encode and decode messages.

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout configures the maximum amount of time a dial will wait for a connect to complete. The default is 30 seconds.

func WithDialer

func WithDialer(dialer Dialer) Option

WithDialer defines the dialer for endpoints.

func WithIdleTimeout

func WithIdleTimeout(timeout time.Duration) Option

WithIdleTimeout configures the maximum idle time to allow for a connection.

func WithLifeTimeout

func WithLifeTimeout(timeout time.Duration) Option

WithLifeTimeout configures the maximum life of a connection.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout configures the maximum read time for a connection.

func WithTLSConfig

func WithTLSConfig(tlsConfig *TLSConfig) Option

WithTLSConfig configures the SSL options for a connection.

func WithWrappedDialer

func WithWrappedDialer(wrapper func(dialer Dialer) Dialer) Option

WithWrappedDialer wraps the current dialer.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) Option

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.

func NewPool

func NewPool(maxSize uint64, provider Provider) Pool

NewPool creates a new connection pool.

type Provider

type Provider func(context.Context) (Connection, error)

Provider gets a connection.

func CappedProvider

func CappedProvider(max uint64, provider Provider) Provider

CappedProvider returns a Provider that is constrained by a resource limit.

func OpeningProvider

func OpeningProvider(opener Opener, addr model.Addr, opts ...Option) Provider

OpeningProvider returns a Factory that uses a dialer.

type TLSConfig

type TLSConfig struct{ tls.Config }

TLSConfig contains options for configuring an SSL connection to the server.

func NewTLSConfig

func NewTLSConfig() *TLSConfig

NewTLSConfig creates a new TLSConfig.

func (*TLSConfig) AddCaCertFromFile

func (c *TLSConfig) AddCaCertFromFile(caFile string) error

AddCaCertFromFile adds a root CA certificate to the configuration given a path to the containing file.

func (*TLSConfig) SetInsecure

func (c *TLSConfig) SetInsecure(allow bool)

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 Tracked

func Tracked(c Connection) *TrackedConnection

Tracked creates a tracked connection.

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) Inc

func (tc *TrackedConnection) Inc()

Inc increments the usage count.

func (*TrackedConnection) Model

func (tc *TrackedConnection) Model() *model.Conn

Model gets a description of the connection.

func (*TrackedConnection) Read

func (tc *TrackedConnection) Read(ctx context.Context, responseTo int32) (msg.Response, error)

Read reads a message from the connection.

func (*TrackedConnection) Write

func (tc *TrackedConnection) Write(ctx context.Context, reqs ...msg.Request) error

Write writes a number of messages to the connection.

Jump to

Keyboard shortcuts

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