清除无效代码
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -42,40 +41,3 @@ type Article struct {
|
||||
CreateTime time.Time `json:"create_time" db:"create_time"`
|
||||
UpdateTime time.Time `json:"update_time" db:"update_time"`
|
||||
}
|
||||
|
||||
// 利用反射获取每个结构体所有字段
|
||||
func getFields(s interface{}) (fields []string) {
|
||||
t := reflect.TypeOf(s)
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
fields = append(fields, t.Field(i).Name)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// 检查字段是否存在
|
||||
func checkFields(fields []string, fields_list []string) bool {
|
||||
for _, field := range fields {
|
||||
if !contains(fields_list, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 判断字符串是否存在于字符串数组中
|
||||
func contains(s []string, e string) bool {
|
||||
for _, v := range s {
|
||||
if v == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func QueryUserList(fields []string) (user_list []User) {
|
||||
if !checkFields(fields, getFields(User{})) {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user