perf: apply fieldalignement (#1284)
This commit is contained in:
parent
da1890380e
commit
9dd4de6f1f
27 changed files with 90 additions and 94 deletions
|
|
@ -8,9 +8,9 @@ import (
|
|||
|
||||
func TestASNsValid(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *ASNs
|
||||
err error
|
||||
input *ASNs
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "basic valid",
|
||||
|
|
|
|||
|
|
@ -62,13 +62,11 @@ type BotConfig struct {
|
|||
Expression *ExpressionOrList `json:"expression,omitempty" yaml:"expression,omitempty"`
|
||||
Challenge *ChallengeRules `json:"challenge,omitempty" yaml:"challenge,omitempty"`
|
||||
Weight *Weight `json:"weight,omitempty" yaml:"weight,omitempty"`
|
||||
GeoIP *GeoIP `json:"geoip,omitempty"`
|
||||
ASNs *ASNs `json:"asns,omitempty"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Action Rule `json:"action" yaml:"action"`
|
||||
RemoteAddr []string `json:"remote_addresses,omitempty" yaml:"remote_addresses,omitempty"`
|
||||
|
||||
// Thoth features
|
||||
GeoIP *GeoIP `json:"geoip,omitempty"`
|
||||
ASNs *ASNs `json:"asns,omitempty"`
|
||||
}
|
||||
|
||||
func (b BotConfig) Zero() bool {
|
||||
|
|
@ -324,13 +322,13 @@ func (sc StatusCodes) Valid() error {
|
|||
}
|
||||
|
||||
type fileConfig struct {
|
||||
Bots []BotOrImport `json:"bots"`
|
||||
DNSBL bool `json:"dnsbl"`
|
||||
OpenGraph openGraphFileConfig `json:"openGraph,omitempty"`
|
||||
Impressum *Impressum `json:"impressum,omitempty"`
|
||||
StatusCodes StatusCodes `json:"status_codes"`
|
||||
Store *Store `json:"store"`
|
||||
Bots []BotOrImport `json:"bots"`
|
||||
Thresholds []Threshold `json:"thresholds"`
|
||||
StatusCodes StatusCodes `json:"status_codes"`
|
||||
DNSBL bool `json:"dnsbl"`
|
||||
}
|
||||
|
||||
func (c *fileConfig) Valid() error {
|
||||
|
|
@ -462,13 +460,13 @@ func Load(fin io.Reader, fname string) (*Config, error) {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
Impressum *Impressum
|
||||
Store *Store
|
||||
OpenGraph OpenGraph
|
||||
Bots []BotConfig
|
||||
Thresholds []Threshold
|
||||
DNSBL bool
|
||||
Impressum *Impressum
|
||||
OpenGraph OpenGraph
|
||||
StatusCodes StatusCodes
|
||||
Store *Store
|
||||
DNSBL bool
|
||||
}
|
||||
|
||||
func (c Config) Valid() error {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ func p[V any](v V) *V { return &v }
|
|||
|
||||
func TestBotValid(t *testing.T) {
|
||||
var tests = []struct {
|
||||
bot BotConfig
|
||||
err error
|
||||
name string
|
||||
bot BotConfig
|
||||
}{
|
||||
{
|
||||
name: "simple user agent",
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ import (
|
|||
|
||||
func TestExpressionOrListMarshalJSON(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *ExpressionOrList
|
||||
output []byte
|
||||
err error
|
||||
input *ExpressionOrList
|
||||
name string
|
||||
output []byte
|
||||
}{
|
||||
{
|
||||
name: "single expression",
|
||||
|
|
@ -74,10 +74,10 @@ func TestExpressionOrListMarshalJSON(t *testing.T) {
|
|||
|
||||
func TestExpressionOrListMarshalYAML(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *ExpressionOrList
|
||||
output []byte
|
||||
err error
|
||||
input *ExpressionOrList
|
||||
name string
|
||||
output []byte
|
||||
}{
|
||||
{
|
||||
name: "single expression",
|
||||
|
|
@ -217,8 +217,8 @@ func TestExpressionOrListUnmarshalJSON(t *testing.T) {
|
|||
func TestExpressionOrListString(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
in ExpressionOrList
|
||||
out string
|
||||
in ExpressionOrList
|
||||
}{
|
||||
{
|
||||
name: "single expression",
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import (
|
|||
|
||||
func TestGeoIPValid(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *GeoIP
|
||||
err error
|
||||
input *GeoIP
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "basic valid",
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import (
|
|||
|
||||
func TestImpressumValid(t *testing.T) {
|
||||
for _, cs := range []struct {
|
||||
name string
|
||||
inp Impressum
|
||||
err error
|
||||
inp Impressum
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "basic happy path",
|
||||
|
|
|
|||
|
|
@ -13,17 +13,17 @@ var (
|
|||
)
|
||||
|
||||
type openGraphFileConfig struct {
|
||||
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
|
||||
TimeToLive string `json:"ttl" yaml:"ttl"`
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
ConsiderHost bool `json:"considerHost" yaml:"enabled"`
|
||||
TimeToLive string `json:"ttl" yaml:"ttl"`
|
||||
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
|
||||
}
|
||||
|
||||
type OpenGraph struct {
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
ConsiderHost bool `json:"considerHost" yaml:"enabled"`
|
||||
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
|
||||
TimeToLive time.Duration `json:"ttl" yaml:"ttl"`
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
ConsiderHost bool `json:"considerHost" yaml:"enabled"`
|
||||
}
|
||||
|
||||
func (og *openGraphFileConfig) Valid() error {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import (
|
|||
|
||||
func TestOpenGraphFileConfigValid(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *openGraphFileConfig
|
||||
err error
|
||||
input *openGraphFileConfig
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "basic happy path",
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import (
|
|||
|
||||
func TestStoreValid(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
err error
|
||||
name string
|
||||
input config.Store
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "no backend",
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ var (
|
|||
)
|
||||
|
||||
type Threshold struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Expression *ExpressionOrList `json:"expression" yaml:"expression"`
|
||||
Action Rule `json:"action" yaml:"action"`
|
||||
Challenge *ChallengeRules `json:"challenge" yaml:"challenge"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Action Rule `json:"action" yaml:"action"`
|
||||
}
|
||||
|
||||
func (t Threshold) Valid() error {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
func TestThresholdValid(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
input *Threshold
|
||||
err error
|
||||
input *Threshold
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "basic allow",
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ func TestBotEnvironment(t *testing.T) {
|
|||
|
||||
t.Run("missingHeader", func(t *testing.T) {
|
||||
tests := []struct {
|
||||
headers map[string]string
|
||||
name string
|
||||
expression string
|
||||
headers map[string]string
|
||||
expected types.Bool
|
||||
description string
|
||||
expected types.Bool
|
||||
}{
|
||||
{
|
||||
name: "missing-header",
|
||||
|
|
@ -167,10 +167,10 @@ func TestBotEnvironment(t *testing.T) {
|
|||
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
env any
|
||||
name string
|
||||
description string
|
||||
expression string
|
||||
env any
|
||||
wantFailCompile bool
|
||||
wantFailEval bool
|
||||
}{
|
||||
|
|
@ -244,11 +244,11 @@ func TestThresholdEnvironment(t *testing.T) {
|
|||
}
|
||||
|
||||
tests := []struct {
|
||||
variables map[string]interface{}
|
||||
name string
|
||||
expression string
|
||||
variables map[string]interface{}
|
||||
expected types.Bool
|
||||
description string
|
||||
expected types.Bool
|
||||
shouldCompile bool
|
||||
}{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
)
|
||||
|
||||
type loadAvg struct {
|
||||
lock sync.RWMutex
|
||||
data *load.AvgStat
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
func (l *loadAvg) updateThread(ctx context.Context) {
|
||||
|
|
|
|||
|
|
@ -29,16 +29,15 @@ var (
|
|||
)
|
||||
|
||||
type ParsedConfig struct {
|
||||
orig *config.Config
|
||||
|
||||
Bots []Bot
|
||||
Thresholds []*Threshold
|
||||
DNSBL bool
|
||||
Store store.Interface
|
||||
orig *config.Config
|
||||
Impressum *config.Impressum
|
||||
OpenGraph config.OpenGraph
|
||||
DefaultDifficulty int
|
||||
Bots []Bot
|
||||
Thresholds []*Threshold
|
||||
StatusCodes config.StatusCodes
|
||||
Store store.Interface
|
||||
DefaultDifficulty int
|
||||
DNSBL bool
|
||||
}
|
||||
|
||||
func newParsedConfig(orig *config.Config) *ParsedConfig {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue