client

package
v0.52.16 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBootstrapPeers

func DefaultBootstrapPeers() []string

DefaultBootstrapPeers returns the library's default bootstrap peer multiaddrs. These can be overridden by environment variables or config.

func DefaultDatabaseEndpoints

func DefaultDatabaseEndpoints() []string

DefaultDatabaseEndpoints returns default DB HTTP endpoints. These can be overridden by environment variables or config.

func IsInternalContext

func IsInternalContext(ctx context.Context) bool

IsInternalContext checks if a context is marked for internal operations

func MapAddrsToDBEndpoints

func MapAddrsToDBEndpoints(addrs []multiaddr.Multiaddr, dbPort int) []string

MapAddrsToDBEndpoints converts a set of peer multiaddrs to DB HTTP endpoints using dbPort.

func WithInternalAuth

func WithInternalAuth(ctx context.Context) context.Context

WithInternalAuth creates a context that bypasses authentication for internal system operations. This should only be used by the system itself (migrations, internal tasks, etc.)

func WithNamespace

func WithNamespace(ctx context.Context, ns string) context.Context

WithNamespace applies pubsub namespace override to the context. It is a convenience helper for client callers to ensure subsystems receive the same, consistent namespace override.

Types

type Client

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

Client implements the NetworkClient interface

func (*Client) Config

func (c *Client) Config() *ClientConfig

Config returns a snapshot copy of the client's configuration

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes connection to the network

func (*Client) Database

func (c *Client) Database() DatabaseClient

Database returns the database client

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect closes the connection to the network

func (*Client) Health

func (c *Client) Health() (*HealthStatus, error)

Health returns the current health status

func (*Client) Network

func (c *Client) Network() NetworkInfo

Network returns the network info client

func (*Client) PubSub

func (c *Client) PubSub() PubSubClient

PubSub returns the pub/sub client

type ClientConfig

type ClientConfig struct {
	AppName           string        `json:"app_name"`
	DatabaseName      string        `json:"database_name"`
	BootstrapPeers    []string      `json:"bootstrap_peers"`
	DatabaseEndpoints []string      `json:"database_endpoints"`
	ConnectTimeout    time.Duration `json:"connect_timeout"`
	RetryAttempts     int           `json:"retry_attempts"`
	RetryDelay        time.Duration `json:"retry_delay"`
	QuietMode         bool          `json:"quiet_mode"` // Suppress debug/info logs
	APIKey            string        `json:"api_key"`    // API key for gateway auth
	JWT               string        `json:"jwt"`        // Optional JWT bearer token
}

ClientConfig represents configuration for network clients

func DefaultClientConfig

func DefaultClientConfig(appName string) *ClientConfig

DefaultClientConfig returns a default client configuration

type ColumnInfo

type ColumnInfo struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Nullable bool   `json:"nullable"`
	Default  string `json:"default"`
}

ColumnInfo contains information about a table column

type DatabaseClient

type DatabaseClient interface {
	Query(ctx context.Context, sql string, args ...interface{}) (*QueryResult, error)
	Transaction(ctx context.Context, queries []string) error
	CreateTable(ctx context.Context, schema string) error
	DropTable(ctx context.Context, tableName string) error
	GetSchema(ctx context.Context) (*SchemaInfo, error)
}

DatabaseClient provides database operations for applications

type DatabaseClientImpl

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

DatabaseClientImpl implements DatabaseClient

func (*DatabaseClientImpl) CreateTable

func (d *DatabaseClientImpl) CreateTable(ctx context.Context, schema string) error

CreateTable creates a new table

func (*DatabaseClientImpl) DropTable

func (d *DatabaseClientImpl) DropTable(ctx context.Context, tableName string) error

DropTable drops a table

func (*DatabaseClientImpl) GetSchema

func (d *DatabaseClientImpl) GetSchema(ctx context.Context) (*SchemaInfo, error)

GetSchema returns schema information

func (*DatabaseClientImpl) Query

func (d *DatabaseClientImpl) Query(ctx context.Context, sql string, args ...interface{}) (*QueryResult, error)

