mapz

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

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 PopEncode

func PopEncode(str string) string

PopEncode encodes the string for pop

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

type Body map[string]any

Body is a map[string]any

func (Body) All added in v0.0.17

func (b Body) All() iter.Seq2[string, any]

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 (b Body) CloneJsonReader() (*bytes.Reader, error)

func (Body) Close added in v0.0.26

func (b Body) Close() error

func (Body) JsonReader added in v0.0.26

func (b Body) JsonReader() (*bytes.Reader, error)

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 (b Body) MustJsonReader() *bytes.Reader

func (Body) QueryBytes

func (b Body) QueryBytes(valueEncode func(string) string) []byte

QueryBytes returns the query bytes

func (Body) QueryString

func (b Body) QueryString(valueEncode func(string) string) string

QueryString returns the query string

func (Body) Read

func (b Body) Read(p []byte) (int, error)

Read reads the body as bytes.Reader

func (Body) Seek added in v0.0.26

func (b Body) Seek(offset int64, whence int) (int64, error)

type KV added in v0.0.15

type KV[K comparable, V any] map[K]V

func (KV[K, V]) Contains added in v0.0.21

func (m KV[K, V]) Contains(key K) bool

Contains returns whether the key exists.

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

func (m KV[K, V]) Get(key K) (V, bool)

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

func (m KV[K, V]) GetDel(key K) (V, bool)

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

func (m KV[K, V]) GetOrSet(key K, value V) (actual V, got bool)

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

func (m KV[K, V]) GetSet(key K, value V) (V, bool)

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

func (m KV[K, V]) Has(key K) bool

Has returns whether the key exists. This is an alias for Contains.

func (KV[K, V]) Keys added in v0.0.15

func (m KV[K, V]) Keys() []K

Keys returns all the keys.

func (KV[K, V]) Len added in v0.0.15

func (m KV[K, V]) Len() int

Len returns the number of items.

func (KV[K, V]) Range added in v0.0.15

func (m KV[K, V]) Range(fn func(key K, value V) bool)

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

func (m KV[K, V]) RemoveIf(key K, fn func(oldValue V) bool) bool

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

func (m KV[K, V]) SetIf(key K, value V, fn func(oldValue V) bool) bool

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

func (m KV[K, V]) SetIfAbsent(key K, value V) bool

SetIfAbsent sets the value associated with the key if the key does not exist.

func (KV[K, V]) SetIfPresent added in v0.0.24

func (m KV[K, V]) SetIfPresent(key K, value V) bool

SetIfPresent sets the value associated with the key if the key exists.

func (KV[K, V]) SetNx added in v0.0.15

func (m KV[K, V]) SetNx(key K, value V) bool

SetNx sets the value associated with the key if the key does not exist. This is an alias for SetIfAbsent.

func (KV[K, V]) SetX added in v0.0.15

func (m KV[K, V]) SetX(key K, value V) bool

SetX sets the value associated with the key if the key exists. This is an alias for SetIfPresent.

func (KV[K, V]) Values added in v0.0.15

func (m KV[K, V]) Values() []V

Values returns all the values.

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

func (s *SafeKV[K, V]) All() iter.Seq2[K, V]

All returns an iterator that yields all key-value pairs in the SafeKV.

func (*SafeKV[K, V]) Clear

func (s *SafeKV[K, V]) Clear()

Clear clears the map

func (*SafeKV[K, V]) Contains added in v0.0.21

func (s *SafeKV[K, V]) Contains(key K) bool

Contains returns whether the key exists

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

func (s *SafeKV[K, V]) Get(key K) (V, bool)

Get returns the value associated with the key and whether the key existed

func (*SafeKV[K, V]) GetDel added in v0.0.24

func (s *SafeKV[K, V]) GetDel(key K) (V, bool)

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

func (s *SafeKV[K, V]) GetOrSet(key K, value V) (actual V, got bool)

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

func (s *SafeKV[K, V]) GetOrSetFunc(key K, fn func() (V, error)) (actual V, got bool, err error)

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

func (s *SafeKV[K, V]) GetSet(key K, value V) (V, bool)

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]) Has added in v0.0.15

func (s *SafeKV[K, V]) Has(key K) bool

Has returns whether the key exists alias of Contains

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]) Len

func (s *SafeKV[K, V]) Len() int

Len returns the length of the map

func (*SafeKV[K, V]) Map

func (s *SafeKV[K, V]) Map(fn func(KV[K, V]))

Map calls fn with the map under write lock

func (*SafeKV[K, V]) Range

func (s *SafeKV[K, V]) Range(fn func(key K, value V) bool)

Range calls fn sequentially for each key and value present in the map.

func (*SafeKV[K, V]) ReadMap added in v0.0.24

func (s *SafeKV[K, V]) ReadMap(fn func(KV[K, V]))

ReadMap calls fn with the map under read lock

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

func (s *SafeKV[K, V]) RemoveIf(key K, fn func(value V) bool) bool

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

func (s *SafeKV[K, V]) SetIf(key K, value V, fn func(oldValue V) bool) bool

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

func (s *SafeKV[K, V]) SetIfAbsent(key K, value V) bool

SetIfAbsent sets the value associated with the key if the key does not exist

func (*SafeKV[K, V]) SetIfPresent added in v0.0.24

func (s *SafeKV[K, V]) SetIfPresent(key K, value V) bool

SetIfPresent sets the value associated with the key if the key exists

func (*SafeKV[K, V]) SetNx

func (s *SafeKV[K, V]) SetNx(key K, value V) bool

SetNx sets the value associated with the key if the key does not exist alias of SetIfAbsent

func (*SafeKV[K, V]) SetX

func (s *SafeKV[K, V]) SetX(key K, value V) bool

SetX sets the value associated with the key if the key exists alias of SetIfPresent

func (*SafeKV[K, V]) Values added in v0.0.15

func (s *SafeKV[K, V]) Values() []V

Values returns all the values

Jump to

Keyboard shortcuts

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