Documentation
¶
Overview ¶
Package goutils includes common functions for other Go packages.
Index ¶
- Constants
- Variables
- func AsBoolean(value any) (bool, error)
- func AsBooleanReflection(value reflect.Value) (bool, error)
- func AsBooleanSlice(value any) ([]bool, error)
- func AsNullableBoolean(value any) (*bool, error)
- func AsNullableBooleanReflection(value reflect.Value) (*bool, error)
- func AsNullableBooleanSlice(value any) (*[]bool, error)
- func AsNullableNumber[...](value any) (*T, error)
- func AsNullableNumberReflection[...](value reflect.Value) (*T, error)
- func AsNumber[...](value any) (T, error)
- func AsNumberReflection[...](value reflect.Value) (T, error)
- func AsNumberSlice[...](value any) ([]T, error)
- func AsNumberSliceReflection[...](reflectValue reflect.Value) ([]T, error)
- func CatchWarnContextErrorFunc(fn func(ctx context.Context) error)
- func CatchWarnErrorFunc(fn func() error)
- func CloseResponse(resp *http.Response)
- func DecodeBoolean(value any) (bool, error)
- func DecodeBooleanReflection(value reflect.Value) (bool, error)
- func DecodeBooleanSlice(value any) ([]bool, error)
- func DecodeNullableBoolean(value any) (*bool, error)
- func DecodeNullableBooleanReflection(value reflect.Value) (*bool, error)
- func DecodeNullableBooleanSlice(value any) (*[]bool, error)
- func DecodeNullableNumber[...](value any) (*T, error)
- func DecodeNullableNumberReflection[...](value reflect.Value) (*T, error)
- func DecodeNullableString(value any) (*string, error)
- func DecodeNullableStringReflection(value reflect.Value) (*string, error)
- func DecodeNumber[...](value any) (T, error)
- func DecodeNumberReflection[...](value reflect.Value) (T, error)
- func DecodeNumberSlice[...](value any) ([]T, error)
- func DecodeNumberSliceReflection[...](reflectValue reflect.Value) ([]T, error)
- func DecodeString(value any) (string, error)
- func DecodeStringReflection(value reflect.Value) (string, error)
- func DecodeStringSlice(value any) ([]string, error)
- func DecodeStringSliceReflection(reflectValue reflect.Value) ([]string, error)
- func DeepEqual[T any](x T, y any, omitZero bool) bool
- func DeepEqualPtr[T any](x, y *T, omitZero bool) bool
- func EqualComparableAny[T comparable](x T, y any) bool
- func EqualComparableAnyPtr[T comparable](x *T, y any) bool
- func EqualComparablePtr[T comparable](x, y *T) bool
- func EqualComparableSlice[T comparable](x []T, y any, omitZero bool) bool
- func EqualMap[K comparable, V any](mapA, mapB map[K]V, omitZero bool) bool
- func EqualMapPointer[K comparable, V Equaler[V]](mapA, mapB map[K]*V, omitZero bool) bool
- func EqualPtr[T Equaler[T]](a, b *T) bool
- func EqualSlice[T any](sliceA, sliceB []T, omitZero bool) bool
- func EqualSlicePtr[T Equaler[T]](sliceA, sliceB []*T) bool
- func EqualSliceSorted[T cmp.Ordered](sliceA, sliceB []T) bool
- func ExtractHeaders(headers http.Header) map[string]string
- func FileReaderFromPath(ctx context.Context, filePath string, options ...DownloadFileOption) (io.ReadCloser, string, error)
- func FormatScalar(value any) (string, bool)
- func FormatScalarReflection(reflectValue reflect.Value) (string, bool)
- func GetNodeValueFromYAMLMap(node *yaml.Node, key string) (*yaml.Node, error)
- func GetSortedKeys[K cmp.Ordered, V any](input map[K]V) []K
- func GetStringValueFromYAMLMap(node *yaml.Node, key string) (*string, error)
- func HasStringPrefixFold(input string, prefix string) bool
- func HasStringSuffixFold(input string, suffix string) bool
- func IsDigit[C byte | rune](c C) bool
- func IsDigitString(value string) bool
- func IsIntegerString(value string) bool
- func IsLowerAlphabet[C byte | rune](c C) bool
- func IsMetaCharacter[C byte | rune](c C) bool
- func IsNil(value any) bool
- func IsUpperAlphabet[C byte | rune](c C) bool
- func IsZero[T any](value T) bool
- func IsZeroPtr[T any](ptr *T) bool
- func LoadMultiJSONDocumentStream[T any](reader io.Reader) ([]T, error)
- func LoadMultiYAMLDocumentStream[T any](reader io.Reader) ([]T, error)
- func Map[T, M any](input []T, f func(T) M) []M
- func NewUUIDv7() uuid.UUID
- func ParseDateTimeNative[B []byte | string](input B) (time.Time, error)
- func ParseHTTPURL(input string) (*url.URL, error)
- func ParseIntInRange[B []byte | string](s B, minValue int, maxValue int) (int, bool)
- func ParsePathOrHTTPURL(input string) (*url.URL, error)
- func ParsePathOrURL(input string) (*url.URL, error)
- func ParseSubnet(value string) (*net.IPNet, error)
- func PtrToNumberSlice[...](inputs []*T1) ([]T2, error)
- func QuoteBytes[T string | []byte](input T) []byte
- func ReadJSONOrYAMLFile[T any](ctx context.Context, filePath string, options ...DownloadFileOption) (*T, error)
- func ReadMultiFromJSONOrYAMLFile[T any](ctx context.Context, filePath string, options ...DownloadFileOption) ([]T, error)
- func StringContainsCTLByte(s string) bool
- func ToAnyMap[K comparable, V any](input map[K]V) map[K]any
- func ToAnySlice[T any](inputs []T) []any
- func ToNumberSlice[...](inputs []T1) []T2
- func ToString(value any) string
- func UnwrapPointerFromReflectValue(reflectValue reflect.Value) (reflect.Value, bool)
- func ValidateIP(ip net.IP, options ValidateIPOptions) error
- func ValidateIPOrDomain(ctx context.Context, domainOrIP string, options ValidateIPOptions) error
- func ValidateURL(ctx context.Context, uri *url.URL, options ValidateHTTPURLOptions) error
- func ValidateURLString(ctx context.Context, urlStr string, options ValidateHTTPURLOptions) (*url.URL, error)
- type AllOrListString
- func (j AllOrListString) Contains(input string) bool
- func (j AllOrListString) Equal(target AllOrListString) bool
- func (j AllOrListString) IsAll() bool
- func (j AllOrListString) IsZero() bool
- func (j AllOrListString) List() []string
- func (j AllOrListString) Map(f func(s string) string) AllOrListString
- func (j AllOrListString) MarshalJSON() ([]byte, error)
- func (j AllOrListString) MarshalYAML() (any, error)
- func (j AllOrListString) String() string
- func (j *AllOrListString) UnmarshalJSON(data []byte) error
- func (j *AllOrListString) UnmarshalText(text []byte) error
- func (j *AllOrListString) UnmarshalYAML(value *yaml.Node) error
- type AllOrListWildcardString
- func (j AllOrListWildcardString) Contains(input string) bool
- func (j AllOrListWildcardString) Equal(target AllOrListWildcardString) bool
- func (j AllOrListWildcardString) IsZero() bool
- func (j AllOrListWildcardString) MarshalJSON() ([]byte, error)
- func (j AllOrListWildcardString) MarshalYAML() (any, error)
- func (j AllOrListWildcardString) String() string
- func (j *AllOrListWildcardString) UnmarshalJSON(data []byte) error
- func (j *AllOrListWildcardString) UnmarshalYAML(value *yaml.Node) error
- func (j AllOrListWildcardString) Wildcards() []Wildcard
- type Doer
- type DownloadFileOption
- func DownloadFileExcludingPaths(paths []string) DownloadFileOption
- func DownloadFileIncludingPaths(paths []string) DownloadFileOption
- func DownloadFileWithAllowedHosts(hosts []string) DownloadFileOption
- func DownloadFileWithBlockedHosts(hosts []string) DownloadFileOption
- func DownloadFileWithHTTPClient(client Doer) DownloadFileOption
- type Duration
- func (d Duration) Abs() Duration
- func (d Duration) Hours() float64
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) MarshalText() ([]byte, error)
- func (d Duration) Microseconds() int64
- func (d Duration) Milliseconds() int64
- func (d Duration) Minutes() float64
- func (d Duration) Nanoseconds() int64
- func (d Duration) Round(m Duration) Duration
- func (d Duration) Seconds() float64
- func (d *Duration) Set(s string) error
- func (d Duration) String() string
- func (d Duration) Truncate(m Duration) Duration
- func (*Duration) Type() string
- func (d *Duration) UnmarshalJSON(data []byte) error
- func (d *Duration) UnmarshalText(text []byte) error
- type Equaler
- type HTTPErrorWithExtensions
- type IsZeroer
- type RegexpMatcher
- func (j RegexpMatcher) Equal(target RegexpMatcher) bool
- func (j RegexpMatcher) IsZero() bool
- func (j RegexpMatcher) MarshalJSON() ([]byte, error)
- func (j RegexpMatcher) MarshalText() ([]byte, error)
- func (j *RegexpMatcher) Match(b []byte) bool
- func (j *RegexpMatcher) MatchString(s string) bool
- func (j RegexpMatcher) String() string
- func (j *RegexpMatcher) UnmarshalJSON(data []byte) error
- func (j *RegexpMatcher) UnmarshalText(bs []byte) error
- type Slug
- type Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) AddDate(years int, months int, days int) Time
- func (t Time) After(u Time) bool
- func (t Time) AppendBinary(b []byte) ([]byte, error)
- func (t Time) AppendFormat(b []byte, layout string) []byte
- func (t Time) AppendText(b []byte) ([]byte, error)
- func (t Time) Before(u Time) bool
- func (t Time) Clock() (int, int, int)
- func (t Time) Compare(u Time) int
- func (t Time) Date() (int, time.Month, int)
- func (t Time) Day() int
- func (t Time) Equal(u Time) bool
- func (t Time) Format(layout string) string
- func (t Time) GoString() string
- func (t *Time) GobDecode(data []byte) error
- func (t Time) GobEncode() ([]byte, error)
- func (t Time) Hour() int
- func (t Time) ISOWeek() (int, int)
- func (t Time) In(loc *time.Location) Time
- func (t Time) IsDST() bool
- func (t Time) IsZero() bool
- func (t Time) Local() Time
- func (t Time) Location() *time.Location
- func (t Time) MarshalBinary() ([]byte, error)
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Minute() int
- func (t Time) Month() time.Month
- func (t Time) Nanosecond() int
- func (t Time) Round(d time.Duration) Time
- func (t Time) Second() int
- func (t Time) String() string
- func (t Time) Sub(u Time) time.Duration
- func (t Time) Truncate(d time.Duration) Time
- func (t Time) UTC() Time
- func (t Time) Unix() int64
- func (t Time) UnixMicro() int64
- func (t Time) UnixMilli() int64
- func (t Time) UnixNano() int64
- func (t *Time) UnmarshalBinary(data []byte) error
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(data []byte) error
- func (t Time) Weekday() time.Weekday
- func (t Time) Year() int
- func (t Time) YearDay() int
- func (t Time) Zone() (string, int)
- func (t Time) ZoneBounds() (Time, Time)
- type ValidateHTTPURLOptions
- type ValidateIPOptions
- type Wildcard
Constants ¶
const ( // YAMLNullTag represents a constant for a YAML null tag. YAMLNullTag = "!!null" // YAMLBoolTag represents a constant for a YAML boolean tag. YAMLBoolTag = "!!bool" // YAMLStrTag represents a constant for a YAML string tag. YAMLStrTag = "!!str" // YAMLIntTag represents a constant for a YAML integer tag. YAMLIntTag = "!!int" // YAMLFloatTag represents a constant for a YAML float tag. YAMLFloatTag = "!!float" // YAMLTimestampTag represents a constant for a YAML timestamp tag. YAMLTimestampTag = "!!timestamp" // YAMLSeqTag represents a constant for a YAML sequence tag. YAMLSeqTag = "!!seq" // YAMLMapTag represents a constant for a YAML map tag. YAMLMapTag = "!!map" // YAMLBinaryTag represents a constant for a YAML binary tag. YAMLBinaryTag = "!!binary" // YAMLMergeTag represents a constant for a YAML merge tag. YAMLMergeTag = "!!merge" )
const NullStr = "null"
NullStr represents an enum for a null value.
Variables ¶
var ( // ErrDurationOutOfRange occurs when the duration int64 value is out of range. ErrDurationOutOfRange = errors.New("duration out of range") // ErrDurationEmpty occurs when the duration string is empty. ErrDurationEmpty = errors.New("empty duration string") // ErrInvalidDurationString occurs when the duration string is invalid. ErrInvalidDurationString = errors.New("not a valid duration string") // ErrUnknownDurationUnit occurs when the duration unit is unknown. ErrUnknownDurationUnit = errors.New("unknown duration unit") // ErrInvalidDateTimeString occurs when the date time string is invalid. ErrInvalidDateTimeString = errors.New("not a valid date time string") )
var ( // ErrInvalidURI represents an invalid uri error. ErrInvalidURI = errors.New("invalid URI") // ErrBlockedIP occurs when the IP is blocked. ErrBlockedIP = errors.New("ip is blocked") // ErrInvalidURLScheme represents an invalid URL scheme error. ErrInvalidURLScheme = errors.New("invalid url scheme") // ErrInvalidSubnet occurs when the subnet string is invalid. ErrInvalidSubnet = errors.New("invalid IP or subnet") // ErrInvalidSlug represents an invalid slug error. ErrInvalidSlug = errors.New("invalid slug") // ErrMalformedJSON occurs when the JSON syntax or value is malformed. ErrMalformedJSON = errors.New("malformed JSON") // ErrStringNull occurs when the string value is nil. ErrStringNull = errors.New("string value must not be null") // ErrMalformedString occurs when the string value is malformed. ErrMalformedString = errors.New("malformed string") // ErrMalformedStringSlice occurs when the string slice is malformed. ErrMalformedStringSlice = errors.New("malformed string slice") // ErrStringSliceNull occurs when the string slice is nil. ErrStringSliceNull = errors.New("string slice must not be null") // ErrNumberNull occurs when the number value is nil. ErrNumberNull = errors.New("number value must not be null") // ErrMalformedNumber occurs when the number value is malformed. ErrMalformedNumber = errors.New("malformed number") // ErrMalformedNumberSlice occurs when the number slice is malformed. ErrMalformedNumberSlice = errors.New("malformed number slice") // ErrBooleanNull occurs when the boolean value is nil. ErrBooleanNull = errors.New("boolean value must not be null") // ErrMalformedBoolean occurs when the boolean value is malformed. ErrMalformedBoolean = errors.New("malformed boolean") // ErrMalformedBooleanSlice occurs when the boolean slice is malformed. ErrMalformedBooleanSlice = errors.New("malformed boolean slice") // ErrBooleanSliceNull occurs when the boolean slice is nil. ErrBooleanSliceNull = errors.New("boolean slice must not be null") // ErrMalformedYAML occurs when the YAML syntax or structure is malformed. ErrMalformedYAML = errors.New("malformed YAML") )
Functions ¶
func AsBooleanReflection ¶
AsBooleanReflection tries to cast a boolean value from reflection.
func AsBooleanSlice ¶
AsBooleanSlice tries to cast a boolean slice from an unknown value.
func AsNullableBoolean ¶
AsNullableBoolean tries to cast an unknown value to a bool pointer.
func AsNullableBooleanReflection ¶
AsNullableBooleanReflection tries to cast a nullable boolean value from reflection.
func AsNullableBooleanSlice ¶
AsNullableBooleanSlice tries to cast a nullable boolean slice from an unknown value.
func AsNullableNumber ¶
func AsNullableNumber[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) (*T, error)
AsNullableNumber tries to cast an unknown value to a typed number.
func AsNullableNumberReflection ¶
func AsNullableNumberReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value reflect.Value, ) (*T, error)
AsNullableNumberReflection tries to cast a nullable numeric value (int, uint, or float) using reflection.
func AsNumber ¶
func AsNumber[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) (T, error)
AsNumber tries to cast an unknown value to a typed number.
func AsNumberReflection ¶
func AsNumberReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value reflect.Value, ) (T, error)
AsNumberReflection tries to cast the number value using reflection.
func AsNumberSlice ¶
func AsNumberSlice[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) ([]T, error)
AsNumberSlice tries to cast a number slice from an unknown value.
func AsNumberSliceReflection ¶
func AsNumberSliceReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( reflectValue reflect.Value, ) ([]T, error)
AsNumberSliceReflection tries to cast a number slice from a reflection value.
func CatchWarnContextErrorFunc ¶
CatchWarnContextErrorFunc catches the closer function with context and prints error with the WARN level.
func CatchWarnErrorFunc ¶
func CatchWarnErrorFunc(fn func() error)
CatchWarnErrorFunc catches the closer function and prints error with the WARN level.
func CloseResponse ¶
CloseResponse gracefully closes the HTTP response and tries to drain the body if it exists. It makes a best effort to reuse the HTTP connection.
func DecodeBoolean ¶
DecodeBoolean tries to convert an unknown value to a bool value.
func DecodeBooleanReflection ¶
DecodeBooleanReflection decodes a boolean value from reflection.
func DecodeBooleanSlice ¶
DecodeBooleanSlice decodes a boolean slice from an unknown value.
func DecodeNullableBoolean ¶
DecodeNullableBoolean tries to convert an unknown value to a bool pointer.
func DecodeNullableBooleanReflection ¶
DecodeNullableBooleanReflection decodes a nullable boolean value from reflection.
func DecodeNullableBooleanSlice ¶
DecodeNullableBooleanSlice decodes a nullable boolean slice from an unknown value.
func DecodeNullableNumber ¶
func DecodeNullableNumber[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) (*T, error)
DecodeNullableNumber tries to convert an unknown value to a typed number.
func DecodeNullableNumberReflection ¶
func DecodeNullableNumberReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value reflect.Value, ) (*T, error)
DecodeNullableNumberReflection decodes a nullable numeric value (int, uint, or float) using reflection.
func DecodeNullableString ¶
DecodeNullableString tries to convert an unknown value to a string pointer.
func DecodeNullableStringReflection ¶
DecodeNullableStringReflection decodes a nullable string from reflection value.
func DecodeNumber ¶
func DecodeNumber[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) (T, error)
DecodeNumber tries to convert an unknown value to a typed number.
func DecodeNumberReflection ¶
func DecodeNumberReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value reflect.Value, ) (T, error)
DecodeNumberReflection decodes the number value using reflection.
func DecodeNumberSlice ¶
func DecodeNumberSlice[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( value any, ) ([]T, error)
DecodeNumberSlice decodes a number slice from an unknown value.
func DecodeNumberSliceReflection ¶
func DecodeNumberSliceReflection[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( reflectValue reflect.Value, ) ([]T, error)
DecodeNumberSliceReflection decodes a number slice from a reflection value.
func DecodeString ¶
DecodeString tries to convert an unknown value to a string value.
func DecodeStringReflection ¶
DecodeStringReflection decodes a string from reflection value.
func DecodeStringSlice ¶
DecodeStringSlice decodes a string slice from an unknown value.
func DecodeStringSliceReflection ¶
DecodeStringSliceReflection decodes a string slice from a reflection value.
func DeepEqualPtr ¶
DeepEqualPtr checks if both pointers are equal recursively.
func EqualComparableAny ¶
func EqualComparableAny[T comparable](x T, y any) bool
EqualComparableAny checks if the y is comparable and equal x.
func EqualComparableAnyPtr ¶
func EqualComparableAnyPtr[T comparable](x *T, y any) bool
EqualComparableAnyPtr checks if the y is comparable and equal the pointer x.
func EqualComparablePtr ¶
func EqualComparablePtr[T comparable](x, y *T) bool
EqualComparablePtr checks if the y is comparable and equal the pointer x.
func EqualComparableSlice ¶
func EqualComparableSlice[T comparable](x []T, y any, omitZero bool) bool
EqualComparableSlice checks if the y is comparable and equal x.
func EqualMap ¶
func EqualMap[K comparable, V any](mapA, mapB map[K]V, omitZero bool) bool
EqualMap checks if both maps' elements are matched.
func EqualMapPointer ¶
func EqualMapPointer[K comparable, V Equaler[V]]( mapA, mapB map[K]*V, omitZero bool, ) bool
EqualMapPointer checks if both maps' pointer elements are matched.
func EqualSlice ¶
EqualSlice checks if both slices' elements are matched.
func EqualSlicePtr ¶
EqualSlicePtr checks if both slices' pointer elements are matched.
func EqualSliceSorted ¶
EqualSliceSorted checks if both slices's elements are matched with sorted order.
func ExtractHeaders ¶
ExtractHeaders converts the http.Header to string map with lowercase header names.
func FileReaderFromPath ¶
func FileReaderFromPath( ctx context.Context, filePath string, options ...DownloadFileOption, ) (io.ReadCloser, string, error)
FileReaderFromPath reads content from either a local filesystem path or an HTTP/HTTPS URL.
Supported URL schemes are "http" and "https". If the provided path parses as a URL with one of these schemes, an HTTP GET request is issued using http.DefaultClient without an explicit timeout configured. Callers that require timeouts or custom HTTP behavior should arrange this outside of this helper.
For other schemes, or if the input does not represent an http/https URL, the value is treated as a filesystem path, cleaned with filepath.Clean, and opened via os.Open.
The caller is responsible for closing the returned io.ReadCloser when finished with it.
func FormatScalar ¶
FormatScalar converts an arbitrary value to its string representation.
It handles the following cases:
- For nil values, it returns the provided NullStr.
- For primitive types (bool, string, integers, floats, complex), it uses the appropriate formatting.
- For time.Time and *time.Time, it uses the standard time formatting.
- For types implementing fmt.Stringer, it uses their String() method.
- For pointers, it dereferences and formats the underlying value, or returns NullStr if nil.
- For unsupported types, return an empty string and a false value.
The NullStr parameter specifies the string to return for nil values or nil pointers.
func FormatScalarReflection ¶
FormatScalarReflection converts a reflection value to its string representation.
func GetNodeValueFromYAMLMap ¶
GetNodeValueFromYAMLMap gets the node value from a YAML map node.
func GetSortedKeys ¶
GetSortedKeys extract and sort keys of a map.
func GetStringValueFromYAMLMap ¶
GetStringValueFromYAMLMap gets the string value from a YAML map node.
func HasStringPrefixFold ¶
HasStringPrefixFold check if a string has a case-insensitive prefix.
func HasStringSuffixFold ¶
HasStringSuffixFold checks if a string has a case-insensitive suffix.
func IsDigitString ¶
IsDigitString checks if every character in the string is an ASCII digit.
func IsIntegerString ¶
IsIntegerString checks if the input string can be parsed to an integer.
func IsLowerAlphabet ¶
IsLowerAlphabet checks if the character is a lowercase alphabet.
func IsMetaCharacter ¶
IsMetaCharacter checks if the character is a word character. A word character is a character a-z, A-Z, 0-9, including _ (underscore) and - (hyphen).
func IsUpperAlphabet ¶
IsUpperAlphabet checks if the character is an uppercase alphabet.
func LoadMultiJSONDocumentStream ¶
LoadMultiJSONDocumentStream loads multi-document JSON from a reader stream.
func LoadMultiYAMLDocumentStream ¶
LoadMultiYAMLDocumentStream loads multi-documents YAML from a reader stream.
func Map ¶
func Map[T, M any](input []T, f func(T) M) []M
Map applies a function to each element of a slice and returns a new slice with the results. T is the type of the input slice elements. M is the type of the output slice elements.
func ParseDateTimeNative ¶
ParseDateTimeNative parses date time in RFC 3339 or ISO 8601 format formats.
func ParseHTTPURL ¶
ParseHTTPURL parses and validate the input string to have http(s) scheme.
func ParseIntInRange ¶
ParseIntInRange parses s as an integer and verifies that it is within some range. If it is invalid or out-of-range, it sets ok to false and returns the min value.
func ParsePathOrHTTPURL ¶
ParsePathOrHTTPURL validates and parses a path or HTTP URL.
func ParsePathOrURL ¶
ParsePathOrURL validates and parses a path or URL.
func ParseSubnet ¶
ParseSubnet parses the subnet from a raw string.
func PtrToNumberSlice ¶
func PtrToNumberSlice[T1, T2 ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( inputs []*T1, ) ([]T2, error)
PtrToNumberSlice converts a slice of number pointers to a slice of values. Returns nil, nil if inputs is nil. Returns an error if any element in the slice is nil.
func QuoteBytes ¶
QuoteBytes add double quotes surround the string and convert it to bytes.
func ReadJSONOrYAMLFile ¶
func ReadJSONOrYAMLFile[T any]( ctx context.Context, filePath string, options ...DownloadFileOption, ) (*T, error)
ReadJSONOrYAMLFile reads and decodes a JSON or YAML document from the given source, which may be a local file path or an HTTP/HTTPS URL.
func ReadMultiFromJSONOrYAMLFile ¶
func ReadMultiFromJSONOrYAMLFile[T any]( ctx context.Context, filePath string, options ...DownloadFileOption, ) ([]T, error)
ReadMultiFromJSONOrYAMLFile reads and decodes multiple JSON or YAML documents from the given source, which may be a local file path or an HTTP/HTTPS URL.
func StringContainsCTLByte ¶
StringContainsCTLByte reports whether s contains any ASCII control character.
func ToAnyMap ¶
func ToAnyMap[K comparable, V any](input map[K]V) map[K]any
ToAnyMap converts a typed map to a map[K]any.
func ToAnySlice ¶
ToAnySlice converts the a typed slice to any slice.
func ToNumberSlice ¶
func ToNumberSlice[T1, T2 ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64]( inputs []T1, ) []T2
ToNumberSlice converts the element type of a number slice.
func ToString ¶
ToString converts an arbitrary value to its string representation.
It handles the following cases:
- For nil values, it returns the provided NullStr.
- For primitive types (bool, string, integers, floats, complex), it uses the appropriate formatting.
- For time.Time, time.Duration, and their pointer types, it uses the standard time formatting.
- For types implementing fmt.Stringer, it uses their String() method.
- For pointers, it dereferences and formats the underlying value, or returns NullStr if nil.
- For all other types, it uses a best-effort formatting strategy.
If JSON marshaling fails, it returns an error.
The NullStr parameter specifies the string to return for nil values or nil pointers.
func UnwrapPointerFromReflectValue ¶
UnwrapPointerFromReflectValue recursively unwraps pointers from a reflect value. Returns the unwrapped value and true if the value is valid and not nil, or false if the value is nil or invalid.
func ValidateIP ¶
func ValidateIP(ip net.IP, options ValidateIPOptions) error
ValidateIP checks if the IP is valid for SSRF protection. Note: the allowed ranges option is the highest priority to bypass other rules.
func ValidateIPOrDomain ¶
func ValidateIPOrDomain( ctx context.Context, domainOrIP string, options ValidateIPOptions, ) error
ValidateIPOrDomain checks if the IP string or IP of domain is valid for SSRF protection. If the input string is a domain, lookup the IP from it before validation.
func ValidateURL ¶
ValidateURL parses and validates URL.
func ValidateURLString ¶
func ValidateURLString( ctx context.Context, urlStr string, options ValidateHTTPURLOptions, ) (*url.URL, error)
ValidateURLString parses and validates URL from a string. Returns the parsed URL and an error.
Types ¶
type AllOrListString ¶
type AllOrListString struct {
// contains filtered or unexported fields
}
AllOrListString is a type that represents either a wildcard ("*") meaning "all items", or a specific list of strings. This is useful for configuration fields where you want to allow users to specify either all possible values (using "*") or a subset of values.
func NewAll ¶
func NewAll() AllOrListString
NewAll creates an AllOrListString that accepts all values.
func NewStringList ¶
func NewStringList(list []string) AllOrListString
NewStringList creates an AllOrListString with a list of static strings.
func (AllOrListString) Contains ¶
func (j AllOrListString) Contains(input string) bool
Contains reports whether the input value is accepted. It returns true if the wildcard "all" is set or if the input value is present in the list.
func (AllOrListString) Equal ¶
func (j AllOrListString) Equal(target AllOrListString) bool
Equal checks if the target value is equal.
func (AllOrListString) IsAll ¶
func (j AllOrListString) IsAll() bool
IsAll returns true if the value represents the wildcard ("all").
func (AllOrListString) IsZero ¶
func (j AllOrListString) IsZero() bool
IsZero returns true if the current instance is in its zero state (neither all nor list is set).
func (AllOrListString) List ¶
func (j AllOrListString) List() []string
List returns the list of strings, or nil if IsAll() is true.
func (AllOrListString) Map ¶
func (j AllOrListString) Map(f func(s string) string) AllOrListString
Map returns a new AllOrListString with transformed list string.
func (AllOrListString) MarshalJSON ¶
func (j AllOrListString) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (AllOrListString) MarshalYAML ¶
func (j AllOrListString) MarshalYAML() (any, error)
MarshalYAML implements the custom behavior for the yaml.Marshaler interface. If the wildcard state is set (all == true), it serializes as the string "*". Otherwise, it serializes the list as a YAML sequence.
func (AllOrListString) String ¶
func (j AllOrListString) String() string
String implements the custom behavior for the fmt.Stringer interface.
func (*AllOrListString) UnmarshalJSON ¶
func (j *AllOrListString) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*AllOrListString) UnmarshalText ¶
func (j *AllOrListString) UnmarshalText(text []byte) error
UnmarshalText implements the custom behavior for the encoding.TextUnmarshaler interface.
func (*AllOrListString) UnmarshalYAML ¶
func (j *AllOrListString) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements custom deserialization for the yaml.Unmarshaler interface. If the YAML value is the string "*", it is treated as a wildcard and sets 'all' to true and 'list' to nil. Otherwise, it expects a list of strings and sets 'list' accordingly, with 'all' set to false.
type AllOrListWildcardString ¶
type AllOrListWildcardString struct {
AllOrListString
// contains filtered or unexported fields
}
AllOrListWildcardString is a type that represents either a wildcard ("*") meaning "all items", or a specific list of strings. Accept a star (*) in any string for sub-matching patterns.
func NewAllOrListWildcardStringFromStrings ¶
func NewAllOrListWildcardStringFromStrings(values []string) AllOrListWildcardString
NewAllOrListWildcardStringFromStrings constructs an AllOrListWildcardString from the provided list of strings, parsing any wildcard patterns using the same logic as JSON/YAML unmarshaling.
func NewAllWildcard ¶
func NewAllWildcard() AllOrListWildcardString
NewAllWildcard creates an AllOrListWildcardString that represents all items ("*").
func (AllOrListWildcardString) Contains ¶
func (j AllOrListWildcardString) Contains(input string) bool
Contains reports whether the input value is contained in this set. It returns true if the embedded AllOrListString is in the "all" state, or if the input value is present in its static list, or if the input matches any of the configured wildcard patterns.
func (AllOrListWildcardString) Equal ¶
func (j AllOrListWildcardString) Equal(target AllOrListWildcardString) bool
Equal checks if the target value is equal.
func (AllOrListWildcardString) IsZero ¶
func (j AllOrListWildcardString) IsZero() bool
IsZero returns true if the current instance is in its zero state (neither all nor list is set).
func (AllOrListWildcardString) MarshalJSON ¶
func (j AllOrListWildcardString) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (AllOrListWildcardString) MarshalYAML ¶
func (j AllOrListWildcardString) MarshalYAML() (any, error)
MarshalYAML implements the custom behavior for the yaml.Marshaler interface. If the wildcard state is set (all == true), it serializes as the string "*". Otherwise, it serializes the list as a YAML sequence.
func (AllOrListWildcardString) String ¶
func (j AllOrListWildcardString) String() string
String implements the custom behavior for the fmt.Stringer interface.
func (*AllOrListWildcardString) UnmarshalJSON ¶
func (j *AllOrListWildcardString) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*AllOrListWildcardString) UnmarshalYAML ¶
func (j *AllOrListWildcardString) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements custom deserialization for the yaml.Unmarshaler interface. If the YAML value is the string "*", it is treated as a wildcard and sets 'all' to true and 'list' to nil. Otherwise, it expects a list of strings and sets 'list' accordingly, with 'all' set to false.
func (AllOrListWildcardString) Wildcards ¶
func (j AllOrListWildcardString) Wildcards() []Wildcard
Wildcards returns the list of wildcards, or nil if IsAll() is true.
type Doer ¶
type Doer interface {
// Do sends an HTTP request and returns an HTTP response, following policy
// (such as redirects, cookies, auth) as configured on the client.
Do(req *http.Request) (*http.Response, error)
}
Doer abstracts an interface for sending HTTP requests.
type DownloadFileOption ¶
type DownloadFileOption func(opts *downloadFileOptions)
DownloadFileOption abstracts a function to configure options for loading files.
func DownloadFileExcludingPaths ¶
func DownloadFileExcludingPaths(paths []string) DownloadFileOption
DownloadFileExcludingPaths creates an option to set a list of paths to be excluded.
func DownloadFileIncludingPaths ¶
func DownloadFileIncludingPaths(paths []string) DownloadFileOption
DownloadFileIncludingPaths creates an option to set a list of paths to be included.
func DownloadFileWithAllowedHosts ¶
func DownloadFileWithAllowedHosts(hosts []string) DownloadFileOption
DownloadFileWithAllowedHosts creates an option to set a list of allowed hosts for URL.
func DownloadFileWithBlockedHosts ¶
func DownloadFileWithBlockedHosts(hosts []string) DownloadFileOption
DownloadFileWithBlockedHosts creates an option to set a list of blocked hosts for URL.
func DownloadFileWithHTTPClient ¶
func DownloadFileWithHTTPClient(client Doer) DownloadFileOption
DownloadFileWithHTTPClient creates an option to set a custom HTTP client to load file.
type Duration ¶
Duration wraps time.Duration. It is used to parse and format custom duration strings from YAML, JSON, and text formats.
func ParseDuration ¶
ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h. Negative durations are not supported.
func (Duration) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Duration) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Duration) Microseconds ¶
Microseconds returns the duration as an integer microsecond count.
func (Duration) Milliseconds ¶
Milliseconds returns the duration as an integer millisecond count.
func (Duration) Nanoseconds ¶
Nanoseconds returns the duration as an integer nanosecond count.
func (Duration) Round ¶
Round returns the result of rounding d to the nearest multiple of m. The rounding behavior for halfway values is to round away from zero. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, Round returns the maximum (or minimum) duration. If m <= 0, Round returns d unchanged.
func (Duration) Truncate ¶
Truncate returns the result of rounding d toward zero to a multiple of m. If m <= 0, Truncate returns d unchanged.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Equaler ¶
type Equaler[T any] interface { // Equal checks if the target value is equal. Equal(target T) bool }
Equaler abstracts an interface to check the equality.
type HTTPErrorWithExtensions ¶
type HTTPErrorWithExtensions struct {
httperror.HTTPError
// Additional members that are specific to that problem type.
Extensions map[string]any
}
HTTPErrorWithExtensions is the data structure of an HTTP error with extensions. that follows the RFC 9457 specification. The schema is inspired by Swagger API specification.
func NewHTTPErrorWithExtensions ¶
func NewHTTPErrorWithExtensions( err httperror.HTTPError, extensions map[string]any, ) *HTTPErrorWithExtensions
NewHTTPErrorWithExtensions creates a new RFC 9457 error with extensions.
func (HTTPErrorWithExtensions) Error ¶
func (e HTTPErrorWithExtensions) Error() string
Error implements the error interface for HTTPErrorWithExtensions.
func (HTTPErrorWithExtensions) MarshalJSON ¶
func (e HTTPErrorWithExtensions) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*HTTPErrorWithExtensions) UnmarshalJSON ¶
func (e *HTTPErrorWithExtensions) UnmarshalJSON( data []byte, ) error
UnmarshalJSON implements the json.Unmarshaler interface.
type IsZeroer ¶
type IsZeroer interface {
IsZero() bool
}
IsZeroer abstracts an interface to check if the instance is zero.
type RegexpMatcher ¶
type RegexpMatcher struct {
// contains filtered or unexported fields
}
RegexpMatcher wraps the regexp.Regexp with a string for simple matching.
func MustRegexpMatcher ¶
func MustRegexpMatcher(input string) *RegexpMatcher
MustRegexpMatcher creates a RegexpMatcher from a raw string. Panic if error.
func NewRegexpMatcher ¶
func NewRegexpMatcher(input string) (*RegexpMatcher, error)
NewRegexpMatcher creates a RegexpMatcher from a raw string.
func (RegexpMatcher) Equal ¶
func (j RegexpMatcher) Equal(target RegexpMatcher) bool
Equal checks if the target value is equal.
func (RegexpMatcher) IsZero ¶
func (j RegexpMatcher) IsZero() bool
IsZero returns true if the current instance is in its zero state.
func (RegexpMatcher) MarshalJSON ¶
func (j RegexpMatcher) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (RegexpMatcher) MarshalText ¶
func (j RegexpMatcher) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*RegexpMatcher) Match ¶
func (j *RegexpMatcher) Match(b []byte) bool
Match reports whether the byte slice b contains any match of the regular expression re.
func (*RegexpMatcher) MatchString ¶
func (j *RegexpMatcher) MatchString(s string) bool
MatchString reports whether the string s contains any match of the regular expression re.
func (RegexpMatcher) String ¶
func (j RegexpMatcher) String() string
String implements the fmt.Stringer interface.
func (*RegexpMatcher) UnmarshalJSON ¶
func (j *RegexpMatcher) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*RegexpMatcher) UnmarshalText ¶
func (j *RegexpMatcher) UnmarshalText(bs []byte) error
UnmarshalText implements encoding.TextUnmarshaler by compiling the encoded value with regexp.Compile when treating it as a regular expression.
type Slug ¶
type Slug string
Slug represents a url-encoded string that allows alphabet, digits, hyphens and underscores only.
func (*Slug) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Slug) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler by parsing the provided text into a Slug and validating that it contains only allowed characters.
type Time ¶
Time wraps time.Time. It is used to parse and format custom date/time strings from YAML, JSON, and text formats.
func Date ¶
func Date( year int, month time.Month, day int, hour int, minutes int, sec int, nsec int, loc *time.Location, ) Time
Date returns the Time corresponding to yyyy-mm-dd hh:mm:ss + nsec nanoseconds in the appropriate zone for that time in the given location. The month, day, hour, min, sec, and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1. A daylight savings time transition skips or repeats times. For example, in the United States, March 13, 2011 2:15am never occurred, while November 6, 2011 1:15am occurred twice. In such cases, the choice of time zone, and therefore the time, is not well-defined. Date returns a time that is correct in one of the two zones involved in the transition, but it does not guarantee which. Date panics if loc is nil.
func ParseDateTime ¶
ParseDateTime parses date time in RFC 3339 or ISO 8601 format formats.
func Unix ¶
Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).
func (Time) AddDate ¶
AddDate returns the time corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.
Note that dates are fundamentally coupled to timezones, and calendrical periods like days don't have fixed durations. AddDate uses the Location of the Time value to determine these durations. That means that the same AddDate arguments can produce a different shift in absolute time depending on the base Time value and its Location. For example, AddDate(0, 0, 1) applied to 12:00 on March 27 always returns 12:00 on March 28. At some locations and in some years this is a 24 hour shift. In others it's a 23 hour shift due to daylight savings time transitions.
AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.
func (Time) AppendBinary ¶
AppendBinary implements the encoding.BinaryAppender interface.
func (Time) AppendFormat ¶
AppendFormat is like Time.Format but appends the textual representation to b and returns the extended buffer.
func (Time) AppendText ¶
AppendText implements the encoding.TextAppender interface. The time is formatted in RFC 3339 format with sub-second precision. If the timestamp cannot be represented as valid RFC 3339 (e.g., the year is out of range), then an error is returned.
func (Time) Compare ¶
Compare compares the time instant t with u. If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0.
func (Time) Equal ¶
Equal reports whether t and u represent the same time instant. Two times can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal. See the documentation on the Time type for the pitfalls of using == with Time values; most code should use Equal instead.
func (Time) Format ¶
Format returns a textual representation of the time value formatted according to the layout defined by the argument. See the documentation for the constant called [Layout] to see how to represent the layout format. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference.
func (Time) GoString ¶
GoString implements fmt.GoStringer and formats t to be printed in Go source code.
func (Time) ISOWeek ¶
ISOWeek returns the ISO 8601 year and week number in which t occurs. Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1 of year n+1.
func (Time) In ¶
In returns a copy of t representing the same time instant, but with the copy's location information set to loc for display purposes.
func (Time) IsDST ¶
IsDST reports whether the time in the configured location is in Daylight Savings Time.
func (Time) IsZero ¶
IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
func (Time) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Time) MarshalJSON ¶
MarshalJSON implements the encoding/json.Marshaler interface. The time is a quoted string in the RFC 3339 format with sub-second precision. If the timestamp cannot be represented as valid RFC 3339 (e.g., the year is out of range), then an error is reported.
func (Time) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output matches that of calling the Time.AppendText method.
func (Time) Minute ¶
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
func (Time) Nanosecond ¶
Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].
func (Time) Round ¶
Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged. Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Time) Second ¶
Second returns the second offset within the minute specified by t, in the range [0, 59].
func (Time) String ¶
String returns the time formatted using the format string
"2006-01-02 15:04:05.999999999 -0700 MST" If the time has a monotonic clock reading, the returned string includes a final field "m=±<value>", where value is the monotonic clock reading formatted as a decimal number of seconds.
The returned string is meant for debugging; for a stable serialized representation, use t.MarshalText, t.MarshalBinary, or t.Format with an explicit format string.
func (Time) Sub ¶
Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a time.Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).
func (Time) Truncate ¶
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged. Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Time) Unix ¶
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t. Unix-like operating systems often record time as a 32-bit count of seconds, but since the method here returns a 64-bit value it is valid for billions of years into the past or future.
func (Time) UnixMicro ¶
UnixMicro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in microseconds cannot be represented by an int64 (a date before year -290307 or after year 294246). The result does not depend on the location associated with t.
func (Time) UnixMilli ¶
UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in milliseconds cannot be represented by an int64 (a date more than 292 million years before or after 1970). The result does not depend on the location associated with t.
func (Time) UnixNano ¶
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined. The result does not depend on the location associated with t.
func (*Time) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the encoding/json.Unmarshaler interface. The time must be a quoted string in the RFC 3339 or ISO 8601 format.
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The time must be in the RFC 3339 or ISO 8601 format.
func (Time) YearDay ¶
YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years.
func (Time) Zone ¶
Zone computes the time zone in effect at time t, returning the abbreviated name of the zone (such as "CET") and its offset in seconds east of UTC.
func (Time) ZoneBounds ¶
ZoneBounds returns the bounds of the time zone in effect at time t. The zone begins at start and the next zone begins at end. If the zone begins at the beginning of time, start will be returned as a zero Time. If the zone goes on forever, end will be returned as a zero Time. The Location of the returned times will be the same as t.
type ValidateHTTPURLOptions ¶
type ValidateHTTPURLOptions struct {
AllowedSchemes []string
AllowedHosts []string
BlockedHosts []string
PublicIPOnly bool
AllowedIPRanges []string
BlockedIPRanges []string
// Custom lookup IP function.
LookupIP func(ctx context.Context, host string) ([]net.IP, error)
}
ValidateHTTPURLOptions represent URL validation options.
type ValidateIPOptions ¶
type ValidateIPOptions struct {
// Block all private IPs.
PublicIPOnly bool
// IP ranges to allow.
AllowedIPRanges []*net.IPNet
// IP ranges to block.
BlockedIPRanges []*net.IPNet
// Custom lookup IP function.
LookupIP func(ctx context.Context, host string) ([]net.IP, error)
}
ValidateIPOptions represent URL validation options.
type Wildcard ¶
type Wildcard struct {
// contains filtered or unexported fields
}
Wildcard represents a string with a wildcard pattern.
func NewWildcard ¶
NewWildcard creates a new Wildcard instance from string.
func (Wildcard) IsZero ¶
IsZero returns true if the current instance is in its zero state (both prefix and suffix are empty).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httperror defines HTTP error types.
|
Package httperror defines HTTP error types. |
|
Package httpheader defines HTTP header constants.
|
Package httpheader defines HTTP header constants. |