-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_type.go
40 lines (34 loc) · 1.14 KB
/
db_type.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
28
29
30
31
32
33
34
35
36
37
38
39
40
package db
import "reflect"
func getSliceTypeString(paramType reflect.Type) string {
sTypeName := reflect.SliceOf(paramType.Elem()).Elem().Kind().String()
switch sTypeName {
case "bool", "float64", "float32", "int8", "uint8", "int16", "uint16",
"int32", "uint32", "int64", "uint64", "string", "int", "uint":
return "[]" + sTypeName
}
return "[]struct"
}
func getArrayTypeString(paramType reflect.Type) string {
sTypeName := reflect.SliceOf(paramType.Elem()).Elem().Kind().String()
switch sTypeName {
case "bool", "float64", "float32", "int8", "uint8", "int16", "uint16",
"int32", "uint32", "int64", "uint64", "string", "int", "uint":
return "[*]" + sTypeName
}
return "[*]struct"
}
func getTypeString(classField reflect.StructField, classVal reflect.Value) string {
paramType := classField.Type
sType := ""
if paramType.Kind() == reflect.Ptr {
sType = "*" + paramType.Elem().Kind().String()
} else if paramType.Kind() == reflect.Slice {
sType = getSliceTypeString(paramType)
} else if paramType.Kind() == reflect.Array {
sType = getArrayTypeString(paramType)
} else {
sType = classField.Type.Kind().String()
}
return sType
}