mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-01-24 06:16:43 +02:00
added DynamicModel form tag and removed unused helper
This commit is contained in:
parent
1cbf16b3bf
commit
3160fb2d99
@ -18,7 +18,6 @@ package jsvm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -457,7 +456,7 @@ func newDynamicModel(shape map[string]any) any {
|
||||
structFields = append(structFields, reflect.StructField{
|
||||
Name: strings.Title(k), // ensures that the field is exportable
|
||||
Type: vt,
|
||||
Tag: reflect.StructTag(`db:"` + k + `" json:"` + k + `"`),
|
||||
Tag: reflect.StructTag(`db:"` + k + `" json:"` + k + `" form:"` + k + `"`),
|
||||
})
|
||||
}
|
||||
|
||||
@ -470,42 +469,3 @@ func newDynamicModel(shape map[string]any) any {
|
||||
|
||||
return elem.Addr().Interface()
|
||||
}
|
||||
|
||||
func loadMapFields(data any, instance any) error {
|
||||
if reflect.TypeOf(data).Kind() != reflect.Map {
|
||||
return errors.New("data must be map")
|
||||
}
|
||||
|
||||
if reflect.TypeOf(instance).Kind() != reflect.Pointer {
|
||||
return errors.New("instance must be pointer")
|
||||
}
|
||||
|
||||
iv := reflect.ValueOf(instance).Elem()
|
||||
if iv.Kind() != reflect.Struct {
|
||||
return errors.New("value must be a pointer to a struct/interface")
|
||||
}
|
||||
|
||||
dv := reflect.ValueOf(data)
|
||||
|
||||
for _, k := range dv.MapKeys() {
|
||||
name := strings.Title(k.String()) // @todo reverse mapping
|
||||
field := iv.FieldByName(name)
|
||||
|
||||
if !field.CanSet() {
|
||||
continue
|
||||
}
|
||||
|
||||
v := dv.MapIndex(k)
|
||||
|
||||
if !v.CanInterface() {
|
||||
continue
|
||||
}
|
||||
|
||||
// if v.Type().Kind() == reflect.Func {
|
||||
// }
|
||||
|
||||
// field.Set(reflect.ValueOf(v.Interface()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user