add redis
This commit is contained in:
+14
-2
@@ -1,16 +1,28 @@
|
||||
package utils
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// ToMap struct to map[string]interface{}
|
||||
func ToMap(ss interface{}) map[string]interface{} {
|
||||
t := reflect.ValueOf(ss).Elem()
|
||||
|
||||
smap := make(map[string]interface{})
|
||||
mtag := regexp.MustCompile(`cc:\"(.+)\"`)
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
smap[t.Type().Field(i).Name] = f.Interface()
|
||||
tag := string(t.Type().Field(i).Tag)
|
||||
str := mtag.FindStringSubmatch(tag)
|
||||
name := t.Type().Field(i).Name
|
||||
if len(str) > 1 {
|
||||
name = str[1]
|
||||
}
|
||||
if name != "-" {
|
||||
smap[name] = f.Interface()
|
||||
}
|
||||
}
|
||||
|
||||
return smap
|
||||
|
||||
Reference in New Issue
Block a user