utils

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFile added in v0.0.3

func AppendFile(filePath string, content string) error

AppendFile appends the given content to the given file path. If the file does not exist, it creates the file.

func CheckHash

func CheckHash(input, hash string) error

func Contains

func Contains[T comparable](slice []T, element T) bool

func CopyFile

func CopyFile(src string, dst string) error

func Env

func Env(name string, defaultValues ...string) string

func EscapeQuery

func EscapeQuery(query string) string

EscapeQuery escapes the query string to be used in a regular expression. copied from ent test

func Filter

func Filter[T any](slice []T, predicate func(T) bool) []T

func GenerateHash

func GenerateHash(input string) (string, error)

func GetMapKeys

func GetMapKeys[K comparable, V any](m map[K]V) []K

func GetMapValues

func GetMapValues[K comparable, V any](m map[K]V) []V

func If

func If[T any](condition bool, ifTrue T, ifFalse T) T

func IfFn

func IfFn[T any](condition bool, ifTrue func() T, ifFalse func() T) T

func IsFileExists

func IsFileExists(filePath string) bool

IsFileExists checks if the given file path exists.

func IsNumber

func IsNumber(value any) bool

IsNumber checks if the given any is a number

func IsValidBool

func IsValidBool(v any) bool

IsValidBool check if the given value is a valid boolean.

func IsValidFloat

func IsValidFloat(v any) bool

IsValidFloat check if the given value is a valid float.

func IsValidInt

func IsValidInt(v any) bool

IsValidInt check if the given value is a valid integer.

func IsValidString

func IsValidString(v any) bool

IsValidString check if the given value is a valid string.

func IsValidTime

func IsValidTime(v any) bool

IsValidTime check if the given value is a valid time.

func IsValidUInt

func IsValidUInt(v any) bool

IsValidUInt check if the given value is a valid unsigned integer.

func Map

func Map[T any, R any](slice []T, mapper func(T) R) []R

func MergeErrorMessages added in v0.0.5

func MergeErrorMessages(errs ...error) error

func MkDirs

func MkDirs(dirs ...string) error

func Must

func Must[T any](value T, err error) T

func Pick

func Pick(obj any, path string, defaultValues ...any) any

Pick returns value in the nested map by the given paths in format: "path.to.value"

func RandomString

func RandomString(length int) string

func ReadCloserToString added in v0.0.5

func ReadCloserToString(rc io.ReadCloser) (string, error)

func SecureRandomBytes

func SecureRandomBytes(length int) ([]byte, error)

SecureRandomBytes returns the requested number of bytes using crypto/rand

func SliceEqual

func SliceEqual[T comparable](slice1 []T, slice2 []T) bool

func SliceInsertBeforeElement

func SliceInsertBeforeElement[T comparable](slice []T, newElement T, checkIndexFn func(element T) bool) []T

func WriteFile

func WriteFile(filePath string, content string) error

WriteFile writes the given content to the given file path.

Types

type HashConfig

type HashConfig struct {
	Iterations uint32
	Memory     uint32
	KeyLen     uint32
	Threads    uint8
}

Jump to

Keyboard shortcuts

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