package hreflect
import "github.com/gohugoio/hugo/common/hreflect"
Package hreflect contains reflect helpers.
Index ¶
- func AsTime(v reflect.Value, loc *time.Location) (time.Time, bool)
- func CallMethodByName(cxt context.Context, name string, v reflect.Value) []reflect.Value
- func GetMethodByName(v reflect.Value, name string) reflect.Value
- func GetMethodIndexByName(tp reflect.Type, name string) int
- func IsContextType(tp reflect.Type) bool
- func IsFloat(kind reflect.Kind) bool
- func IsInt(kind reflect.Kind) bool
- func IsMap(v any) bool
- func IsNumber(kind reflect.Kind) bool
- func IsSlice(v any) bool
- func IsTime(tp reflect.Type) bool
- func IsTruthful(in any) bool
- func IsTruthfulValue(val reflect.Value) (truth bool)
- func IsUint(kind reflect.Kind) bool
- func IsValid(v reflect.Value) bool
- func ToSliceAny(v any) ([]any, bool)
Functions ¶
func AsTime ¶
AsTime returns v as a time.Time if possible. The given location is only used if the value implements AsTimeProvider (e.g. go-toml local). A zero Time and false is returned if this isn't possible. Note that this function does not accept string dates.
func CallMethodByName ¶
func GetMethodByName ¶
GetMethodByName is the same as reflect.Value.MethodByName, but it caches the type lookup.
func GetMethodIndexByName ¶
GetMethodIndexByName returns the index of the method with the given name, or -1 if no such method exists.
func IsContextType ¶
IsContextType returns whether tp is a context.Context type.
func IsFloat ¶
IsFloat returns whether the given kind is a float.
func IsInt ¶
IsInt returns whether the given kind is an int.
func IsMap ¶
IsMap reports whether v is a map.
func IsNumber ¶
TODO(bep) replace the private versions in /tpl with these. IsNumber returns whether the given kind is a number.
func IsSlice ¶
IsSlice reports whether v is a slice.
func IsTime ¶
IsTime returns whether tp is a time.Time type or if it can be converted into one in ToTime.
func IsTruthful ¶
IsTruthful returns whether in represents a truthful value. See IsTruthfulValue
func IsTruthfulValue ¶
IsTruthfulValue returns whether the given value has a meaningful truth value. This is based on template.IsTrue in Go's stdlib, but also considers IsZero and any interface value will be unwrapped before it's considered for truthfulness.
func IsUint ¶
IsUint returns whether the given kind is an uint.
func IsValid ¶
IsValid returns whether v is not nil and a valid value.
func ToSliceAny ¶
ToSliceAny converts the given value to a slice of any if possible.
Source Files ¶
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 13 hours ago –
Tools for package owners.