Documentation ¶
Index ¶
- func Assign(value any, out any) bool
- func BindingName(field reflect.StructField) string
- func FindField(structType reflect.Type, name string) (reflect.StructField, bool)
- func FlattenPointerType(t reflect.Type) reflect.Type
- func IndirectTypeKind(valueType reflect.Type) reflect.Kind
- func IsNil(value reflect.Value) bool
- func IsStructOrPointerTo(valueType reflect.Type) bool
- func ToBindingValue(value any, bindingPath string, out any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶
Assign simply performs a reflective replacement of the value, making sure to try to properly handle pointers.
func BindingName ¶
func BindingName(field reflect.StructField) string
BindingName just returns the name of the field/attribute on the struct unless it has a `json` tag defined. If so, it will use the remapped name for this field instead.
type Foo struct { A string B string `json:"hello" }
The binding name for the first attribute is "A", but the binding name for the other is "hello".
func FindField ¶
FindField looks up the struct field attribute for the given field on the given struct.
func FlattenPointerType ¶
FlattenPointerType looks at the reflective type and if it's a pointer it will flatten it to the type it is a pointer for (e.g. "*string"->"string"). If it's already a non-pointer then we will leave this type as-is.
func IndirectTypeKind ¶
IndirectTypeKind returns the underlying reflection Kind. This will unravel pointers until we get to a primordial value type.
IndirectTypeKind(reflect.Type(someInt)) -> reflect.Int IndirectTypeKind(reflect.Type(someIntPointer)) -> reflect.Int IndirectTypeKind(reflect.Type(someString)) -> reflect.String IndirectTypeKind(reflect.Type(someStringPointer)) -> reflect.String IndirectTypeKind(reflect.Type(someDuration)) -> reflect.Int64 IndirectTypeKind(reflect.Type(someDurationPointer)) -> reflect.Int64
func IsStructOrPointerTo ¶
IsStructOrPointerTo returns true if the given type is any sort of struct or a pointer to some sort of struct type.
func ToBindingValue ¶
ToBindingValue is used for fetching one-off values from struct instances given their binding string. For example, you can take an instance of a User{} struct and the binding path "Group.ID" to fetch the user's group id.
Example:
user := User{Name: "Bob", Group: Group{ID:"12345", Name:"Admins"}} name := ToBindingValue(user, "Name") // will be "Bob" groupID := ToBindingValue(user, "Group.ID") // will be "12345" groupName := ToBindingValue(user, "Group.Name") // will be "Admins"
Types ¶
This section is empty.