Linting and staticcheck fixes. (#101)

* Fix linting and staticcheck issues

* Add changelog update

* Remove SetNext
This commit is contained in:
Yulian Kuncheff 2025-03-25 15:02:05 +01:00 committed by GitHub
parent 18cd8a66a2
commit f29a200f09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 13 additions and 17 deletions

View file

@ -64,7 +64,7 @@ func (m *Impl[K, V]) Get(key K) (V, bool) {
m.lock.Lock() m.lock.Lock()
// Since previously reading m.data[key], the value may have been updated. // Since previously reading m.data[key], the value may have been updated.
// Delete the entry only if the expiry time is still the same. // Delete the entry only if the expiry time is still the same.
if m.data[key].expiry == value.expiry { if m.data[key].expiry.Equal(value.expiry) {
delete(m.data, key) delete(m.data, key)
} }
m.lock.Unlock() m.lock.Unlock()

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactor & Split up Anubis into cmd and lib.go - Refactor & Split up Anubis into cmd and lib.go
- Fixed bot check to only apply if address range matches - Fixed bot check to only apply if address range matches
- Fix default difficulty setting that was broken in a refactor - Fix default difficulty setting that was broken in a refactor
- Linting fixes
## v1.14.2 ## v1.14.2

View file

@ -153,7 +153,7 @@ func startPlaywright(t *testing.T) {
daemonize(t, fmt.Sprintf("npx --yes playwright@%s run-server --port %d", playwrightVersion, *playwrightPort)) daemonize(t, fmt.Sprintf("npx --yes playwright@%s run-server --port %d", playwrightVersion, *playwrightPort))
for true { for {
if _, err := http.Get(fmt.Sprintf("http://localhost:%d", *playwrightPort)); err != nil { if _, err := http.Get(fmt.Sprintf("http://localhost:%d", *playwrightPort)); err != nil {
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
continue continue
@ -355,7 +355,7 @@ func pwTimeout(tc testCase, deadline time.Time) *float64 {
max = *playwrightMaxHardTime max = *playwrightMaxHardTime
} }
d := deadline.Sub(time.Now()) d := time.Until(deadline)
if d <= 0 || d > max { if d <= 0 || d > max {
return playwright.Float(float64(max.Milliseconds())) return playwright.Float(float64(max.Milliseconds()))
} }

View file

@ -98,10 +98,6 @@ func New(opts Options) (*Server, error) {
return nil, fmt.Errorf("failed to generate ed25519 key: %w", err) return nil, fmt.Errorf("failed to generate ed25519 key: %w", err)
} }
if err != nil {
return nil, err // parseConfig sets a fancy error for us
}
result := &Server{ result := &Server{
next: opts.Next, next: opts.Next,
priv: priv, priv: priv,

View file

@ -51,7 +51,7 @@ func (b BotConfig) Valid() error {
errs = append(errs, ErrBotMustHaveName) errs = append(errs, ErrBotMustHaveName)
} }
if b.UserAgentRegex == nil && b.PathRegex == nil && (b.RemoteAddr == nil || len(b.RemoteAddr) == 0) { if b.UserAgentRegex == nil && b.PathRegex == nil && len(b.RemoteAddr) == 0 {
errs = append(errs, ErrBotMustHaveUserAgentOrPath) errs = append(errs, ErrBotMustHaveUserAgentOrPath)
} }
@ -71,7 +71,7 @@ func (b BotConfig) Valid() error {
} }
} }
if b.RemoteAddr != nil && len(b.RemoteAddr) > 0 { if len(b.RemoteAddr) > 0 {
for _, cidr := range b.RemoteAddr { for _, cidr := range b.RemoteAddr {
if _, _, err := net.ParseCIDR(cidr); err != nil { if _, _, err := net.ParseCIDR(cidr); err != nil {
errs = append(errs, ErrInvalidCIDR, err) errs = append(errs, ErrInvalidCIDR, err)

View file

@ -46,24 +46,23 @@ func ParseConfig(fin io.Reader, fname string, defaultDifficulty int) (*ParsedCon
return nil, err return nil, err
} }
var err error var validationErrs []error
result := NewParsedConfig(c) result := NewParsedConfig(c)
result.DefaultDifficulty = defaultDifficulty result.DefaultDifficulty = defaultDifficulty
for _, b := range c.Bots { for _, b := range c.Bots {
if berr := b.Valid(); berr != nil { if berr := b.Valid(); berr != nil {
err = errors.Join(err, berr) validationErrs = append(validationErrs, berr)
continue continue
} }
var botParseErr error
parsedBot := Bot{ parsedBot := Bot{
Name: b.Name, Name: b.Name,
Action: b.Action, Action: b.Action,
} }
if b.RemoteAddr != nil && len(b.RemoteAddr) > 0 { if len(b.RemoteAddr) > 0 {
parsedBot.Ranger = cidranger.NewPCTrieRanger() parsedBot.Ranger = cidranger.NewPCTrieRanger()
for _, cidr := range b.RemoteAddr { for _, cidr := range b.RemoteAddr {
@ -79,7 +78,7 @@ func ParseConfig(fin io.Reader, fname string, defaultDifficulty int) (*ParsedCon
if b.UserAgentRegex != nil { if b.UserAgentRegex != nil {
userAgent, err := regexp.Compile(*b.UserAgentRegex) userAgent, err := regexp.Compile(*b.UserAgentRegex)
if err != nil { if err != nil {
botParseErr = errors.Join(botParseErr, fmt.Errorf("while compiling user agent regexp: %w", err)) validationErrs = append(validationErrs, fmt.Errorf("while compiling user agent regexp: %w", err))
continue continue
} else { } else {
parsedBot.UserAgent = userAgent parsedBot.UserAgent = userAgent
@ -89,7 +88,7 @@ func ParseConfig(fin io.Reader, fname string, defaultDifficulty int) (*ParsedCon
if b.PathRegex != nil { if b.PathRegex != nil {
path, err := regexp.Compile(*b.PathRegex) path, err := regexp.Compile(*b.PathRegex)
if err != nil { if err != nil {
botParseErr = errors.Join(botParseErr, fmt.Errorf("while compiling path regexp: %w", err)) validationErrs = append(validationErrs, fmt.Errorf("while compiling path regexp: %w", err))
continue continue
} else { } else {
parsedBot.Path = path parsedBot.Path = path
@ -112,8 +111,8 @@ func ParseConfig(fin io.Reader, fname string, defaultDifficulty int) (*ParsedCon
result.Bots = append(result.Bots, parsedBot) result.Bots = append(result.Bots, parsedBot)
} }
if err != nil { if len(validationErrs) > 0 {
return nil, fmt.Errorf("errors validating policy config JSON %s: %w", fname, err) return nil, fmt.Errorf("errors validating policy config JSON %s: %w", fname, errors.Join(validationErrs...))
} }
result.DNSBL = c.DNSBL result.DNSBL = c.DNSBL