Documentation
¶
Overview ¶
Package utils the helpers
Index ¶
- func CookieToString(cookies []*http.Cookie) string
- func EmptyOr[T any](value, defaultValue []T) []T
- func ExpandPath(path string) (string, error)
- func ParseCookie(cookies string) []*http.Cookie
- func ReadYaml[T any](path string) (t T, err error)
- func ZeroOr[T comparable](value, defaultValue T) T
- type LRUCache
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CookieToString ¶
CookieToString returns the serialization string of the slice http.Cookie.
func EmptyOr ¶
func EmptyOr[T any](value, defaultValue []T) []T
EmptyOr if slice is empty returns the defaultValue
func ParseCookie ¶
ParseCookie parses the given cookie string and return a slice http.Cookie.
func ZeroOr ¶
func ZeroOr[T comparable](value, defaultValue T) T
ZeroOr if value is zero value returns the defaultValue
Types ¶
type LRUCache ¶
type LRUCache[K comparable, V any] struct { sync.RWMutex // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specifies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key K, value V) // contains filtered or unexported fields }
LRUCache is an LRU cache. It is safe for concurrent access.
func NewLRUCache ¶
func NewLRUCache[K comparable, V any](maxEntries int) *LRUCache[K, V]
NewLRUCache creates a new LRUCache. If maxEntries is zero, the cache has no limit, and it's assumed that eviction is done by the caller.
func (*LRUCache[K, V]) Add ¶
func (c *LRUCache[K, V]) Add(key K, value V)
Add adds a value to the cache.
func (*LRUCache[K, V]) Clear ¶
func (c *LRUCache[K, V]) Clear()
Clear purges all stored items from the cache.
func (*LRUCache[K, V]) Remove ¶
func (c *LRUCache[K, V]) Remove(key K)
Remove removes the provided key from the cache.
func (*LRUCache[K, V]) RemoveOldest ¶
func (c *LRUCache[K, V]) RemoveOldest()
RemoveOldest removes the oldest item from the cache.