kos/util/reflection/reflection.go

24 lines
481 B
Go
Raw Permalink Normal View History

2023-06-30 14:16:16 +08:00
package reflection
2023-12-06 17:09:47 +08:00
import (
2024-11-12 17:47:28 +08:00
"git.nobla.cn/golang/kos/util/reflect"
2023-12-06 17:09:47 +08:00
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)
}