- no platform dependency in sync.go
This commit is contained in:
22
business/jxutils/jxutils_reflect.go
Normal file
22
business/jxutils/jxutils_reflect.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package jxutils
|
||||
|
||||
import "reflect"
|
||||
|
||||
func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
||||
value := reflect.ValueOf(item)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
} else {
|
||||
panic("item ust be ptr type")
|
||||
}
|
||||
return &value
|
||||
}
|
||||
|
||||
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
||||
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
||||
}
|
||||
|
||||
func SetObjFieldByName(obj interface{}, fieldName string, value interface{}) {
|
||||
refValue := CheckAndGetStructValue(obj)
|
||||
refValue.FieldByName(fieldName).Set(reflect.ValueOf(value))
|
||||
}
|
||||
Reference in New Issue
Block a user