- no platform dependency in sync.go

This commit is contained in:
gazebo
2018-10-11 22:17:20 +08:00
parent 02b97909bc
commit 6133998e54
17 changed files with 152 additions and 52 deletions

View 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))
}