Documentation
¶
Overview ¶
Package bind provides functions to work with flattened lists of structure fields.
Index ¶
- func AcceptsFields[T any]() bool
- func AcceptsList[T any]() bool
- func AcceptsScalar[T any]() bool
- func BindScalar(receiver any, value ...any) bool
- func Bindable[T any]() bool
- func BindableType(t reflect.Type) bool
- func CreateAndBindScalar[T any](value ...any) (T, bool)
- func CreateAndBindScalarFieldType(t FieldType, value ...any) (reflect.Value, bool)
- func CreateAndBindScalarFor(t reflect.Type, value ...any) (reflect.Value, bool)
- func TypeAcceptsFields(t reflect.Type) bool
- func TypeAcceptsList(t reflect.Type) bool
- func TypeAcceptsScalar(t reflect.Type) bool
- type Field
- func Bind(structure any, value ...Field) []Field
- func CreateAndBind[T any](value ...Field) (T, []Field)
- func CreateAndBindFor(t reflect.Type, value ...Field) (reflect.Value, []Field)
- func FieldValues(structure any) []Field
- func Fields[T any]() []Field
- func FieldsOf(t reflect.Type) []Field
- func NamedValue(name string, value any) Field
- func ValueByPath(path []string, value any) Field
- type FieldType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcceptsFields ¶
AcceptsFields checks if a type can be used with BindFieldsCreate or the values of the type with BindFields.
func AcceptsList ¶
AcceptsList checks if a type can be used to bind multiple values.
func AcceptsScalar ¶
AcceptsScalar checks if a type can be used with CreateScalarAndBind or the values of the type with BindScalar.
func BindScalar ¶
BindScalar sets the receiver to the provided value or values. It traverses the receiver through wrappers like pointers, slices and interfaces. If the receiver contains a slice which is greater or equal length as the number of the provided values, N, it sets the first N slice items to the values. It returns true, if the values were set. It returns false, if the values were not set, e.g. due to incompatible types.
func BindableType ¶
BindableType is like Bindable, but uses type t as input.
func CreateAndBindScalar ¶
CreateAndBindScalar is like BindScalar, but it allocates the receiver from the type T.
func CreateAndBindScalarFieldType ¶
CreateAndBindScalarFieldType is like BindScalar, but it allocates the receiver from the field type t.
func CreateAndBindScalarFor ¶
CreateAndBindScalarFor is like BindScalar, but it allocates the receiver from the type t.
func TypeAcceptsFields ¶
TypeAcceptsFields is like AcceptsFields, but uses type t as input.
func TypeAcceptsList ¶
TypeAcceptsList is like AcceptsList, but uses type t as input.
func TypeAcceptsScalar ¶
TypeAcceptsScalar is like AcceptsScalar, but uses type t as input.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is a field of structure or a compatible map. It is used as the output of the inspection functions, and as the input of the binding functions.
func Bind ¶
Bind sets structure fields recursively. It traverses through pointers, slices and interfaces. It returns the values for which it is not possible to find a compatible matching field. It supports maps that have string keys and scalar values.
func CreateAndBind ¶
CreateAndBind is like Bind, but it allocates the receiver from type T.
func CreateAndBindFor ¶
CreateAndBindFor is like Bind, but it allocates the receiver from type t.
func FieldValues ¶
FieldValues returns the fields of a structure value recursively. It traverses through pointers, slices and interfaces.
func Fields ¶
Fields returns the fields of a structure type recursively. It traverses through pointers and slices.
func NamedValue ¶
NamedValue defines a field for inptu to BindFields or BindFieldsCreate. The name is the kebab case representation of the field path. The struct boundaries in the field path are not represented in the name, which leads to potentially ambigous field references, depending on the receiver type structure and naming. In case of ambigous fields, the field that can match multiple structure fields, will be bound to each matched structure field.
func ValueByPath ¶
ValueByPath defines a field for input to BindFields or BindFieldsCreate. It defines the field by its exact field path in the receiver structure.
func (Field) List ¶
List indicates whether a field is wrapped in a slice and accpets multiple values.
type FieldType ¶
Field type represents the possible types of a field.
const ( Bool FieldType = reflect.Bool Int FieldType = reflect.Int Int8 FieldType = reflect.Int8 Int16 FieldType = reflect.Int16 Int32 FieldType = reflect.Int32 Int64 FieldType = reflect.Int64 Uint FieldType = reflect.Uint Uint8 FieldType = reflect.Uint8 Uint16 FieldType = reflect.Uint16 Uint32 FieldType = reflect.Uint32 Uint64 FieldType = reflect.Uint64 Float32 FieldType = reflect.Float32 Float64 FieldType = reflect.Float64 String FieldType = reflect.String Any FieldType = reflect.Interface Duration FieldType = 0xfffe Time FieldType = 0xffff )