From 35076331649f79f4a2639566c1cfca6338a9d2ad Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Sat, 6 Feb 2021 01:48:22 +0800 Subject: [PATCH] no message --- utils/reflect.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 utils/reflect.go diff --git a/utils/reflect.go b/utils/reflect.go new file mode 100644 index 0000000..1b0f11d --- /dev/null +++ b/utils/reflect.go @@ -0,0 +1,21 @@ +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 +} \ No newline at end of file