utils.go
397 Bytes
package utils
import (
"reflect"
"strings"
)
func FindIndex(schema interface{}) map[string]string{
s := reflect.TypeOf(schema)
tb := make(map[string]string)
for i := 0; i < s.NumField(); i++ {
if s.Field(i).Tag.Get("index") != "" {
js := strings.Split(s.Field(i).Tag.Get("json"), ",")
if len(js) == 0 {
continue
}
tb[strings.ToLower(s.Name())] = js[0]
}
}
return tb
}