internal

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 CopyNestedMap

func CopyNestedMap(source map[string]map[string]any) map[string]map[string]any

CopyNestedMap returns a copy of the given map with all nested maps copied as well.

func ExtractPlaceholders

func ExtractPlaceholders(input string) []string

ExtractPlaceholders extracts all placeholders including curly brackets from a pattern.

func GetRandomKeyFromMap

func GetRandomKeyFromMap[T any](m map[string]T) string

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

func GetSortedMapKeys[T any](content map[string]T) []string

GetSortedMapKeys returns the keys of the given map sorted alphabetically.

func GetValueByDottedPath

func GetValueByDottedPath(data map[string]any, path string) any

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 IsInteger

func IsInteger(value any) bool

IsInteger checks if the value is an integer

func IsMap

func IsMap(i any) bool

IsMap checks if the value is a map

func IsNumber

func IsNumber(value any) bool

IsNumber checks if the value is a number: integer or float

func IsSliceUnique

func IsSliceUnique[T comparable](path []T) bool

IsSliceUnique returns true if all values in the given slice are unique.

func IsValidHTTPVerb

func IsValidHTTPVerb(verb string) bool

IsValidHTTPVerb checks if the given HTTP verb is valid.

func IsValidURLResource

func IsValidURLResource(urlPattern string) bool

IsValidURLResource checks if the given URL resource pattern is valid: placeholders contain only alphanumeric characters, underscores, and hyphens

func MapToURLEncodedForm

func MapToURLEncodedForm(data map[string]any) string

MapToURLEncodedForm converts a map to a URL encoded form. e.g. {"a": {"b": 1}} becomes "a[b]=1"

func MaybeRegexPattern

func MaybeRegexPattern(input string) bool

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

func RemovePointer[T bool | float64 | int64 | uint64](value *T) T

RemovePointer removes pointer from the boolean or numeric value

func SetValueByDottedPath

func SetValueByDottedPath(data map[string]any, path string, value any)

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

func SliceDeleteAtIndex[T any](slice []T, index int) []T

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 ToFloat64

func ToFloat64(value any) (float64, error)

ToFloat64 converts underlying value to float64 if it can be represented as float64

func ToInt32

func ToInt32(value any) (int32, bool)

ToInt32 converts underlying value to int32 if it can be represented as int32

func ToInt64

func ToInt64(value any) (int64, bool)

ToInt64 converts underlying value to int64 if it can be represented as int64

func ToSnakeCase

func ToSnakeCase(input string) string

ToSnakeCase converts a string to snake_case case

func ToString

func ToString(value any) string

func ValidateStringWithPattern

func ValidateStringWithPattern(input string, pattern string) bool

ValidateStringWithPattern checks if the input string matches the given pattern.

Types

This section is empty.

Jump to

Keyboard shortcuts

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