Documentation
¶
Index ¶
- func Keys[K comparable, V any](ms ...map[K]V) []K
- func PopEncode(str string) string
- func Values[K comparable, V any](ms ...map[K]V) []V
- type Body
- func (b Body) All() iter.Seq2[string, any]
- func (b Body) CleanPayload()
- func (b Body) ClearCache()
- func (b Body) CloneJsonReader() (*bytes.Reader, error)
- func (b Body) Close() error
- func (b Body) JsonReader() (*bytes.Reader, error)
- func (b Body) MustJsonReader() *bytes.Reader
- func (b Body) QueryBytes(valueEncode func(string) string) []byte
- func (b Body) QueryString(valueEncode func(string) string) string
- func (b Body) Read(p []byte) (int, error)
- func (b Body) Seek(offset int64, whence int) (int64, error)
- type KV
- func (m KV[K, V]) Contains(key K) bool
- func (m KV[K, V]) Delete(keys ...K)
- func (m KV[K, V]) Get(key K) (V, bool)
- func (m KV[K, V]) GetDel(key K) (V, bool)
- func (m KV[K, V]) GetOrSet(key K, value V) (actual V, got bool)
- func (m KV[K, V]) GetSet(key K, value V) (V, bool)
- func (m KV[K, V]) Has(key K) bool
- func (m KV[K, V]) Keys() []K
- func (m KV[K, V]) Len() int
- func (m KV[K, V]) Range(fn func(key K, value V) bool)
- func (m KV[K, V]) Remove(keys ...K)
- func (m KV[K, V]) RemoveIf(key K, fn func(oldValue V) bool) bool
- func (m KV[K, V]) Set(key K, value V)
- func (m KV[K, V]) SetIf(key K, value V, fn func(oldValue V) bool) bool
- func (m KV[K, V]) SetIfAbsent(key K, value V) bool
- func (m KV[K, V]) SetIfPresent(key K, value V) bool
- func (m KV[K, V]) SetNx(key K, value V) bool
- func (m KV[K, V]) SetX(key K, value V) bool
- func (m KV[K, V]) Values() []V
- type SafeKV
- func (s *SafeKV[K, V]) All() iter.Seq2[K, V]
- func (s *SafeKV[K, V]) Clear()
- func (s *SafeKV[K, V]) Contains(key K) bool
- func (s *SafeKV[K, V]) Delete(keys ...K)
- func (s *SafeKV[K, V]) FillMap(m map[K]V)
- func (s *SafeKV[K, V]) Get(key K) (V, bool)
- func (s *SafeKV[K, V]) GetDel(key K) (V, bool)
- func (s *SafeKV[K, V]) GetOrSet(key K, value V) (actual V, got bool)
- func (s *SafeKV[K, V]) GetOrSetFunc(key K, fn func() (V, error)) (actual V, got bool, err error)
- func (s *SafeKV[K, V]) GetSet(key K, value V) (V, bool)
- func (s *SafeKV[K, V]) GetWithLock(key K, fn func(V))
- func (s *SafeKV[K, V]) GetWithMap(m map[K]V)
- func (s *SafeKV[K, V]) Has(key K) bool
- func (s *SafeKV[K, V]) Keys() []K
- func (s *SafeKV[K, V]) Len() int
- func (s *SafeKV[K, V]) Map(fn func(KV[K, V]))
- func (s *SafeKV[K, V]) Range(fn func(key K, value V) bool)
- func (s *SafeKV[K, V]) ReadMap(fn func(KV[K, V]))
- func (s *SafeKV[K, V]) Remove(keys ...K)
- func (s *SafeKV[K, V]) RemoveIf(key K, fn func(value V) bool) bool
- func (s *SafeKV[K, V]) Set(key K, value V)
- func (s *SafeKV[K, V]) SetBatch(kvs map[K]V)
- func (s *SafeKV[K, V]) SetIf(key K, value V, fn func(oldValue V) bool) bool
- func (s *SafeKV[K, V]) SetIfAbsent(key K, value V) bool
- func (s *SafeKV[K, V]) SetIfPresent(key K, value V) bool
- func (s *SafeKV[K, V]) SetNx(key K, value V) bool
- func (s *SafeKV[K, V]) SetX(key K, value V) bool
- func (s *SafeKV[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Keys ¶ added in v0.0.13
func Keys[K comparable, V any](ms ...map[K]V) []K
Keys returns all keys of the map.
func Values ¶ added in v0.0.13
func Values[K comparable, V any](ms ...map[K]V) []V
Values returns all values of the map.
Types ¶
type Body ¶
Body is a map[string]any
func (Body) All ¶ added in v0.0.17
All returns an iterator that yields all key-value pairs in the Body.
func (Body) CleanPayload ¶
func (b Body) CleanPayload()
CleanPayload cleans the payload Deprecated: use ClearCache instead.
func (Body) ClearCache ¶ added in v0.0.26
func (b Body) ClearCache()
ClearCache clears the cached reader
func (Body) CloneJsonReader ¶ added in v0.0.26
func (Body) JsonReader ¶ added in v0.0.26
JsonReader will return a bytes.Reader for the JSON representation of the Body It will cache the reader for subsequent calls
func (Body) MustJsonReader ¶ added in v0.0.26
func (Body) QueryBytes ¶
QueryBytes returns the query bytes
func (Body) QueryString ¶
QueryString returns the query string
type KV ¶ added in v0.0.15
type KV[K comparable, V any] map[K]V
func (KV[K, V]) Delete ¶ added in v0.0.15
func (m KV[K, V]) Delete(keys ...K)
Delete deletes the value associated with the key. This is an alias for Remove.
func (KV[K, V]) Get ¶ added in v0.0.15
Get returns the value associated with the key and whether the key existed or not.
func (KV[K, V]) GetDel ¶ added in v0.0.24
GetDel deletes the value associated with the key and returns the old value and whether the key existed or not.
func (KV[K, V]) GetOrSet ¶ added in v0.0.24
GetOrSet returns the value associated with the key if it exists. Otherwise, it sets the value associated with the key to the provided value and returns that value.
func (KV[K, V]) GetSet ¶ added in v0.0.24
GetSet sets the value associated with the key and returns the old value and whether the key existed or not.
func (KV[K, V]) Has ¶ added in v0.0.15
Has returns whether the key exists. This is an alias for Contains.
func (KV[K, V]) Range ¶ added in v0.0.15
Range calls fn sequentially for each key and value present in the map.
func (KV[K, V]) Remove ¶ added in v0.0.24
func (m KV[K, V]) Remove(keys ...K)
Remove deletes the value associated with the key.
func (KV[K, V]) RemoveIf ¶ added in v0.0.24
RemoveIf deletes the value associated with the key if fn returns true for the old value.
func (KV[K, V]) Set ¶ added in v0.0.15
func (m KV[K, V]) Set(key K, value V)
Set sets the value associated with the key.
func (KV[K, V]) SetIf ¶ added in v0.0.24
SetIf sets the value associated with the key if the key does not exist or if fn returns true for the old value.
func (KV[K, V]) SetIfAbsent ¶ added in v0.0.24
SetIfAbsent sets the value associated with the key if the key does not exist.
func (KV[K, V]) SetIfPresent ¶ added in v0.0.24
SetIfPresent sets the value associated with the key if the key exists.
func (KV[K, V]) SetNx ¶ added in v0.0.15
SetNx sets the value associated with the key if the key does not exist. This is an alias for SetIfAbsent.
type SafeKV ¶
type SafeKV[K comparable, V any] struct { // contains filtered or unexported fields }
SafeKV is a thread-safe map
func NewSafeKV ¶
func NewSafeKV[K comparable, V any](cap int) *SafeKV[K, V]
NewSafeKV creates a new SafeKV
func (*SafeKV[K, V]) All ¶ added in v0.0.17
All returns an iterator that yields all key-value pairs in the SafeKV.
func (*SafeKV[K, V]) Delete ¶
func (s *SafeKV[K, V]) Delete(keys ...K)
Delete deletes the value associated with the key alias of Remove
func (*SafeKV[K, V]) FillMap ¶ added in v0.0.24
func (s *SafeKV[K, V]) FillMap(m map[K]V)
FillMap fills the provided map with values from the SafeKV for existing keys
func (*SafeKV[K, V]) Get ¶
Get returns the value associated with the key and whether the key existed
func (*SafeKV[K, V]) GetDel ¶ added in v0.0.24
GetDel deletes the value associated with the key and returns the old value and whether the key existed
func (*SafeKV[K, V]) GetOrSet ¶ added in v0.0.24
GetOrSet returns the value associated with the key if it exists. Otherwise, it sets the value associated with the key to the provided value and returns that value.
func (*SafeKV[K, V]) GetOrSetFunc ¶ added in v0.0.24
GetOrSetFunc returns the value associated with the key if it exists. Otherwise, it sets the value associated with the key to the result of fn and returns that value. got indicates whether the value was already present.
func (*SafeKV[K, V]) GetSet ¶ added in v0.0.24
GetSet sets the value associated with the key and returns the old value and whether the key existed
func (*SafeKV[K, V]) GetWithLock ¶ added in v0.0.15
func (s *SafeKV[K, V]) GetWithLock(key K, fn func(V))
GetWithLock calls fn with the value associated with the key if the key existed
func (*SafeKV[K, V]) GetWithMap ¶ added in v0.0.15
func (s *SafeKV[K, V]) GetWithMap(m map[K]V)
GetWithMap returns the value associated with the key and whether the key existed Deprecated: use FillMap instead
func (*SafeKV[K, V]) Keys ¶ added in v0.0.15
func (s *SafeKV[K, V]) Keys() []K
Keys returns all the keys
func (*SafeKV[K, V]) Remove ¶ added in v0.0.24
func (s *SafeKV[K, V]) Remove(keys ...K)
Remove deletes the value associated with the key
func (*SafeKV[K, V]) RemoveIf ¶ added in v0.0.24
RemoveIf deletes the value associated with the key if fn returns true for the old value
func (*SafeKV[K, V]) Set ¶
func (s *SafeKV[K, V]) Set(key K, value V)
Set sets the value associated with the key
func (*SafeKV[K, V]) SetBatch ¶ added in v0.0.24
func (s *SafeKV[K, V]) SetBatch(kvs map[K]V)
SetBatch sets multiple key-value pairs at once
func (*SafeKV[K, V]) SetIf ¶ added in v0.0.24
SetIf sets the value associated with the key if the key does not exist or if fn returns true for the old value
func (*SafeKV[K, V]) SetIfAbsent ¶ added in v0.0.24
SetIfAbsent sets the value associated with the key if the key does not exist
func (*SafeKV[K, V]) SetIfPresent ¶ added in v0.0.24
SetIfPresent sets the value associated with the key if the key exists
func (*SafeKV[K, V]) SetNx ¶
SetNx sets the value associated with the key if the key does not exist alias of SetIfAbsent