Blame view

utils/utils.go 397 Bytes
3592dfd3   zhangqijia   重构models, 索引唯一索引
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  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
  }