add Substrings parameter to cfgset
This commit is contained in:
parent
5980768866
commit
71013d5b0d
@ -71,6 +71,18 @@ func (cfgset *CfgSet) BuildRegex(cfg *config.Config) {
|
|||||||
cfgset.Regex = fmt.Sprintf("(%s)", strings.Join(regs, "|"))
|
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) {
|
func GetSets(cfg *config.Config) (res []CfgSet, err error) {
|
||||||
var w = []CfgSet{}
|
var w = []CfgSet{}
|
||||||
|
|
||||||
@ -101,8 +113,9 @@ func GetAllConfigv2(cfg *config.Config) (res CfgAllv2, err error) {
|
|||||||
|
|
||||||
var sets = []CfgSet{}
|
var sets = []CfgSet{}
|
||||||
if err := cfg.Db.Find(&sets); err == nil {
|
if err := cfg.Db.Find(&sets); err == nil {
|
||||||
for i, _ := range sets {
|
for i := range sets {
|
||||||
sets[i].BuildRegex(cfg)
|
sets[i].BuildRegex(cfg)
|
||||||
|
sets[i].BuildSubStrings(cfg)
|
||||||
}
|
}
|
||||||
res.Sets = sets
|
res.Sets = sets
|
||||||
}
|
}
|
||||||
@ -178,14 +191,15 @@ type Cfg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CfgSet struct {
|
type CfgSet struct {
|
||||||
ID int `xorm:"pk autoincr" json:"-"`
|
ID int `xorm:"pk autoincr" json:"-"`
|
||||||
Path string `xorm:"text notnull default" json:"path"`
|
Path string `xorm:"text notnull default" json:"path"`
|
||||||
Src string `xorm:"text notnull" json:"src"`
|
Src string `xorm:"text notnull" json:"src"`
|
||||||
Filename string `xorm:"text notnull" json:"filename"`
|
Filename string `xorm:"text notnull" json:"filename"`
|
||||||
Regex string `xorm:"-" json:"regex"`
|
Regex string `xorm:"-" json:"regex"`
|
||||||
Blocktime int64 `xorm:"notnull default 60" json:"blocktime"`
|
SubStrings []string `xorm:"-" json:"substrings"`
|
||||||
TryFail int64 `xorm:"notnull default 5" json:"tryfail"`
|
Blocktime int64 `xorm:"notnull default 60" json:"blocktime"`
|
||||||
Enabled bool `xorm:"notnull default true" json:"-"`
|
TryFail int64 `xorm:"notnull default 5" json:"tryfail"`
|
||||||
|
Enabled bool `xorm:"notnull default true" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CfgExpr struct {
|
type CfgExpr struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user