mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 09:48:08 -04:00

* perf(internal): Use FastHash for internal hashing docs: Add xxhash performance improvement to changelog entry feat(hash): Add fast non-cryptographic hash function Signed-off-by: Jason Cameron <git@jasoncameron.dev> * test(hash): add xxhash benchmarks and collision tests Signed-off-by: Jason Cameron <git@jasoncameron.dev> * Update metadata check-spelling run (pull_request) for json/hash Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com> on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev> --------- Signed-off-by: Jason Cameron <git@jasoncameron.dev> Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
42 lines
639 B
Go
42 lines
639 B
Go
// Package checker defines the Checker interface and a helper utility to avoid import cycles.
|
|
package checker
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/TecharoHQ/anubis/internal"
|
|
)
|
|
|
|
type Impl interface {
|
|
Check(*http.Request) (bool, error)
|
|
Hash() string
|
|
}
|
|
|
|
type List []Impl
|
|
|
|
func (l List) Check(r *http.Request) (bool, error) {
|
|
for _, c := range l {
|
|
ok, err := c.Check(r)
|
|
if err != nil {
|
|
return ok, err
|
|
}
|
|
if ok {
|
|
return ok, nil
|
|
}
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
func (l List) Hash() string {
|
|
var sb strings.Builder
|
|
|
|
for _, c := range l {
|
|
fmt.Fprintln(&sb, c.Hash())
|
|
}
|
|
|
|
return internal.FastHash(sb.String())
|
|
}
|