common

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinBytes

func JoinBytes(bytes ...interface{}) []byte

JoinBytes is an easy way to join multiple values into a single []byte

func SysFreeMemory added in v2.2.0

func SysFreeMemory() float64

SysFreeMemory returns the amount of memory available in megabytes

func ToNumber

func ToNumber[T interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float64 | float32
}](val interface{}) T

toNumber converts multiple types to a number

accepts: int (and variants), string, []byte, byte, bool

func ToString

func ToString[T interface{ string | []byte }](val interface{}) T

toString converts multiple types to a string|[]byte

accepts: string, []byte, byte, int (and variants), [][]byte, []interface{}

Types

type CacheMap added in v2.2.0

type CacheMap[T any] struct {
	// contains filtered or unexported fields
}

func NewCache added in v2.2.0

func NewCache[T any]() CacheMap[T]

func (*CacheMap[T]) DelOld added in v2.2.0

func (cache *CacheMap[T]) DelOld(cacheTime time.Duration)

delOld removes old cache items

func (*CacheMap[T]) Get added in v2.2.0

func (cache *CacheMap[T]) Get(key string) (T, error)

get returns a value or an error if it exists

if the object key does not exist, it will return both a nil/zero value (of the relevant type) and nil error

func (*CacheMap[T]) Set added in v2.2.0

func (cache *CacheMap[T]) Set(key string, value T, err error)

set sets or adds a new key with either a value, or an error

Jump to

Keyboard shortcuts

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