Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyFunc[A ~[]T, T any](a A, fn func(T)) A
- func ApplyFuncA[A ~[]T, T any](a A, fn func(T, int, A)) A
- func CloneDeepJsonable[P *V, V any](src P) (P, error)
- func ComparePassword(password, encodedHash string) (bool, error)
- func ContainsAny[A ~[]T, T comparable](a A, b A) bool
- func FilterFunc[A ~[]T, T any](a A, fn func(T) bool) A
- func FilterFuncA[A ~[]T, T any](a A, fn func(T, int, A) bool) A
- func GetEnv(key, defaultValue string, nonEmpty bool) string
- func GetEnvBool(key string, defaultValue bool) (bool, error)
- func GetEnvBoolCsv(key string, defaultValue []bool) ([]bool, error)
- func GetEnvCsv(key string, defaultValue []string) []string
- func GetEnvFloat(key string, defaultValue float64, bitSize int) (float64, error)
- func GetEnvFloat32(key string, defaultValue float32) (float32, error)
- func GetEnvFloat32Csv(key string, defaultValue []float32) ([]float32, error)
- func GetEnvFloat64(key string, defaultValue float64) (float64, error)
- func GetEnvFloat64Csv(key string, defaultValue []float64) ([]float64, error)
- func GetEnvFloatCsv(key string, defaultValue []float64, bitSize int) ([]float64, error)
- func GetEnvInt(key string, defaultValue int64, bitSize int) (int64, error)
- func GetEnvInt16(key string, defaultValue int16) (int16, error)
- func GetEnvInt16Csv(key string, defaultValue []int16) ([]int16, error)
- func GetEnvInt32(key string, defaultValue int32) (int32, error)
- func GetEnvInt32Csv(key string, defaultValue []int32) ([]int32, error)
- func GetEnvInt64(key string, defaultValue int64) (int64, error)
- func GetEnvInt64Csv(key string, defaultValue []int64) ([]int64, error)
- func GetEnvInt8(key string, defaultValue int8) (int8, error)
- func GetEnvInt8Csv(key string, defaultValue []int8) ([]int8, error)
- func GetEnvIntCsv(key string, defaultValue []int64, bitSize int) ([]int64, error)
- func GetEnvUint(key string, defaultValue uint64, bitSize int) (uint64, error)
- func GetEnvUint16(key string, defaultValue uint16) (uint16, error)
- func GetEnvUint16Csv(key string, defaultValue []uint16) ([]uint16, error)
- func GetEnvUint32(key string, defaultValue uint32) (uint32, error)
- func GetEnvUint32Csv(key string, defaultValue []uint32) ([]uint32, error)
- func GetEnvUint64(key string, defaultValue uint64) (uint64, error)
- func GetEnvUint64Csv(key string, defaultValue []uint64) ([]uint64, error)
- func GetEnvUint8(key string, defaultValue uint8) (uint8, error)
- func GetEnvUint8Csv(key string, defaultValue []uint8) ([]uint8, error)
- func GetEnvUintCsv(key string, defaultValue []uint64, bitSize int) ([]uint64, error)
- func GetEnvWithDefault(key, defaultValue string) string
- func GetEnvWithDefaultNE(key, defaultValue string) string
- func HashPassword(password string) (string, error)
- func HashPasswordWithParams(password string, params PasswordHashParams) (string, error)
- func Intersect[A ~[]T, T comparable](a A, b A) A
- func IntersectFunc[A ~[]T, T any, O comparable](a A, b A, fn func(T) O) A
- func IntersectFuncA[A ~[]T, T any, O comparable](a A, b A, fn func(T, int, A) O) A
- func JoinInteger[A ~[]T, T Integer](a A, sep string) string
- func JoinNumbersWithFormat[A ~[]T, T Numbers](a A, sep, format string) string
- func MapToAny[T any](val T) (any, error)
- func MapToType[T any](val any) T
- func MapToTypeE[T any](val any) (T, error)
- func NewUuid() (uuid.UUID, error)
- func PanicIfError(err error)
- func Pluck[A ~[]V, V any, T any](a A, fn func(V) T) []T
- func PluckA[A ~[]V, V any, T any](a A, fn func(V, int, A) T) []T
- func Ptr[T any](v T) *T
- func RandomAlphaNum(length int) (string, error)
- func RandomPrintable(length int) (string, error)
- func RandomString(dict string, length int) (string, error)
- func RequestBaseUrl(request *http.Request) *url.URL
- func RequestFullUrl(request *http.Request) string
- func RequestUriWithoutSchemeHost(req *http.Request) *url.URL
- func RequestUrlWithQueryParam(request *http.Request, name string, value string) *url.URL
- func RequestUrlWithQueryParams(request *http.Request, params map[string]string) *url.URL
- func RequestUrlWithoutQueryParams(req *http.Request, params ...string) *url.URL
- func ReturnOrPanic[T any](v T, err error) T
- func SliceFindFunc[A ~[]I, I any](a A, fn func(I) bool) I
- func SliceFindFuncA[A ~[]I, I any](a A, fn func(I, int, A) bool) I
- func SliceMapFunc[AO ~[]O, AI ~[]I, O, I any](a AI, fn func(I) O) AO
- func SliceMapFuncA[AO ~[]O, AI ~[]I, O, I any](a AI, fn func(I, int, AI) O) AO
- func SliceMapFuncAE[AO ~[]O, AI ~[]I, O, I any](a AI, fn func(I, int, AI) (O, error)) (AO, error)
- func SliceMapFuncE[AO ~[]O, AI ~[]I, O, I any](a AI, fn func(I) (O, error)) (AO, error)
- func StringContainsAny(s string, subs []string) bool
- func StringIndexOfAny(s string, subs []string) int
- func Union[A ~[]T, T comparable](a A, b A) A
- func UnionFunc[A ~[]I, I any](a A, b A, fn func(I) bool) A
- func UnionFuncA[A ~[]I, I any](a A, b A, fn func(I, int, A) bool) A
- func UrlWithQueryParam(u url.URL, name string, value string) *url.URL
- func UrlWithQueryParams(u url.URL, params map[string]string) *url.URL
- func UrlWithoutQueryParams(u url.URL, params ...string) *url.URL
- type ComplexNumbers
- type Floats
- type Integer
- type Numbers
- type PasswordHashParams
- type SimpleTaggedLog
- func (l SimpleTaggedLog) Debugf(format string, args ...interface{})
- func (l SimpleTaggedLog) Errorf(format string, args ...interface{})
- func (l SimpleTaggedLog) Infof(format string, args ...interface{})
- func (l SimpleTaggedLog) PanicIfError(err error)
- func (l SimpleTaggedLog) Panicf(format string, args ...interface{})
- type TaggedLogger
Constants ¶
const ( PasswordHashTimesName = "PASSWORD_HASH_TIMES" PasswordHashMemoryName = "PASSWORD_HASH_MEMORY" PasswordHashThreadsName = "PASSWORD_HASH_THREADS" PasswordHashKeyLenName = "PASSWORD_HASH_KEY_LENGTH" PasswordHashSaltLenName = "PASSWORD_HASH_SALT_LENGTH" )
const ( AlphaNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" Printable = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?/`~" )
Variables ¶
var ( ErrInvalidHashFormat = errors.New("invalid hash format") ErrInvalidHashVersion = errors.New("invalid hash version") ErrInvalidHashAlgorithm = errors.New("invalid hash algorithm") )
var Jsoniter = jsoniter.ConfigCompatibleWithStandardLibrary
Functions ¶
func ApplyFunc ¶ added in v0.0.7
func ApplyFunc[A ~[]T, T any](a A, fn func(T)) A
ApplyFunc applies the given function to each element of the slice. This function is intended to operate directly on elements in the slice.
func ApplyFuncA ¶ added in v0.0.9
ApplyFuncA applies the given function to each element of the slice. This function is intended to operate directly on elements in the slice. The predicate is called with current index and the original slice.
func CloneDeepJsonable ¶ added in v0.0.7
func ComparePassword ¶ added in v0.0.4
ComparePassword compares a password with an encoded hash to check if they match.
func ContainsAny ¶ added in v0.0.7
func ContainsAny[A ~[]T, T comparable](a A, b A) bool
func FilterFunc ¶ added in v0.0.7
FilterFunc returns a new slice containing only the elements of the original slice that satisfy the predicate function.
func FilterFuncA ¶ added in v0.0.9
FilterFuncA returns a new slice containing only the elements of the original slice that satisfy the predicate function. The predicate is called with the current element, the index of the current element, and the original slice.
func GetEnv ¶ added in v0.0.3
GetEnv returns the value of the environment variable named by the key. It is guaranteed to return the `defaultValue` if the environment variable is not found. If the environment variable is found, it is guaranteed to return the `defaultValue` if the environment variable is empty and `nonEmpty` is `true`.
func GetEnvBoolCsv ¶ added in v0.0.11
func GetEnvFloat ¶ added in v0.0.11
func GetEnvFloat32 ¶ added in v0.0.11
func GetEnvFloat32Csv ¶ added in v0.0.11
func GetEnvFloat64 ¶ added in v0.0.11
func GetEnvFloat64Csv ¶ added in v0.0.11
func GetEnvFloatCsv ¶ added in v0.0.11
func GetEnvInt16Csv ¶ added in v0.0.11
func GetEnvInt32Csv ¶ added in v0.0.11
func GetEnvInt64Csv ¶ added in v0.0.11
func GetEnvInt8Csv ¶ added in v0.0.11
func GetEnvIntCsv ¶ added in v0.0.11
func GetEnvUint ¶ added in v0.0.11
func GetEnvUint16 ¶ added in v0.0.11
func GetEnvUint16Csv ¶ added in v0.0.11
func GetEnvUint32 ¶ added in v0.0.11
func GetEnvUint32Csv ¶ added in v0.0.11
func GetEnvUint64 ¶ added in v0.0.11
func GetEnvUint64Csv ¶ added in v0.0.11
func GetEnvUint8Csv ¶ added in v0.0.11
func GetEnvUintCsv ¶ added in v0.0.11
func GetEnvWithDefault ¶
GetEnvWithDefault returns the value of the environment variable named by the key. It is guaranteed to return the default value if the environment variable is not found or is empty.
func GetEnvWithDefaultNE ¶ added in v0.0.3
GetEnvWithDefaultNE returns the value of the environment variable named by the key. It is guaranteed to return the default value if the environment variable is not found. If the environment variable is found, it is guaranteed to return the default value if the environment variable is empty.
func HashPassword ¶ added in v0.0.4
HashPassword generates a new password hash using the argon2id algorithm.
func HashPasswordWithParams ¶ added in v0.0.4
func HashPasswordWithParams(password string, params PasswordHashParams) ( string, error, )
HashPassword generates a new password hash using the argon2id algorithm.
func Intersect ¶ added in v0.0.7
func Intersect[A ~[]T, T comparable](a A, b A) A
func IntersectFunc ¶ added in v0.0.7
func IntersectFunc[A ~[]T, T any, O comparable](a A, b A, fn func(T) O) A
IntersectFunc returns a new slice containing the intersection of two slices based on the result of the predicate function.
func IntersectFuncA ¶ added in v0.0.9
func IntersectFuncA[A ~[]T, T any, O comparable]( a A, b A, fn func(T, int, A) O, ) A
IntersectFuncA returns a new slice containing the intersection of two slices based on the result of the predicate function. The predicate function is called with the current element, the index of the current element, and the original slice.
func JoinInteger ¶ added in v0.0.4
JoinInteger converts a slice of integers to a string, joining them with the separator.
func JoinNumbersWithFormat ¶ added in v0.0.7
func MapToAny ¶ added in v0.1.0
MapToAny converts an element of specific type to an element of type any, returning an error if the conversion is not possible. Mainly for use as predicate function in higher-order functions such as SliceMapFuncAE.
func MapToType ¶ added in v0.0.4
MapToType converts an element of interface{} to an element of specific type, returning an error if the conversion is not possible. Mainly for use as predicate function in higher-order functions such as SliceMapFunc.
func MapToTypeE ¶ added in v0.2.0
MapToTypeE converts an element of interface{} to an element of specific type, returning an error if the conversion is not possible. Mainly for use as predicate function in higher-order functions such as SliceMapFuncAE.
func NewUuid ¶ added in v0.1.2
NewUuid returns a new UUID. It tries to generate a UUID using V7, V6, and finally falls back to V4. If all methods fail, it returns an error.
func PanicIfError ¶ added in v0.0.2
func PanicIfError(err error)
PanicIfError panics if the error is not nil.
func Pluck ¶ added in v0.0.4
Pluck extracts a list of values from a slice of structs. The predicate function fn is applied to each element of the slice, and the result is stored in a new slice.
func PluckA ¶ added in v0.0.9
PluckA extracts a list of values from a slice of structs. The predicate function fn is applied to each element of the slice, and the result is stored in a new slice. The predicate is called with current index and the original slice.
func Ptr ¶ added in v0.1.1
func Ptr[T any](v T) *T
Ptr returns a pointer to the value. Use with caution! This function directly returns a pointer to the parameter.
func RandomAlphaNum ¶ added in v0.0.4
func RandomPrintable ¶ added in v0.0.4
func RequestBaseUrl ¶ added in v0.0.6
RequestBaseUrl returns the base URL of the request.
func RequestFullUrl ¶ added in v0.1.3
RequestFullUrl returns the full URL of the request.
func RequestUriWithoutSchemeHost ¶ added in v0.0.6
RequestUriWithoutSchemeHost returns a new URL instance without scheme and host (domain).
func RequestUrlWithQueryParam ¶ added in v0.0.6
RequestUrlWithQueryParam returns a new URL instance with the given query parameter set.
func RequestUrlWithQueryParams ¶ added in v0.0.6
RequestUrlWithQueryParams returns a new URL instance with the given query parameters set.
func RequestUrlWithoutQueryParams ¶ added in v0.0.6
RequestUrlWithoutQueryParams returns a new URL instance without specified query parameters.
func ReturnOrPanic ¶ added in v0.0.12
ReturnOrPanic returns the value if the error is nil, otherwise panics.
func SliceFindFunc ¶ added in v0.0.4
SliceFindFunc returns the first element in the slice that satisfies the predicate function, or the zero value of the element type if none is found.
func SliceFindFuncA ¶ added in v0.0.9
SliceFindFuncA returns the first element in the slice that satisfies the predicate function, or the zero value of the element type if none is found. The predicate is called with current index and the original slice.
func SliceMapFunc ¶ added in v0.0.4
func SliceMapFunc[AO ~[]O, AI ~[]I, O, I any](a AI, fn func(I) O) AO
SliceMapFunc applies the predicate function to each element of the slice, returning a new slice with the results.
func SliceMapFuncA ¶ added in v0.0.9
SliceMapFuncA applies the predicate function to each element of the slice, returning a new slice with the results. The predicate is called with current index and the original slice.
func SliceMapFuncAE ¶ added in v0.2.0
func SliceMapFuncAE[AO ~[]O, AI ~[]I, O, I any]( a AI, fn func(I, int, AI) (O, error), ) (AO, error)
SliceMapFuncAE applies the predicate function to each element of the slice, returning a new slice with the results. If the predicate function returns an error, the function stops and returns the error. The predicate is called with current index and the original slice.
func SliceMapFuncE ¶ added in v0.2.0
SliceMapFuncE applies the predicate function to each element of the slice, returning a new slice with the results. If the predicate function returns an error, the function stops and returns the error.
func StringContainsAny ¶ added in v0.0.4
func StringIndexOfAny ¶ added in v0.0.4
func Union ¶ added in v0.0.10
func Union[A ~[]T, T comparable](a A, b A) A
func UnionFuncA ¶ added in v0.0.10
func UrlWithQueryParam ¶ added in v0.0.6
UrlWithQueryParam returns a URL with the given query parameters set.
func UrlWithQueryParams ¶ added in v0.0.6
UrlWithQueryParams returns a URL with the given query parameters set.
Types ¶
type ComplexNumbers ¶ added in v0.0.7
type ComplexNumbers interface { ~complex64 | ~complex128 }
type Integer ¶ added in v0.0.4
type Integer interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr }
Integer is a type constraint that includes all integer types
type Numbers ¶ added in v0.0.7
type Numbers interface { Integer | Floats | ComplexNumbers }
type PasswordHashParams ¶ added in v0.0.4
type PasswordHashParams struct { // Number of iterations Times uint32 // Amount of memory to use, in KB Memory uint32 // Parallelism, number of threads to use Threads uint8 // Key length KeyLen uint32 // Salt length SaltLen uint32 }
func DefaultPasswordHashParams ¶ added in v0.0.4
func DefaultPasswordHashParams() (*PasswordHashParams, error)
type SimpleTaggedLog ¶ added in v0.0.2
type SimpleTaggedLog struct { Debug bool // contains filtered or unexported fields }
func NewDebugLogger ¶ added in v0.0.2
func NewDebugLogger() SimpleTaggedLog
func NewLogger ¶ added in v0.0.2
func NewLogger() SimpleTaggedLog
func WrapLogger ¶ added in v0.0.2
func WrapLogger(logger *lg.Logger, debug bool) SimpleTaggedLog
func (SimpleTaggedLog) Debugf ¶ added in v0.0.2
func (l SimpleTaggedLog) Debugf(format string, args ...interface{})
func (SimpleTaggedLog) Errorf ¶ added in v0.0.2
func (l SimpleTaggedLog) Errorf(format string, args ...interface{})
func (SimpleTaggedLog) Infof ¶ added in v0.0.2
func (l SimpleTaggedLog) Infof(format string, args ...interface{})
func (SimpleTaggedLog) PanicIfError ¶ added in v0.0.2
func (l SimpleTaggedLog) PanicIfError(err error)
func (SimpleTaggedLog) Panicf ¶ added in v0.0.2
func (l SimpleTaggedLog) Panicf(format string, args ...interface{})