1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-11 19:50:24 +08:00

初步引入regex

This commit is contained in:
源文雨
2023-04-17 23:31:35 +08:00
parent e2a8cdf5b3
commit f65874cf52
3 changed files with 166 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ import (
"reflect"
"regexp"
"strconv"
sql "github.com/FloatTech/sqlite"
)
// Regex stores user's config of splitting docx file
@@ -73,10 +75,16 @@ func (u *UserDatabase) GetUserRegex(id int) (*Regex, error) {
if !user.IsFileManager() {
return nil, ErrInvalidRole
}
reg := newRegex()
u.mu.RLock()
_ = u.db.Find(UserTableRegex, &reg, "WHERE ID="+strconv.Itoa(id))
reg, _ := sql.Find[Regex](&u.db, UserTableRegex, "WHERE ID="+strconv.Itoa(id))
u.mu.RUnlock()
reg.ID = *user.ID
rf := reflect.ValueOf(reg)
defaultrf := reflect.ValueOf(newRegex())
for i := 0; i < rf.NumField(); i++ {
if rf.Field(i).IsZero() {
rf.Field(i).Set(defaultrf.Field(i))
}
}
return &reg, nil
}