21 lines
400 B
Go
21 lines
400 B
Go
package utils
|
|
|
|
import "reflect"
|
|
|
|
func ReflectMakeNew(t reflect.Type) interface{} {
|
|
retptr := reflect.New(t)
|
|
sval := retptr.Elem().Interface()
|
|
return sval
|
|
}
|
|
|
|
type TagMap map[string] string
|
|
|
|
func ReflectTagMap(t reflect.Type) map[string] TagMap{
|
|
ret := map[string] TagMap{}
|
|
num := t.NumField()
|
|
for i := 0;i < num;i++{
|
|
s := t.Field(i).Tag
|
|
ret[string(s)] = t.Field(i).Name
|
|
}
|
|
return ret
|
|
} |