client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package client provides a RemoteTransport that connects to an event server.

Index

Constants

This section is empty.

Variables

View Source
var ErrPermissionDenied = errors.New("event: permission denied")

ErrPermissionDenied is returned when the server denies access to an event.

Functions

This section is empty.

Types

type ConnState

type ConnState int

ConnState represents the connection state.

const (
	ConnStateDisconnected ConnState = iota
	ConnStateConnecting
	ConnStateConnected

	ConnStateClosed
)

func (ConnState) String

func (s ConnState) String() string

type Option

type Option func(*options)

Option configures the RemoteTransport.

func WithCallTimeout

func WithCallTimeout(d time.Duration) Option

WithCallTimeout sets a per-attempt timeout for each gRPC call within a retry loop.

func WithCircuitBreaker

func WithCircuitBreaker(threshold int, timeout time.Duration) Option

WithCircuitBreaker enables circuit breaker for resilience.

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) Option

WithDialOptions appends additional gRPC dial options.

func WithInsecure

func WithInsecure() Option

WithInsecure explicitly enables insecure connections (no TLS). This should only be used for development/testing.

func WithKeepalive

func WithKeepalive(time, timeout time.Duration) Option

WithKeepalive configures gRPC keepalive parameters.

func WithRetry

func WithRetry(maxRetries int, initialBackoff, maxBackoff time.Duration) Option

WithRetry configures retry behavior for failed operations.

func WithStateCallback

func WithStateCallback(fn func(ConnState)) Option

WithStateCallback sets a callback for connection state changes.

func WithStreamErrorCallback

func WithStreamErrorCallback(fn func(error)) Option

WithStreamErrorCallback sets a callback for subscribe stream errors.

func WithSubscribeBufferSize

func WithSubscribeBufferSize(size int) Option

WithSubscribeBufferSize sets the buffer size for subscribe message channels.

func WithSubscribeMaxErrors

func WithSubscribeMaxErrors(n int) Option

WithSubscribeMaxErrors sets the maximum number of consecutive subscribe errors before giving up. Default is 10.

func WithSubscribeReconnect

func WithSubscribeReconnect(enabled bool, waitTime time.Duration) Option

WithSubscribeReconnect enables automatic reconnection for subscribe streams.

func WithTLS

func WithTLS(config *tls.Config) Option

WithTLS enables TLS with the given config. If config is nil, uses system default TLS config.

type PermissionDeniedError

type PermissionDeniedError struct {
	Message string
}

PermissionDeniedError provides details about a permission denial.

func (*PermissionDeniedError) Error

func (e *PermissionDeniedError) Error() string

func (*PermissionDeniedError) Is

func (e *PermissionDeniedError) Is(target error) bool

type RemoteError

type RemoteError struct {
	Code    codes.Code
	Message string
}

RemoteError wraps an error from the remote event server.

func (*RemoteError) Error

func (e *RemoteError) Error() string

type RemoteTransport

type RemoteTransport struct {
	// contains filtered or unexported fields
}

RemoteTransport implements transport.Transport by connecting to an event server. It is safe for concurrent use by multiple goroutines.

func New

func New(addr string, opts ...Option) (*RemoteTransport, error)

New creates a new RemoteTransport connecting to the given address.

func (*RemoteTransport) Close

func (t *RemoteTransport) Close(ctx context.Context) error

Close shuts down the transport and releases resources.

func (*RemoteTransport) Connect

func (t *RemoteTransport) Connect(ctx context.Context) error

Connect establishes the connection to the event server.

func (*RemoteTransport) Publish

func (t *RemoteTransport) Publish(ctx context.Context, name string, msg transport.Message) error

Publish sends a message to an event.

func (*RemoteTransport) Ready

func (t *RemoteTransport) Ready() bool

Ready returns true if the transport is connected and ready.

func (*RemoteTransport) RegisterEvent

func (t *RemoteTransport) RegisterEvent(ctx context.Context, name string) error

RegisterEvent creates transport resources for a named event.

func (*RemoteTransport) State

func (t *RemoteTransport) State() ConnState

State returns the current connection state.

func (*RemoteTransport) Subscribe

Subscribe creates a subscription to receive messages for an event.

func (*RemoteTransport) UnregisterEvent

func (t *RemoteTransport) UnregisterEvent(ctx context.Context, name string) error

UnregisterEvent removes transport resources for a named event.

Jump to

Keyboard shortcuts

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