Documentation
¶
Index ¶
- Variables
- func AppendSliceFirstNonEmpty[T comparable](data []T, value ...T) []T
- func Base64Encode(input string) string
- func CopyNestedMap(source map[string]map[string]any) map[string]map[string]any
- func ExtractPlaceholders(input string) []string
- func GetRandomKeyFromMap[T any](m map[string]T) string
- func GetRandomSliceValue[T any](slice []T) T
- func GetSliceMaxRepetitionNumber[T comparable](values []T) int
- func GetSortedMapKeys[T any](content map[string]T) []string
- func GetValueByDottedPath(data map[string]any, path string) any
- func IsInteger(value any) bool
- func IsMap(i any) bool
- func IsNumber(value any) bool
- func IsSliceUnique[T comparable](path []T) bool
- func IsValidHTTPVerb(verb string) bool
- func IsValidURLResource(urlPattern string) bool
- func MapToURLEncodedForm(data map[string]any) string
- func MaybeRegexPattern(input string) bool
- func RemovePointer[T bool | float64 | int64 | uint64](value *T) T
- func SetValueByDottedPath(data map[string]any, path string, value any)
- func SliceContains[T comparable](slice []T, value T) bool
- func SliceDeleteAtIndex[T any](slice []T, index int) []T
- func SliceUnique[T comparable](slice []T) []T
- func ToFloat64(value any) (float64, error)
- func ToInt32(value any) (int32, bool)
- func ToInt64(value any) (int64, bool)
- func ToSnakeCase(input string) string
- func ToString(value any) string
- func ValidateStringWithPattern(input string, pattern string) bool
Constants ¶
This section is empty.
Variables ¶
var PlaceholderRegex = regexp.MustCompile(`\{[^\}]*\}`)
Functions ¶
func AppendSliceFirstNonEmpty ¶
func AppendSliceFirstNonEmpty[T comparable](data []T, value ...T) []T
AppendSliceFirstNonEmpty appends the first non-empty value to the given slice.
func Base64Encode ¶ added in v0.1.29
func CopyNestedMap ¶
CopyNestedMap returns a copy of the given map with all nested maps copied as well.
func ExtractPlaceholders ¶
ExtractPlaceholders extracts all placeholders including curly brackets from a pattern.
func GetRandomKeyFromMap ¶
GetRandomKeyFromMap returns a random key from the given map.
func GetRandomSliceValue ¶
func GetRandomSliceValue[T any](slice []T) T
GetRandomSliceValue returns a random value from the given slice.
func GetSliceMaxRepetitionNumber ¶
func GetSliceMaxRepetitionNumber[T comparable](values []T) int
GetSliceMaxRepetitionNumber returns the maximum number of non-unique values in the given slice.
func GetSortedMapKeys ¶
GetSortedMapKeys returns the keys of the given map sorted alphabetically.
func GetValueByDottedPath ¶
GetValueByDottedPath returns the value of the given path in the given map. If the path does not exist, nil is returned. e.g. GetValueByDottedPath(map[string]any{"a": map[string]any{"b": 1}}, "a.b") returns 1
func IsSliceUnique ¶
func IsSliceUnique[T comparable](path []T) bool
IsSliceUnique returns true if all values in the given slice are unique.
func IsValidHTTPVerb ¶
IsValidHTTPVerb checks if the given HTTP verb is valid.
func IsValidURLResource ¶
IsValidURLResource checks if the given URL resource pattern is valid: placeholders contain only alphanumeric characters, underscores, and hyphens
func MapToURLEncodedForm ¶
MapToURLEncodedForm converts a map to a URL encoded form. e.g. {"a": {"b": 1}} becomes "a[b]=1"
func MaybeRegexPattern ¶
MaybeRegexPattern checks if the input string contains any special characters. This is a simple good-enough check to see if the context key is a regex pattern.
func RemovePointer ¶
RemovePointer removes pointer from the boolean or numeric value
func SetValueByDottedPath ¶
SetValueByDottedPath sets the value of the given path in the given map. If the path does not exist, it is created. e.g. SetValueByDottedPath(map[string]any{"a": map[string]any{"b": 1}}, "a.b", 2) sets the value of "a.b" to 2 ! This function modifies the given map.
func SliceContains ¶
func SliceContains[T comparable](slice []T, value T) bool
SliceContains returns true if the given slice contains the given value.
func SliceDeleteAtIndex ¶
SliceDeleteAtIndex deletes an element from a slice at the given index and preserves the order of the slice.
func SliceUnique ¶
func SliceUnique[T comparable](slice []T) []T
SliceUnique returns a new slice with unique values from the given slice.
func ToSnakeCase ¶
ToSnakeCase converts a string to snake_case case
func ValidateStringWithPattern ¶
ValidateStringWithPattern checks if the input string matches the given pattern.
Types ¶
This section is empty.