Version: v0.101.0 Latest Latest

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 6 Imported by: 0



Package hreflect contains reflect helpers.



This section is empty.


View Source
var ContextInterface = reflect.TypeOf((*context.Context)(nil)).Elem()


func AsTime added in v0.100.2

func AsTime(v reflect.Value, loc *time.Location) (time.Time, bool)

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 GetMethodByName added in v0.94.0

func GetMethodByName(v reflect.Value, name string) reflect.Value

GetMethodByName is the same as reflect.Value.MethodByName, but it caches the type lookup.

func GetMethodIndexByName added in v0.94.0

func GetMethodIndexByName(tp reflect.Type, name string) int

GetMethodIndexByName returns the index of the method with the given name, or -1 if no such method exists.

func IsFloat added in v0.76.0

func IsFloat(kind reflect.Kind) bool

IsFloat returns whether the given kind is a float.

func IsInt added in v0.76.0

func IsInt(kind reflect.Kind) bool

IsInt returns whether the given kind is an int.

func IsNumber added in v0.76.0

func IsNumber(kind reflect.Kind) bool

TODO(bep) replace the private versions in /tpl with these. IsNumber returns whether the given kind is a number.

func IsTime added in v0.100.2

func IsTime(tp reflect.Type) bool

IsTime returns whether tp is a time.Time type or if it can be converted into one in ToTime.

func IsTruthful

func IsTruthful(in any) bool

IsTruthful returns whether in represents a truthful value. See IsTruthfulValue

func IsTruthfulValue

func IsTruthfulValue(val reflect.Value) (truth bool)

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.

Based on:

func IsUint added in v0.76.0

func IsUint(kind reflect.Kind) bool

IsUint returns whether the given kind is an uint.


This section is empty.

Source Files

Jump to

Keyboard shortcuts

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