mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-23 08:36:41 +00:00
feat(config): add support for log filters
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Logging struct {
|
||||
Filters []LogFilter `json:"filters,omitempty" yaml:"filters,omitempty"`
|
||||
}
|
||||
|
||||
func (l *Logging) Valid() error {
|
||||
var errs []error
|
||||
|
||||
for _, lf := range l.Filters {
|
||||
if err := lf.Valid(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) != 0 {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type LogFilter struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Expression ExpressionOrList `json:"expression" yaml:"expression"`
|
||||
}
|
||||
|
||||
func (lf LogFilter) Valid() error {
|
||||
var errs []error
|
||||
|
||||
if lf.Name == "" {
|
||||
errs = append(errs, fmt.Errorf("%w: log filter has no name", ErrMissingValue))
|
||||
}
|
||||
|
||||
if err := lf.Expression.Valid(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if len(errs) != 0 {
|
||||
return fmt.Errorf("log filter %q is not valid: %w", lf.Name, errors.Join(errs...))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user