wireclient

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package wireclient provides low-level wire protocol client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

func Connect(ctx context.Context, uri string, l *slog.Logger) (*Conn, error)

Connect creates a new connection for the given MongoDB URI.

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

func ConnectPing(ctx context.Context, uri string, l *slog.Logger) *Conn

ConnectPing uses a combination of Connect and Conn.Ping to establish a working connection.

nil is returned on context expiration.

func New

func New(c net.Conn, l *slog.Logger) *Conn

New wraps the given connection.

The passed logger will be used only for debug-level messages.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Login added in v0.0.6

func (c *Conn) Login(ctx context.Context, username, password, authDB 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.

func (*Conn) Ping added in v0.0.6

func (c *Conn) Ping(ctx context.Context) error

Ping sends a ping command. It returns error for unexpected server response or any other error.

func (*Conn) Read

func (c *Conn) Read(ctx context.Context) (*wire.MsgHeader, wire.MsgBody, error)

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.

func (*Conn) Write

func (c *Conn) Write(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) error

Write writes the given message to the connection.

Passed context's deadline is honored if set.

func (*Conn) WriteRaw

func (c *Conn) WriteRaw(ctx context.Context, b []byte) error

WriteRaw writes the given raw bytes to the connection.

Passed context's deadline is honored if set.

Jump to

Keyboard shortcuts

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