diff --git a/rule.go b/rule.go index 9e7c8a8..e70fbce 100644 --- a/rule.go +++ b/rule.go @@ -16,11 +16,17 @@ import ( type Ruleset struct { Rule []struct { - ID string `fig:"id" validate:"required"` - Regexp *regexp.Regexp `fig:"regexp" validate:"required"` + ID string `fig:"id" validate:"required"` + Regexp *regexp.Regexp `fig:"regexp" validate:"required"` + HostMatch *string `fig:"host_match"` } `fig:"rule"` } +// NewRuleset initializes a new Ruleset based on the provided Config. +// It reads the rule file specified in the Config, validates the file's +// existence, and loads the Ruleset using the fig library. +// It checks for duplicate rules and returns an error if any duplicates are found. +// If all operations are successful, it returns the created Ruleset and no error. func NewRuleset(c *Config) (*Ruleset, error) { rs := &Ruleset{} p := filepath.Dir(c.Server.RuleFile) diff --git a/server.go b/server.go index 98b9fcd..0a98107 100644 --- a/server.go +++ b/server.go @@ -71,6 +71,15 @@ func (s *Server) Run() error { s.ruleset = rs for _, r := range rs.Rule { s.log.Debug("found rule", slog.String("ID", r.ID)) + if r.HostMatch != nil { + s.log.Debug("host match enabled", slog.String("host", *r.HostMatch)) + } + if r.Regexp != nil { + foo := r.Regexp.FindAllStringSubmatch("test_foo23", -1) + if len(foo) > 0 { + s.log.Debug("matched", slog.Any("groups", foo)) + } + } } return s.RunWithListener(l)