utils

package
v0.0.0-...-c6cbf5f Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayContains

func ArrayContains[T comparable](arr []T, value T) bool

func ArrayExcluding

func ArrayExcluding[T comparable](arr []T, valueToExclude ...T) []T

func ArrayIntersection

func ArrayIntersection[T comparable](firstArray []T, secondArray []T) []T

func ArrayMap

func ArrayMap[V any, R any](arr []V, mappingFunc func(V) R) []R

func ExtractObject

func ExtractObject(object any, path ...string) (any, error)

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePort asks the kernel for free open ports that are ready to use.

func GetPort

func GetPort() int

GetPort is deprecated, use GetFreePort instead Ask the kernel for a free open port that is ready to use

func HashAny

func HashAny(value interface{}) (uint64, error)

func HashBytes

func HashBytes(payload []byte) [16]byte

func HashString

func HashString(value string) [16]byte

func IsLetterOrNumber

func IsLetterOrNumber(symbol int32) bool

IsLetterOrNumber returns true if input symbol is:

A - Z: 65-90
a - z: 97-122

func IsNumber

func IsNumber(symbol int32) bool

func JoinNonEmptyStrings

func JoinNonEmptyStrings(sep string, elems ...string) string

JoinNonEmptyStrings joins strings with separator, but ignoring empty strings

func MapClear

func MapClear[K comparable, V any](mp map[K]V)

func MapCopy

func MapCopy[K comparable, V any](mp map[K]V) map[K]V

MapCopy returns copy of map

func MapHasSameKeys

func MapHasSameKeys[K comparable, V any, J any](a map[K]V, b map[K]J) bool

func MapNVL

func MapNVL[K comparable, V any](mp map[K]V, key K, defaultValue V) V

func MapNVLFunc

func MapNVLFunc[K comparable, V any](mp map[K]V, key K, defaultFunc func() V) V

func MapNVLKeys

func MapNVLKeys[K comparable, V any](mp map[K]V, keys ...K) V

MapNVLKeys returns value by first key that exists or empty value of V type if no keys exist

func MapPutAll

func MapPutAll[K comparable, V any](destination map[K]V, source map[K]V) map[K]V

func MapPutIfAbsent

func MapPutIfAbsent[K comparable, V any](mp map[K]V, key K, value V) bool

MapPutIfAbsent puts value into map if key doesn't exist. Returns true if value was put

func MapToSlice

func MapToSlice[K comparable, V any, R any](mp map[K]V, mappingFunc func(K, V) R) []R

func MaxDuration

func MaxDuration(a, b time.Duration) time.Duration

func MaxInt

func MaxInt(a, b int) int

func Nvl

func Nvl[T comparable](args ...T) T

Nvl returns first not null object or pointer from varargs

return nil if all passed arguments are nil

func NvlMap

func NvlMap(args ...map[string]any) map[string]any

NvlMap returns first not empty map from varargs

return nil if all passed maps are empty

func NvlString

func NvlString(args ...string) string

NvlString returns first not empty string value from varargs

return "" if all strings are empty

func ParseBool

func ParseBool(value any) (bool, error)

ParseBool parses value of string, int or bool into a bool.

func ParseFloat

func ParseFloat(value any) (float64, error)

ParseFloat parses value of string, int, integer float into float64.

func ParseInt

func ParseInt(value any) (int, error)

ParseInt parses value of string, int, integer float into int.

func ParseObject

func ParseObject[K any](inputObject any, result *K) error

ParseObject parses struct of any type from input object that can be:

map, json string or yaml string,

already struct of provided type or pointer to it

func ParseString

func ParseString(value any) (string, error)

ParseString parses value of string - effectively strict type checking.

func SanitizeString

func SanitizeString(str string) string

SanitizeString returns string with only alphanumeric characters and underscores

func ShortenString

func ShortenString(str string, n int) string

ShortenString returns the first N slice of a string.

func ShortenStringWithEllipsis

func ShortenStringWithEllipsis(str string, n int) string

ShortenStringWithEllipsis returns the first N slice of a string and ends with ellipsis.

Types

type RichError

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

func NewRichError

func NewRichError(error string, payload any) *RichError

func (*RichError) Error

func (r *RichError) Error() string

func (*RichError) Payload

func (r *RichError) Payload() any

type Set

type Set[K comparable] map[K]struct{}

func NewSet

func NewSet[K comparable](values ...K) Set[K]

func (Set[K]) Clear

func (s Set[K]) Clear()

func (Set[K]) Clone

func (s Set[K]) Clone() Set[K]

func (Set[K]) Contains

func (s Set[K]) Contains(key K) bool

func (Set[K]) Equals

func (s Set[K]) Equals(other Set[K]) bool

func (Set[K]) Put

func (s Set[K]) Put(key K)

func (Set[K]) PutAll

func (s Set[K]) PutAll(keys []K)

func (Set[K]) PutAllKeys

func (s Set[K]) PutAllKeys(m map[K]any)

func (Set[K]) PutSet

func (s Set[K]) PutSet(keys Set[K])

func (Set[K]) Remove

func (s Set[K]) Remove(key K)

func (Set[K]) ToSlice

func (s Set[K]) ToSlice() []K

type Ticker

type Ticker struct {
	C      chan time.Time
	Closed chan struct{}
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(d time.Duration, startDelay time.Duration) *Ticker

func (*Ticker) Period

func (t *Ticker) Period() time.Duration

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off a ticker. After Stop, no more ticks will be sent.

Jump to

Keyboard shortcuts

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