keyvalue

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair struct {
	Key, Value string
}

type Storage

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

Storage is a generic structure for storing pairs of string-string. It is used across the whole database. For example, it is primarily used for request headers, however used as well as a storage for URI query, dynamic routing parameters, etc.

func New

func New() *Storage

func NewFromMap

func NewFromMap(m map[string][]string) *Storage

NewFromMap returns a new instance with already inserted values from given map. Note: as maps are unordered, resulting underlying structure will also contain unordered pairs

func NewPreAlloc

func NewPreAlloc(n int) *Storage

NewPreAlloc returns an instance of Storage with pre-allocated underlying storage

func (*Storage) Add

func (s *Storage) Add(key, value string) *Storage

Add adds a new pair of key and value

func (*Storage) Clear

func (s *Storage) Clear()

Clear all the entries. However, all the allocated space won't be freed

func (*Storage) Clone

func (s *Storage) Clone() *Storage

Clone creates a deep copy, which may be used later or stored somewhere safely. However, it comes at cost of multiple allocations

func (*Storage) Get

func (s *Storage) Get(key string) (string, bool)

Get returns a value corresponding to the key and a bool, indicating whether the key exists. In case it doesn't, empty string will be returned either

func (*Storage) Has

func (s *Storage) Has(key string) bool

Has indicates, whether there's an entry of the key

func (*Storage) Iter

func (s *Storage) Iter() iter.Iterator[Pair]

Iter returns an iterator over the pairs

func (*Storage) Keys

func (s *Storage) Keys() []string

Keys returns all unique presented keys.

WARNING: calling it twice will override values, returned by the first call. Consider copying the returned slice for safe use

func (*Storage) Unwrap

func (s *Storage) Unwrap() []Pair

Unwrap reveals underlying data structure. Try to avoid the method if possible, as changing the signature may not affect a major version

func (*Storage) Value

func (s *Storage) Value(key string) string

Value returns the first value, corresponding to the key. Otherwise, empty string is returned

func (*Storage) ValueOr

func (s *Storage) ValueOr(key, or string) string

ValueOr returns either the first value corresponding to the key or custom value, defined via the second parameter

func (*Storage) Values

func (s *Storage) Values(key string) (values []string)

Values returns all values by the key. Returns nil if key doesn't exist.

WARNING: calling it twice will override values, returned by the first call. Consider copying the returned slice for safe use

Jump to

Keyboard shortcuts

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