feat: add regex support for account item (#2714)

* feat: add regex support for account item

* feat: use reflect to process user field

* fix: fix lint problem

* feat: improve code format and fix reflect error
This commit is contained in:
DacongDA
2024-02-17 15:24:36 +08:00
committed by GitHub
parent 4a68dd65cd
commit d731c3c934
52 changed files with 336 additions and 39 deletions

View File

@ -15,7 +15,9 @@
package object
import (
"encoding/json"
"fmt"
"reflect"
"strconv"
"strings"
@ -221,6 +223,26 @@ type ManagedAccount struct {
SigninUrl string `xorm:"varchar(200)" json:"signinUrl"`
}
func GetUserFieldStringValue(user *User, fieldName string) (bool, string, error) {
val := reflect.ValueOf(*user)
fieldValue := val.FieldByName(fieldName)
if !fieldValue.IsValid() {
return false, "", nil
}
if fieldValue.Kind() == reflect.String {
return true, fieldValue.String(), nil
}
marshalValue, err := json.Marshal(fieldValue.Interface())
if err != nil {
return false, "", err
}
return true, string(marshalValue), nil
}
func GetGlobalUserCount(field, value string) (int64, error) {
session := GetSession("", -1, -1, field, value, "", "")
return session.Count(&User{})