mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-28 02:52:42 +00:00
chore(lib/policy): move Checker to its own package to avoid import cycles
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
countryCodeRegexp = regexp.MustCompile(`^\w{2}$`)
|
||||
|
||||
ErrNotCountryCode = errors.New("config.Bot: invalid country code")
|
||||
)
|
||||
|
||||
type GeoIP struct {
|
||||
Countries []string `json:"countries"`
|
||||
}
|
||||
|
||||
func (g *GeoIP) Valid() error {
|
||||
var errs []error
|
||||
|
||||
for i, cc := range g.Countries {
|
||||
if !countryCodeRegexp.MatchString(cc) {
|
||||
errs = append(errs, fmt.Errorf("%w: %s", ErrNotCountryCode, cc))
|
||||
}
|
||||
|
||||
g.Countries[i] = strings.ToLower(cc)
|
||||
}
|
||||
|
||||
if len(errs) != 0 {
|
||||
return fmt.Errorf("bot.GeoIP: invalid GeoIP settings: %w", errors.Join(errs...))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user