-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
27 lines (22 loc) · 894 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package autumn
import "reflect"
// isStructurePointer determines if the supplied value is a structure pointer
func isStructurePointer(data interface{}) bool {
isPtr := reflect.ValueOf(data).Kind() == reflect.Ptr
if !isPtr {
return false
}
return reflect.ValueOf(data).Elem().Kind() == reflect.Struct
}
// getStructureType gets the type of the supplied structure
func getStructureType(data interface{}) reflect.Type {
return reflect.ValueOf(data).Elem().Type()
}
// getStructureValue gets the reflection value of the supplied structure, which is usually a pointer to the structure
func getStructureValue(data interface{}) reflect.Value {
return reflect.ValueOf(data)
}
// getStructureElement dereferences the structure pointer and gets a reflection value for the underlying structure
func getStructureElement(data interface{}) reflect.Value {
return reflect.ValueOf(data).Elem()
}