utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils the helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookieToString

func CookieToString(cookies []*http.Cookie) string

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 ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath expands path "." or "~"

func ParseCookie

func ParseCookie(cookies string) []*http.Cookie

ParseCookie parses the given cookie string and return a slice http.Cookie.

func ReadYaml

func ReadYaml[T any](path string) (t T, err error)

ReadYaml read the YAML file and convert it to T

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

func (c *LRUCache[K, V]) Get(key K) (value V, ok bool)

Get looks up a key's value from the cache.

func (*LRUCache[K, V]) Len

func (c *LRUCache[K, V]) Len() int

Len returns the number of items in 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.

type Pair

type Pair[K comparable, V any] struct {
	Key   K
	Value V
}

Pair a key and a value pair

Jump to

Keyboard shortcuts

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