69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
|
|
// provides more flexible and permissive ways of setting values than reflect.Value.Set
|
||
|
|
package bind
|
||
|
|
|
||
|
|
type Field struct {
|
||
|
|
name string
|
||
|
|
path []string
|
||
|
|
list bool
|
||
|
|
value any
|
||
|
|
}
|
||
|
|
|
||
|
|
// the receiver must be addressable
|
||
|
|
func BindScalar(receiver any, value ...any) bool {
|
||
|
|
return bindScalarReflect(receiver, value)
|
||
|
|
}
|
||
|
|
|
||
|
|
func BindScalarCreate[T any](value ...any) (T, bool) {
|
||
|
|
return bindScalarCreateReflect[T](value)
|
||
|
|
}
|
||
|
|
|
||
|
|
func FieldValue(path []string, value any) Field {
|
||
|
|
return Field{path: path, value: value}
|
||
|
|
}
|
||
|
|
|
||
|
|
func FieldValueByName(name string, value any) Field {
|
||
|
|
return Field{name: name, value: value}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (f Field) Path() []string {
|
||
|
|
p := make([]string, len(f.path))
|
||
|
|
copy(p, f.path)
|
||
|
|
return p
|
||
|
|
}
|
||
|
|
|
||
|
|
func (f Field) Name() string { return f.name }
|
||
|
|
func (f Field) List() bool { return f.list }
|
||
|
|
func (f Field) Value() any { return f.value }
|
||
|
|
|
||
|
|
func Fields[T any]() []Field {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func FieldValues(structure any) []Field {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func BindFields(structure any, values []Field) []Field {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func BindFieldsCreate[T any](values []Field) (any, []Field) {
|
||
|
|
return nil, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func AcceptsScalar[T any]() bool {
|
||
|
|
return acceptsScalarReflect[T]()
|
||
|
|
}
|
||
|
|
|
||
|
|
func AcceptsFields[T any]() bool {
|
||
|
|
return acceptsFieldsReflect[T]()
|
||
|
|
}
|
||
|
|
|
||
|
|
func AcceptsList[T any]() bool {
|
||
|
|
return acceptsListReflect[T]()
|
||
|
|
}
|
||
|
|
|
||
|
|
func Bindable[T any]() bool {
|
||
|
|
return bindableReflect[T]()
|
||
|
|
}
|