Documentation
¶
Index ¶
- Constants
- 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 DeduplicatePathParams(path string) string
- func EncodeFormData(data any, encoding map[string]codegen.RequestBodyEncoding) (string, error)
- 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 GoTypeToOpenAPIType(goType string) string
- 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 SanitizePathForChi(path string) string
- 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 ToUint8(value any) (uint8, bool)
- func ToUint16(value any) (uint16, bool)
- func ToUint32(value any) (uint32, bool)
- func ToUint64(value any) (uint64, bool)
- func ValidateStringWithPattern(input string, pattern string) bool
- type SignedInt
Constants ¶
const ( TypeString = "string" TypeInteger = "integer" TypeNumber = "number" TypeBoolean = "boolean" TypeObject = "object" TypeArray = "array" )
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 ¶
func CopyNestedMap ¶
CopyNestedMap returns a copy of the given map with all nested maps copied as well.
func DeduplicatePathParams ¶
DeduplicatePathParams renames duplicate path parameters in a path string. For example, "/foo/{id}/bar/{id}" becomes "/foo/{id}/bar/{id_2}". This is necessary because Chi router panics when registering routes with duplicate parameter names.
func EncodeFormData ¶
EncodeFormData encodes data as application/x-www-form-urlencoded using the provided encoding metadata. It converts codegen.RequestBodyEncoding to runtime.FieldEncoding and calls the runtime encoder.
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 GoTypeToOpenAPIType ¶
GoTypeToOpenAPIType converts a Go type string to an OpenAPI type string. This is used when converting generated Go types back to OpenAPI schema types.
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 SanitizePathForChi ¶
SanitizePathForChi converts OpenAPI wildcard paths to Chi-compatible format. Chi only allows * at the end of a route, so we convert:
- /health/** -> /health/*
- /foo/*/bar -> /foo/{wildcard}/bar
- /foo/**/bar -> /foo/{wildcard}/bar
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 ¶
func ValidateStringWithPattern ¶
ValidateStringWithPattern checks if the input string matches the given pattern.