client

package
v0.0.0-...-643373b Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a high-performance, connection-pooled interface to Haystack servers. It handles connection management, timeouts, and error recovery automatically.

func New

func New(config *Config) (*Client, error)

New creates a new Haystack client with the given configuration.

func (*Client) Close

func (c *Client) Close() error

Close closes the client and all its connections.

func (*Client) Get

func (c *Client) Get(ctx context.Context, hash needle.Hash) (*needle.Needle, error)

Get retrieves a needle from the Haystack server by its hash.

func (*Client) GetBytes

func (c *Client) GetBytes(ctx context.Context, hashBytes []byte) ([]byte, error)

GetBytes retrieves needle bytes from the Haystack server by hash.

func (*Client) Set

func (c *Client) Set(ctx context.Context, n *needle.Needle) error

Set stores a needle on the Haystack server. This is a fire-and-forget operation - no response is expected.

func (*Client) SetBytes

func (c *Client) SetBytes(ctx context.Context, data []byte) error

SetBytes stores raw needle bytes on the Haystack server. The bytes must be exactly 192 bytes (a valid needle).

func (*Client) Stats

func (c *Client) Stats() PoolStats

Stats returns connection pool statistics.

type Config

type Config struct {
	// Address of the Haystack server (e.g., "localhost:1337")
	Address string

	// Maximum number of connections in the pool (default: 10)
	MaxConnections int

	// Read timeout for GET operations (default: 5s)
	ReadTimeout time.Duration

	// Write timeout for SET operations (default: 5s)
	WriteTimeout time.Duration

	// How long to keep idle connections (default: 30s)
	IdleTimeout time.Duration

	// Logger for error and debug messages (optional, uses NoOp if nil)
	Logger logger.Logger
}

Config holds configuration options for the Haystack client.

func DefaultConfig

func DefaultConfig(address string) *Config

DefaultConfig returns a configuration with sensible defaults.

type PoolStats

type PoolStats struct {
	Active int // Active connections
	Idle   int // Idle connections
	Total  int // Total connections created
}

PoolStats provides statistics about the connection pool.

Jump to

Keyboard shortcuts

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