Query executes a SQL query

func (*DatabaseClientImpl) Transaction

func (d *DatabaseClientImpl) Transaction(ctx context.Context, queries []string) error

Transaction executes multiple queries in a transaction

type HealthStatus

type HealthStatus struct {
	Status       string            `json:"status"` // "healthy", "degraded", "unhealthy"
	Checks       map[string]string `json:"checks"`
	LastUpdated  time.Time         `json:"last_updated"`
	ResponseTime time.Duration     `json:"response_time"`
}

HealthStatus contains health check information

type MessageHandler

type MessageHandler func(topic string, data []byte) error

MessageHandler is called when a pub/sub message is received

type NetworkClient

type NetworkClient interface {
	// Database operations (namespaced per app)
	Database() DatabaseClient

	// Pub/Sub messaging
	PubSub() PubSubClient

	// Network information
	Network() NetworkInfo

	// Lifecycle
	Connect() error
	Disconnect() error
	Health() (*HealthStatus, error)

	// Config access (snapshot copy)
	Config() *ClientConfig
}

NetworkClient provides the main interface for applications to interact with the network

func NewClient

func NewClient(config *ClientConfig) (NetworkClient, error)

NewClient creates a new network client

type NetworkInfo

type NetworkInfo interface {
	GetPeers(ctx context.Context) ([]PeerInfo, error)
	GetStatus(ctx context.Context) (*NetworkStatus, error)
	ConnectToPeer(ctx context.Context, peerAddr string) error
	DisconnectFromPeer(ctx context.Context, peerID string) error
}

NetworkInfo provides network status and peer information

type NetworkInfoImpl

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

NetworkInfoImpl implements NetworkInfo

func (*NetworkInfoImpl) ConnectToPeer

func (n *NetworkInfoImpl) ConnectToPeer(ctx context.Context, peerAddr string) error

ConnectToPeer connects to a specific peer

func (*NetworkInfoImpl) DisconnectFromPeer

func (n *NetworkInfoImpl) DisconnectFromPeer(ctx context.Context, peerID string) error

DisconnectFromPeer disconnects from a specific peer

func (*NetworkInfoImpl) GetPeers

func (n *NetworkInfoImpl) GetPeers(ctx context.Context) ([]PeerInfo, error)

GetPeers returns information about connected peers

func (*NetworkInfoImpl) GetStatus

func (n *NetworkInfoImpl) GetStatus(ctx context.Context) (*NetworkStatus, error)

GetStatus returns network status

type NetworkStatus

type NetworkStatus struct {
	NodeID       string        `json:"node_id"`
	Connected    bool          `json:"connected"`
	PeerCount    int           `json:"peer_count"`
	DatabaseSize int64         `json:"database_size"`
	Uptime       time.Duration `json:"uptime"`
}

NetworkStatus contains overall network status

type PeerInfo

type PeerInfo struct {
	ID        string    `json:"id"`
	Addresses []string  `json:"addresses"`
	Connected bool      `json:"connected"`
	LastSeen  time.Time `json:"last_seen"`
}

PeerInfo contains information about a network peer

type PubSubClient

type PubSubClient interface {
	Subscribe(ctx context.Context, topic string, handler MessageHandler) error
	Publish(ctx context.Context, topic string, data []byte) error
	Unsubscribe(ctx context.Context, topic string) error
	ListTopics(ctx context.Context) ([]string, error)
}

PubSubClient provides publish/subscribe messaging

type QueryResult

type QueryResult struct {
	Columns []string        `json:"columns"`
	Rows    [][]interface{} `json:"rows"`
	Count   int64           `json:"count"`
}

QueryResult represents the result of a database query

type SchemaInfo

type SchemaInfo struct {
	Tables []TableInfo `json:"tables"`
}

SchemaInfo contains database schema information

type TableInfo

type TableInfo struct {
	Name    string       `json:"name"`
	Columns []ColumnInfo `json:"columns"`
}

TableInfo contains information about a database table

Jump to

Keyboard shortcuts

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