utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 18 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 Capitalize added in v0.1.0

func Capitalize(s string) string

Capitalize the first letter of the given string

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 CreateSwaggerUIPage added in v0.1.0

func CreateSwaggerUIPage(specURL string) string

CreateSwaggerUIPage creates a simple HTML page that serves the Swagger UI

func CreateZeroValue added in v0.1.0

func CreateZeroValue(t reflect.Type) any

CreateZeroValue creates a zero value of a type.

func Dereferenceable added in v0.1.0

func Dereferenceable(v any) bool

Dereferenceable returns true if the value is dereferenceable.

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 GeneratePointerChain added in v0.1.0

func GeneratePointerChain(v any, times int) any

GeneratePointerChain creates a chain of pointers by taking the address of the original value 'v' 'times' number of times. It returns the final value in the pointer chain.

func GetDereferencedType added in v0.1.0

func GetDereferencedType(v any) reflect.Type

GetDereferencedType returns the dereferenced type of a value 'v'

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 GetStructFieldName added in v0.1.0

func GetStructFieldName(field reflect.StructField, fromTags ...string) string

GetStructFieldName returns the name of a struct field based on the provided reflect.StructField and tag name.

If no tag name is provided, it defaults to "json".
If the field name is "-", it returns an empty string.

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 IsNotAny added in v0.1.0

func IsNotAny(v any) bool

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 ParseHJSON added in v0.1.0

func ParseHJSON[T any](input []byte) (T, error)

ParseHJSON parses the given input byte slice as HJSON and returns the result as type T.

func ParseStructFieldTag added in v0.1.0

func ParseStructFieldTag(field reflect.StructField, tagName string) map[string]string

ParseStructFieldTag parses the struct field tag and returns a map of tag key-value pairs.

For example, if the struct tag is:
`fs:"name=title;label=Title;multiple;unique;optional;sortable;filterable;size=255"`,
then ParseStructFieldTag(field, "fs") will return:
{
	"name": "title",
	"label": "Title",
	"multiple": "",
	"unique": "",
	"optional": "",
	"sortable": "",
	"filterable": "",
	"size": "255",
}

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 Title added in v0.1.0

func Title(s string) string

Title converts a string to title case

func ToSnakeCase added in v0.1.0

func ToSnakeCase(s string) string

ToSnakeCase converts a string from capital case to snake case

	For example:
 	"ToSnakeCase" -> "create_snake_case"
 	"userID" -> "user_id"
 	"HTTPResponse" -> "http_response"

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