mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-10 10:38:45 +00:00
39 lines
619 B
Go
39 lines
619 B
Go
package path
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
var (
|
|
ErrNoRegex = errors.New("path: no regex is configured")
|
|
ErrInvalidRegex = errors.New("path: regex is invalid")
|
|
)
|
|
|
|
type fileConfig struct {
|
|
Regex string `json:"regex" yaml:"regex"`
|
|
}
|
|
|
|
func (fc fileConfig) String() string {
|
|
return fmt.Sprintf("regex=%q", fc.Regex)
|
|
}
|
|
|
|
func (fc fileConfig) Valid() error {
|
|
var errs []error
|
|
|
|
if fc.Regex == "" {
|
|
errs = append(errs, ErrNoRegex)
|
|
}
|
|
|
|
if _, err := regexp.Compile(fc.Regex); err != nil {
|
|
errs = append(errs, ErrInvalidRegex, err)
|
|
}
|
|
|
|
if len(errs) != 0 {
|
|
return errors.Join(errs...)
|
|
}
|
|
|
|
return nil
|
|
}
|