package utils import "reflect" const DateTimeFormat = "2006-01-02 15:04:05" func DatasToMap(datas []string) map[string]string { m := make(map[string]string, len(datas)/2) for i, data := range datas { if i%2 == 0 { m[data] = "" } else { key := datas[i-1] m[key] = data } } return m } // 根据参数名获取对应参数的值 func GetValue(data interface{}, name string) interface{} { value := reflect.ValueOf(data) for i := 0; i < value.NumField(); i++ { em := value.Field(i) if em.Kind() != reflect.Struct { continue } for j := 0; j < em.NumField(); j++ { varName := em.Type().Field(j).Tag.Get("json") if varName != name { continue } return em.Field(j).Interface() } } return nil }