api

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addressable

type Addressable interface {
	// LocalAddr returns the net.Addr of the server
	LocalAddr() net.Addr
	// RemoteAddr returns the net.Addr of the client that sent the current request.
	RemoteAddr() net.Addr
	RemoteAddrString() string // safe getter for remote address
}

type CachedTCPWriter

type CachedTCPWriter interface {
	// WriteString send the string to the writing queue
	WriteString(message string)
	// Write send the buffer to the writing queue
	Write(message []byte)
}

type CachedUDPWriter

type CachedUDPWriter interface {
	WriteTo(remoteAddr *net.UDPAddr, data []byte)
}

type Codec

type Codec interface {
	OnDecode(data []byte, ch chan<- []byte) (processed bool, err error)
	OnEncode(body []byte) (data []byte, err error)
}

type Conn

type Conn interface {
	Response
	RawWriteable
}

type ConnAware

type ConnAware interface {
	OnConnected(ctx context.Context, conn Conn)
	OnClosing(c Conn, reason int)
	OnClosed(c Conn, reason int)
}

type ErrorAware

type ErrorAware interface {
	OnError(ctx context.Context, conn Conn, err error)
}

type Interceptor

type Interceptor interface {
	// OnReading handles reading event for tcp mode.
	OnReading(ctx context.Context, conn Conn, data []byte, ch chan<- []byte) (processed bool, err error)
	// OnWriting handles writing event for tcp mode.
	//
	// You may override the internal writing action with processed = true and
	// write data yourself. For instance:
	//     processed = true
	//     c.RawWrite(data)
	// By default, after OnWriting do nothing, internal loop will write data
	// to tcp connection rawly.
	OnWriting(ctx context.Context, conn Conn, data []byte) (processed bool, err error)
}

type InterceptorHolder

type InterceptorHolder interface {
	ProtocolInterceptor() Interceptor
}

type RawWriteable

type RawWriteable interface {
	// RawWrite does write through the internal net.Conn
	RawWrite(ctx context.Context, message []byte) (n int, err error)

	// RawWriteTimeout does write message immediately.
	RawWriteTimeout(msg []byte, deadline ...time.Duration) (n int, err error)
}

RawWriteable provides instance writing feature without cache.

type Request

type Request interface {
	Read(p []byte) (n int, err error)

	Addressable
}

type Response

type Response interface {
	basics.Closable

	Addressable
	Writeable
}

type ServerInterceptor

type ServerInterceptor interface {
	OnListened(baseCtx context.Context, addr string)
	OnServerReady(ctx context.Context) // ctx.Value["conn"] -> api.Conn
	OnServerClosed()                   // ctx.Value["logger"] -> log/slog or logg/slog

	Interceptor
}

type ServerInterceptorHolder

type ServerInterceptorHolder interface {
	ProtocolInterceptor() ServerInterceptor
}

type UdpInterceptor

type UdpInterceptor interface {
	// OnUdpReading is special hook if in udp mode
	OnUdpReading(ctx context.Context, packet *UdpPacket) (processed bool, err error)
	// OnUdpWriting is special hook if in udp mode
	OnUdpWriting(ctx context.Context, packet *UdpPacket) (processed bool, err error)
}

type UdpPacket

type UdpPacket struct {
	RemoteAddr *net.UDPAddr
	Data       []byte
}

func NewUdpPacket

func NewUdpPacket(remoteAddr *net.UDPAddr, data []byte) *UdpPacket

type Writeable

type Writeable interface {
	// Write writes a raw buffer back to the client.
	Write(data []byte) (n int, err error)
}

Writeable provides cacheable writing feature

Jump to

Keyboard shortcuts

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