Documentation
¶
Overview ¶
Package wireclient provides low-level wire protocol client.
Index ¶
- func Credentials(uri string) (cleanURI string, credentials *url.Userinfo, authSource, authMechanism string, ...)
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Login(ctx context.Context, userinfo *url.Userinfo, authSource, authMechanism string) error
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Read(ctx context.Context) (*wire.MsgHeader, wire.MsgBody, error)
- func (c *Conn) Request(ctx context.Context, body wire.MsgBody) (*wire.MsgHeader, wire.MsgBody, error)
- func (c *Conn) Write(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) error
- func (c *Conn) WriteRaw(ctx context.Context, b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Credentials ¶ added in v0.1.7
func Credentials(uri string) (cleanURI string, credentials *url.Userinfo, authSource, authMechanism string, err error)
Credentials extracts user credentials, authSource, and authMechanism suitable for Conn.Login from the given MongoDB URI. It also returns a clean URI suitable for Connect.
If both authSource query parameter and URI path are present, the query parameter takes precedence. If both are empty, it does not defaults to "admin". The caller should handle this case if needed.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a single client connection.
It is not safe for concurrent use.
func Connect ¶
Connect creates a new connection for the given MongoDB URI. See Credentials.
Context can be used to cancel the connection attempt. Canceling the context after the connection is established has no effect.
The passed logger will be used only for debug-level messages.
func ConnectPing ¶ added in v0.0.6
ConnectPing uses a combination of Connect and Conn.Ping to establish a working connection.
nil is returned on context expiration.
func New ¶
New wraps the given connection.
The passed logger will be used only for debug-level messages.
func (*Conn) Login ¶ added in v0.0.6
func (c *Conn) Login(ctx context.Context, userinfo *url.Userinfo, authSource, authMechanism string) error
Login authenticates the connection with the given credentials using some unspecified sequences of commands.
It should not be used to test various authentication scenarios.
The authMechanism is used to enforce a specific authentication mechanism. If empty, the negotiation is performed instead using `hello` command. Note that in practice it often fails due to incorrect handling of the `loadBalanced` parameter.
func (*Conn) Ping ¶ added in v0.0.6
Ping sends a ping command. It returns error for unexpected server response or any other error.
func (*Conn) Read ¶
Read reads the next message from the connection.
Passed context's deadline is honored if set.
func (*Conn) Request ¶
func (c *Conn) Request(ctx context.Context, body wire.MsgBody) (*wire.MsgHeader, wire.MsgBody, error)
Request sends the given request to the connection and returns the response. The header is generated automatically.
Passed context's deadline is honored if set.
It returns errors only for request/response parsing or connection issues. All protocol-level errors are stored inside response.