utils

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsTemplate

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

func Base64PCMToWAV

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 ParseDataURL

func ParseDataURL(dataURL string) (contentType string, base64Data string, err error)

ParseDataURL splits a data URL into its content-type and the raw base64 string.

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