base

package module
v0.0.0-...-f9dd4c8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 4 Imported by: 15

README

base-go

Go Reference GoReportCard codecov

base-go contains the definitions for both the client and server.

The client delegates all communication tasks, such as sending Commands, receiving Results, and closing the connection, to the ClientDelegate.

The server utilizes a configurable number of workers to manage client connections using ServerDelegate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncResult

type AsyncResult struct {
	Seq    Seq
	Result Result
	Error  error
}

AsyncResult represents an asynchronous result.

Seq is the sequence number of the Command, Error != nil if something went wrong with the connection.

type ClientDelegate

type ClientDelegate[T any] interface {
	LocalAddr() net.Addr
	RemoteAddr() net.Addr

	SetSendDeadline(deadline time.Time) error
	Send(seq Seq, cmd Cmd[T]) error
	Flush() error

	SetReceiveDeadline(deadline time.Time) error
	Receive() (seq Seq, result Result, err error)

	Close() error
}

ClientDelegate helps the client to send Commands and receive Results.

type ClientKeepaliveDelegate

type ClientKeepaliveDelegate[T any] interface {
	ClientDelegate[T]
	Keepalive(muSn *sync.Mutex)
}

ClientKeepaliveDelegate defines the Keepalive method.

This delegate can be used if you want the client to keepalive connection to the server.

type ClientReconnectDelegate

type ClientReconnectDelegate[T any] interface {
	ClientDelegate[T]
	Reconnect() error
}

ClientReconnectDelegate defines the Reconnect method.

This delegate can be used if you want the client to reconnect to the server in case of a connection loss.

type Cmd

type Cmd[T any] interface {
	Exec(ctx context.Context, at time.Time, seq Seq, receiver T, proxy Proxy) error
}

Cmd defines the general Command interface.

The Exec method is invoked by the server's Invoker. It executes the Command with the following parameters:

  • ctx: Execution context.
  • at: Timestamp when the server received the Command.
  • seq: Sequence number assigned to the Command.
  • receiver: The Receiver of type T.
  • proxy: A server transport proxy used to send Results back to the client.

type Listener

type Listener interface {
	Addr() net.Addr
	SetDeadline(time.Time) error
	Accept() (net.Conn, error)
	Close() error
}

Listener is a server network listener.

On Close, it should not close already accepted connections.

type Proxy

type Proxy interface {
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Send(seq Seq, result Result) error
	SendWithDeadline(deadline time.Time, seq Seq, result Result) error
}

Proxy represents a server transport proxy, enabling Commands to send Results back.

Implementation of this interface must be thread-safe.

type Result

type Result interface {
	LastOne() bool
}

Result represents the outcome of the Сommand execution.

LastOne method indicates the final Result of the Command.

type Seq

type Seq int64

Seq represents the sequence number of a Command.

The sequence number ensures that each Command can be uniquely identified and mapped to its corresponding Results.

type ServerDelegate

type ServerDelegate interface {
	Handle(ctx context.Context, conn net.Conn) error
}

ServerDelegate helps the server handle incoming connections.

Handle method should return context.Canceled error if the context is done.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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