add Substrings parameter to cfgset
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Paul 2025-04-27 14:22:14 +02:00
parent 5980768866
commit 71013d5b0d

View File

@ -71,6 +71,18 @@ func (cfgset *CfgSet) BuildRegex(cfg *config.Config) {
cfgset.Regex = fmt.Sprintf("(%s)", strings.Join(regs, "|"))
}
func (cfgset *CfgSet) BuildSubStrings(cfg *config.Config) {
var rr []CfgExpr
err := cfg.Db.Where("cfgset_id = $1 AND enabled", cfgset.ID).OrderBy("expr").Find(&rr)
if err != nil {
fmt.Println(err)
}
cfgset.SubStrings = []string{}
for _, v := range rr {
cfgset.SubStrings = append(cfgset.SubStrings, v.Expr)
}
}
func GetSets(cfg *config.Config) (res []CfgSet, err error) {
var w = []CfgSet{}
@ -101,8 +113,9 @@ func GetAllConfigv2(cfg *config.Config) (res CfgAllv2, err error) {
var sets = []CfgSet{}
if err := cfg.Db.Find(&sets); err == nil {
for i, _ := range sets {
for i := range sets {
sets[i].BuildRegex(cfg)
sets[i].BuildSubStrings(cfg)
}
res.Sets = sets
}
@ -178,14 +191,15 @@ type Cfg struct {
}
type CfgSet struct {
ID int `xorm:"pk autoincr" json:"-"`
Path string `xorm:"text notnull default" json:"path"`
Src string `xorm:"text notnull" json:"src"`
Filename string `xorm:"text notnull" json:"filename"`
Regex string `xorm:"-" json:"regex"`
Blocktime int64 `xorm:"notnull default 60" json:"blocktime"`
TryFail int64 `xorm:"notnull default 5" json:"tryfail"`
Enabled bool `xorm:"notnull default true" json:"-"`
ID int `xorm:"pk autoincr" json:"-"`
Path string `xorm:"text notnull default" json:"path"`
Src string `xorm:"text notnull" json:"src"`
Filename string `xorm:"text notnull" json:"filename"`
Regex string `xorm:"-" json:"regex"`
SubStrings []string `xorm:"-" json:"substrings"`
Blocktime int64 `xorm:"notnull default 60" json:"blocktime"`
TryFail int64 `xorm:"notnull default 5" json:"tryfail"`
Enabled bool `xorm:"notnull default true" json:"-"`
}
type CfgExpr struct {