kv

package module
v0.0.0-...-581d9f9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package kv provides a key-value store with optional authentication and HTTP server functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a builder for KV.

func New

func New() *Builder

New returns a new KV builder.

func WithRandomBearerToken

func WithRandomBearerToken() *Builder

WithRandomBearerToken sets a random bearer token for the KV.

func (*Builder) Build

func (b *Builder) Build() *KV

Build returns a new KV instance with the configured options.

func (*Builder) WithAddress

func (b *Builder) WithAddress(address string) *Builder

WithAddress sets the address for the KV.

func (*Builder) WithAuth

func (b *Builder) WithAuth(token string) *Builder

WithAuth sets the authentication flag and token for the KV.

func (*Builder) WithLimit

func (b *Builder) WithLimit(limit int) *Builder

WithLimit sets the max number of records that can be stored in the KV.

type KV

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

KV represents a key-value store with optional authentication and network address configuration.

func (*KV) AuthMiddleware

func (k *KV) AuthMiddleware(_ *mux.Router) mux.MiddlewareFunc

AuthMiddleware returns a middleware function that enforces authentication for HTTP requests.

func (*KV) Clear

func (k *KV) Clear() error

Clear removes all keys and values from the KV store.

func (*KV) Data

func (k *KV) Data() *hashmap.Map

Data returns a snapshot of the current data in the KV store.

func (*KV) Get

func (k *KV) Get(key string) (interface{}, error)

Get retrieves a value associated with a key from the KV store.

func (*KV) Has

func (k *KV) Has(key string) bool

Has checks if a key exists in the KV store.

func (*KV) Keys

func (k *KV) Keys() []interface{}

Keys returns a slice of all keys currently stored in the KV store.

func (*KV) Remove

func (k *KV) Remove(key string) error

Remove removes a key and its associated value from the KV store.

func (*KV) Serve

func (k *KV) Serve(port int) error

Serve starts the HTTP server on the specified port with configured routes and middleware.

func (*KV) Set

func (k *KV) Set(key string, value interface{}) error

Set stores a value associated with a key in the KV store.

func (*KV) Size

func (k *KV) Size() int

Size returns the number of items currently stored in the KV store.

func (*KV) ToJSON

func (k *KV) ToJSON() ([]byte, error)

ToJSON returns the KV store data as a JSON string.

func (*KV) Values

func (k *KV) Values() []interface{}

Values returns a slice of all values currently stored in the KV store.

type Option

type Option func(*KV)

Option defines a function signature for options used to configure a KV instance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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