storage

package
v0.43.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const CtxKeyNamespaceOverride ctxKey = "storage_ns_override"

CtxKeyNamespaceOverride is the context key used to override namespace per request

View Source
const (
	StorageProtocolID = "/network/storage/1.0.0"
)

Storage protocol definitions for distributed storage

Variables

This section is empty.

Functions

func WithNamespace

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

WithNamespace returns a new context that carries a storage namespace override

Types

type Client

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

Client provides distributed storage client functionality

func NewClient

func NewClient(h host.Host, namespace string, logger *zap.Logger) *Client

NewClient creates a new storage client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key string) error

Delete removes a key from the distributed storage

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists in the distributed storage

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves a value by key from the distributed storage

func (*Client) List

func (c *Client) List(ctx context.Context, prefix string, limit int) ([]string, error)

List returns keys with a given prefix

func (*Client) Put

func (c *Client) Put(ctx context.Context, key string, value []byte) error

Put stores a key-value pair in the distributed storage

type MessageType

type MessageType string

Message types for storage operations

const (
	MessageTypePut    MessageType = "put"
	MessageTypeGet    MessageType = "get"
	MessageTypeDelete MessageType = "delete"
	MessageTypeList   MessageType = "list"
	MessageTypeExists MessageType = "exists"
)

type Service

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

Service provides distributed storage functionality using RQLite

func NewService

func NewService(db *sql.DB, logger *zap.Logger) (*Service, error)

NewService creates a new storage service backed by RQLite

func (*Service) Close

func (s *Service) Close() error

Close closes the storage service

func (*Service) HandleStorageStream

func (s *Service) HandleStorageStream(stream network.Stream)

HandleStorageStream handles incoming storage protocol streams

type StorageRequest

type StorageRequest struct {
	Type      MessageType `json:"type"`
	Key       string      `json:"key"`
	Value     []byte      `json:"value,omitempty"`
	Prefix    string      `json:"prefix,omitempty"`
	Limit     int         `json:"limit,omitempty"`
	Namespace string      `json:"namespace"`
}

StorageRequest represents a storage operation request

func (*StorageRequest) Marshal

func (r *StorageRequest) Marshal() ([]byte, error)

Marshal serializes a request to JSON

func (*StorageRequest) Unmarshal

func (r *StorageRequest) Unmarshal(data []byte) error

Unmarshal deserializes a request from JSON

type StorageResponse

type StorageResponse struct {
	Success bool     `json:"success"`
	Error   string   `json:"error,omitempty"`
	Value   []byte   `json:"value,omitempty"`
	Keys    []string `json:"keys,omitempty"`
	Exists  bool     `json:"exists,omitempty"`
}

StorageResponse represents a storage operation response

func (*StorageResponse) Marshal

func (r *StorageResponse) Marshal() ([]byte, error)

Marshal serializes a response to JSON

func (*StorageResponse) Unmarshal

func (r *StorageResponse) Unmarshal(data []byte) error

Unmarshal deserializes a response from JSON

Jump to

Keyboard shortcuts

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