utils

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsTemplate

func AsTemplate(s string) (*template.Template, bool)

func Base64PCMToWAV added in v0.1.11

func Base64PCMToWAV(
	base64PCM string,
	sampleRate int,
	channels int,
	bitsPerSample int,
) ([]byte, error)

Base64PCMToWAV converts base64-encoded PCM audio into a WAV byte slice.

func DecodeJSON

func DecodeJSON(r io.Reader, v any) error

func EnvironmentVariables

func EnvironmentVariables() map[string]string

func ExecuteTemplate

func ExecuteTemplate(t *template.Template, data map[string]any) (string, error)

func Ptr

func Ptr[T any](val T) *T

func TryAndParseAsTemplate

func TryAndParseAsTemplate(s string, data map[string]any) string

func WeightedRandomIndex

func WeightedRandomIndex(weights []int) int

Types

type RawMessage

type RawMessage []byte

RawMessage mirrors the behavior of encoding/json.RawMessage while keeping the project on the sonic JSON implementation.

func (*RawMessage) MarshalJSON

func (m *RawMessage) MarshalJSON() ([]byte, error)

func (*RawMessage) UnmarshalJSON

func (m *RawMessage) UnmarshalJSON(data []byte) error

type TTLSyncMap

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

TTLSyncMap is a thread-safe map with automatic cleanup of expired entries

func NewTTLSyncMap

func NewTTLSyncMap(ttl time.Duration, cleanupInterval time.Duration) *TTLSyncMap

NewTTLSyncMap creates a new TTL sync map with the specified TTL and cleanup interval ttl: time to live for each entry cleanupInterval: how often to check for expired entries (should be <= ttl)

func (*TTLSyncMap) Clear

func (m *TTLSyncMap) Clear()

Clear removes all entries from the map

func (*TTLSyncMap) Delete

func (m *TTLSyncMap) Delete(key interface{})

Delete removes a key-value pair from the map

func (*TTLSyncMap) Get

func (m *TTLSyncMap) Get(key interface{}) (interface{}, bool)

Get retrieves a value by key, returns (value, true) if found and not expired, (nil, false) otherwise

func (*TTLSyncMap) GetOrSet

func (m *TTLSyncMap) GetOrSet(key, value interface{}) (actual interface{}, loaded bool)

GetOrSet retrieves a value by key if it exists and is not expired, otherwise sets the new value and returns it

func (*TTLSyncMap) Len

func (m *TTLSyncMap) Len() int

Len returns the number of non-expired entries in the map

func (*TTLSyncMap) Range

func (m *TTLSyncMap) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration. Only non-expired entries are included.

func (*TTLSyncMap) Refresh

func (m *TTLSyncMap) Refresh(key interface{}) bool

Refresh updates the expiration time of an existing entry

func (*TTLSyncMap) Set

func (m *TTLSyncMap) Set(key, value interface{})

Set stores a key-value pair with TTL

func (*TTLSyncMap) Stop

func (m *TTLSyncMap) Stop()

Stop stops the cleanup goroutine and releases resources Call this when you're done with the map to prevent goroutine leaks

Jump to

Keyboard shortcuts

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