add assign method
This commit is contained in:
parent
df640f65fa
commit
83afa05fa3
|
@ -42,6 +42,10 @@ func findField(v reflect.Value, field string) reflect.Value {
|
|||
return v.FieldByName(field)
|
||||
}
|
||||
|
||||
func Assign(variable reflect.Value, value interface{}) (err error) {
|
||||
return safeAssignment(variable, value)
|
||||
}
|
||||
|
||||
func safeAssignment(variable reflect.Value, value interface{}) (err error) {
|
||||
var (
|
||||
n int64
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package reflection
|
||||
|
||||
import "git.nspix.com/golang/kos/util/reflect"
|
||||
import (
|
||||
"git.nspix.com/golang/kos/util/reflect"
|
||||
reflectpkg "reflect"
|
||||
)
|
||||
|
||||
func Setter[T string | int | int64 | float64 | any](hacky any, variables map[string]T) (err error) {
|
||||
for k, v := range variables {
|
||||
|
@ -11,6 +14,10 @@ func Setter[T string | int | int64 | float64 | any](hacky any, variables map[str
|
|||
return
|
||||
}
|
||||
|
||||
func Assign(s reflectpkg.Value, v any) error {
|
||||
return reflect.Assign(s, v)
|
||||
}
|
||||
|
||||
func Set(hacky any, field string, value any) (err error) {
|
||||
return reflect.Set(hacky, field, value)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue