add redis

This commit is contained in:
Jay
2018-04-18 14:16:29 +08:00
parent 4fd4c7018e
commit 6419162471
48 changed files with 9952 additions and 14 deletions
+14 -2
View File
@@ -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