backends

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextMessage   = 1
	BinaryMessage = 2
	CloseMessage  = 8
	PingMessage   = 9
	PongMessage   = 10
)

MessageType constants for realtime connections (WebSocket compatible)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientBackend

type ClientBackend interface {
	// Send a raw JSON message (used for health checks and other simple operations)
	SendRawMessage(jsonString string, insecure bool) (string, error)

	// Send an RPC message with authentication
	SendMessage(method string, jsonString string, prvKey string, insecure bool, ctx context.Context) (string, error)

	// Check the health of the backend connection
	CheckHealth() error

	// Close the backend and clean up blueprints
	Close() error
}

ClientBackend defines the interface for different client transport implementations

type ClientBackendFactory

type ClientBackendFactory interface {
	CreateBackend(config *ClientConfig) (ClientBackend, error)
	GetBackendType() ClientBackendType
}

ClientBackendFactory creates backend-specific clients

type ClientBackendType

type ClientBackendType string

BackendType represents different client backend types

const (
	GinClientBackendType    ClientBackendType = "gin"
	LibP2PClientBackendType ClientBackendType = "libp2p"
	GRPCClientBackendType   ClientBackendType = "grpc"
	CoAPClientBackendType   ClientBackendType = "coap"
)

func ParseClientBackendsFromEnv

func ParseClientBackendsFromEnv(backendsEnv string) []ClientBackendType

ParseClientBackendsFromEnv parses comma-separated backend types from environment variable e.g., "libp2p,http" or "http" or "libp2p"

type ClientBackendWithRealtime

type ClientBackendWithRealtime interface {
	ClientBackend
	RealtimeBackend
}

ClientBackendWithRealtime extends ClientBackend with realtime capabilities

type ClientConfig

type ClientConfig struct {
	BackendType    ClientBackendType
	Host           string
	Port           int
	Insecure       bool
	SkipTLSVerify  bool
	BootstrapPeers string // Comma-separated multiaddresses for LibP2P bootstrap peers
}

ClientConfig holds configuration for client backends

func CreateCoAPClientConfig

func CreateCoAPClientConfig(host string, port int, insecure bool, skipTLSVerify bool) *ClientConfig

CreateCoAPClientConfig creates a client config for CoAP backend

func CreateDefaultClientConfig

func CreateDefaultClientConfig(host string, port int, insecure bool, skipTLSVerify bool) *ClientConfig

CreateDefaultClientConfig creates a default client config for HTTP/Gin backend

func CreateGRPCClientConfig

func CreateGRPCClientConfig(host string, port int, insecure bool, skipTLSVerify bool) *ClientConfig

CreateGRPCClientConfig creates a client config for gRPC backend

func CreateLibP2PClientConfig

func CreateLibP2PClientConfig(host string) *ClientConfig

CreateLibP2PClientConfig creates a client config for LibP2P backend host parameter should be a libp2p multiaddr (e.g., "/ip4/127.0.0.1/tcp/5000/p2p/12D3KooW...")

type MultiBackendClient

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

MultiBackendClient implements ClientBackend by trying multiple backends in order

func NewMultiBackendClient

func NewMultiBackendClient(configs []*ClientConfig, factories map[ClientBackendType]ClientBackendFactory) (*MultiBackendClient, error)

NewMultiBackendClient creates a client that tries multiple backends with fallback

func (*MultiBackendClient) CheckHealth

func (m *MultiBackendClient) CheckHealth() error

CheckHealth checks health of all backends and returns error if all are unhealthy

func (*MultiBackendClient) Close

func (m *MultiBackendClient) Close() error

Close closes all backends

func (*MultiBackendClient) SendMessage

func (m *MultiBackendClient) SendMessage(method string, jsonString string, prvKey string, insecure bool, ctx context.Context) (string, error)

SendMessage tries each backend in order until one succeeds

func (*MultiBackendClient) SendRawMessage

func (m *MultiBackendClient) SendRawMessage(jsonString string, insecure bool) (string, error)

SendRawMessage tries each backend in order until one succeeds

type RealtimeBackend

type RealtimeBackend interface {
	// EstablishRealtimeConn establishes a realtime connection for real-time operations
	EstablishRealtimeConn(jsonString string) (RealtimeConnection, error)
}

RealtimeBackend defines the interface for establishing realtime connections

type RealtimeConnection

type RealtimeConnection interface {
	// WriteMessage writes a message to the realtime connection
	WriteMessage(messageType int, data []byte) error

	// ReadMessage reads a message from the realtime connection
	ReadMessage() (messageType int, data []byte, err error)

	// Close closes the realtime connection
	Close() error

	// SetReadLimit sets the maximum size for incoming messages
	SetReadLimit(limit int64)
}

RealtimeConnection represents a generic realtime connection interface Different backends can implement this using WebSockets, libp2p pubsub, etc.

Jump to

Keyboard shortcuts

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