net

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExist = errors.New("exist")
View Source
var ErrNotExist = errors.New("not exist")

Functions

func WithConnDatabase

func WithConnDatabase(name string) func(*conn)

WithConnDatabase sets a database name.

func WithConnID

func WithConnID(v ConnID) func(*conn)

WithConnID sets a connection ID.

func WithConnTracer

func WithConnTracer(t tracer.Context) func(*conn)

WithConnTracer sets a tracer context.

Types

type Conn

type Conn interface {
	net.Conn
	tracer.Context
	// Context returns the context.
	Context() context.Context
	// SetDatabase sets a database name.
	SetDatabase(db string)
	// Database returns the database name.
	Database() string
	// Timestamp returns the timestamp.
	Timestamp() time.Time
	// UUID returns the UUID.
	UUID() uuid.UUID
	// ID returns the ID.
	ID() ConnID
	// SetSpanContext sets a span context.
	SetSpanContext(ctx tracer.Context)
	// SpanContext returns a span context.
	SpanContext() tracer.Context
}

Conn represents a connection.

func NewConnWith

func NewConnWith(netConn net.Conn, opts ...ConnOption) Conn

NewConnWith returns a connection with a raw connection.

type ConnID

type ConnID = uint64

ConnID represents a connection ID.

type ConnManager

type ConnManager interface {
	// AddConn adds the specified connection.
	AddConn(c Conn) error
	// UpdateConn updates the specified connection.
	UpdateConn(from Conn, to Conn) error
	// Conns returns the included connections.
	Conns() []Conn
	// LookupConnByUID returns a connection and true when the specified connection exists by the connection ID, otherwise nil and false.
	LookupConnByUID(cid uint64) (Conn, bool)
	// LookupConnByUUID returns the connection with the specified UUID.
	LookupConnByUUID(uuid uuid.UUID) (Conn, bool)
	// RemoveConn deletes the specified connection from the map.
	RemoveConn(conn Conn) error
	// RemoveConnByUID deletes the specified connection by the connection ID.
	RemoveConnByUID(cid uint64)
	// RemoveConnByUID deletes the specified connection by the connection ID.
	RemoveConnByUUID(uuid uuid.UUID)
	// Start starts the connection manager.
	Start() error
	// Close closes the connection manager.
	Close() error
	// Stop closes all connections.
	Stop() error
}

ConnManager represents a connection manager interface.

func NewConnManager

func NewConnManager() ConnManager

NewConnManager returns a connection map.

type ConnOption

type ConnOption = func(*conn)

ConnOption represents a connection option.

Jump to

Keyboard shortcuts

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