kos/util/reflection/reflection.go

24 lines
482 B
Go
Raw Normal View History

2023-06-30 14:16:16 +08:00
package reflection
2023-12-06 17:09:47 +08:00
import (
"git.nspix.com/golang/kos/util/reflect"
reflectpkg "reflect"
)
2023-06-30 14:16:16 +08:00
2023-08-16 09:57:42 +08:00
func Setter[T string | int | int64 | float64 | any](hacky any, variables map[string]T) (err error) {
2023-06-30 14:16:16 +08:00
for k, v := range variables {
if err = Set(hacky, k, v); err != nil {
return err
}
}
return
}
2023-12-06 17:09:47 +08:00
func Assign(s reflectpkg.Value, v any) error {
return reflect.Assign(s, v)
}
2023-08-16 09:57:42 +08:00
func Set(hacky any, field string, value any) (err error) {
2023-06-30 14:16:16 +08:00
return reflect.Set(hacky, field, value)
}