validators

package
v0.2.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package validators provides zero-allocation OpenAPI validation for HAProxy models.

This package contains generated validators that work directly on client-native structs, avoiding the ~25GB allocation overhead of JSON marshal/unmarshal cycles that occurs when using the generic kin-openapi validator.

The validators are generated from OpenAPI specs in pkg/generated/dataplaneapi/ and support HAProxy versions 3.0, 3.1, 3.2, 3.3 (and enterprise variants). The generated code itself lives in pkg/generated/validators; this package wraps it with a version-dispatching ValidatorSet and a caching layer.

Usage:

cache := validators.NewCache()
validatorSet := validators.ForVersion(3, 2)

// Validate with caching
err := cache.ValidateServer(server, validatorSet)

// Or validate without caching
err := validatorSet.ValidateServer(server)

Index

Constants

View Source
const CacheSize = 65536

CacheSize is the maximum number of entries the validation cache holds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides an LRU cache for validation results. It uses content-based hashing to achieve high cache hit rates for template-driven configurations that produce repetitive models.

Thread-safe: hashicorp/golang-lru is internally synchronized, so a single cache needs no extra locking or sharding.

func NewCache

func NewCache() *Cache

NewCache creates a new validation cache.

func (*Cache) Add

func (c *Cache) Add(hash uint64, result error)

Add stores a validation result in the cache.

func (*Cache) Get

func (c *Cache) Get(hash uint64) (error, bool)

Get retrieves a cached validation result.

type CachedValidator

type CachedValidator struct {
	// contains filtered or unexported fields
}

CachedValidator provides cached validation for HAProxy models. It combines a Cache with a ValidatorSet to provide high-performance validation with content-based caching.

func NewCachedValidator

func NewCachedValidator(major, minor int) *CachedValidator

NewCachedValidator creates a new cached validator for a specific HAProxy version.

func (*CachedValidator) ValidateACL

func (c *CachedValidator) ValidateACL(m *models.ACL) error

ValidateACL validates an ACL with caching.

func (*CachedValidator) ValidateBackendSwitchingRule

func (c *CachedValidator) ValidateBackendSwitchingRule(m *models.BackendSwitchingRule) error

ValidateBackendSwitchingRule validates a BackendSwitchingRule with caching.

func (*CachedValidator) ValidateBind

func (c *CachedValidator) ValidateBind(m *models.Bind) error

ValidateBind validates a Bind with caching.

func (*CachedValidator) ValidateCapture

func (c *CachedValidator) ValidateCapture(m *models.Capture) error

ValidateCapture validates a Capture with caching.

func (*CachedValidator) ValidateFilter

func (c *CachedValidator) ValidateFilter(m *models.Filter) error

ValidateFilter validates a Filter with caching.

func (*CachedValidator) ValidateHTTPAfterResponseRule

func (c *CachedValidator) ValidateHTTPAfterResponseRule(m *models.HTTPAfterResponseRule) error

ValidateHTTPAfterResponseRule validates an HTTPAfterResponseRule with caching.

func (*CachedValidator) ValidateHTTPCheck

func (c *CachedValidator) ValidateHTTPCheck(m *models.HTTPCheck) error

ValidateHTTPCheck validates an HTTPCheck with caching.

func (*CachedValidator) ValidateHTTPErrorRule

func (c *CachedValidator) ValidateHTTPErrorRule(m *models.HTTPErrorRule) error

ValidateHTTPErrorRule validates an HTTPErrorRule with caching.

func (*CachedValidator) ValidateHTTPRequestRule

func (c *CachedValidator) ValidateHTTPRequestRule(m *models.HTTPRequestRule) error

ValidateHTTPRequestRule validates an HTTPRequestRule with caching.

func (*CachedValidator) ValidateHTTPResponseRule

func (c *CachedValidator) ValidateHTTPResponseRule(m *models.HTTPResponseRule) error

ValidateHTTPResponseRule validates an HTTPResponseRule with caching.

func (*CachedValidator) ValidateLogTarget

func (c *CachedValidator) ValidateLogTarget(m *models.LogTarget) error

ValidateLogTarget validates a LogTarget with caching.

func (*CachedValidator) ValidateServer

func (c *CachedValidator) ValidateServer(m *models.Server) error

ValidateServer validates a Server with caching.

func (*CachedValidator) ValidateServerSwitchingRule

func (c *CachedValidator) ValidateServerSwitchingRule(m *models.ServerSwitchingRule) error

ValidateServerSwitchingRule validates a ServerSwitchingRule with caching.

func (*CachedValidator) ValidateServerTemplate

func (c *CachedValidator) ValidateServerTemplate(m *models.ServerTemplate) error

ValidateServerTemplate validates a ServerTemplate with caching.

func (*CachedValidator) ValidateStickRule

func (c *CachedValidator) ValidateStickRule(m *models.StickRule) error

ValidateStickRule validates a StickRule with caching.

func (*CachedValidator) ValidateTCPCheck

func (c *CachedValidator) ValidateTCPCheck(m *models.TCPCheck) error

ValidateTCPCheck validates a TCPCheck with caching.

func (*CachedValidator) ValidateTCPRequestRule

func (c *CachedValidator) ValidateTCPRequestRule(m *models.TCPRequestRule) error

ValidateTCPRequestRule validates a TCPRequestRule with caching.

func (*CachedValidator) ValidateTCPResponseRule

func (c *CachedValidator) ValidateTCPResponseRule(m *models.TCPResponseRule) error

ValidateTCPResponseRule validates a TCPResponseRule with caching.

type FieldError

type FieldError = genvalidators.FieldError

FieldError represents an OpenAPI validation failure for a specific field.

Aliased from pkg/generated/validators so the public API of this package stays unchanged after the generated code was split into its own subpackage. Callers that construct or type-assert *validators.FieldError continue to work.

type ValidatorSet

type ValidatorSet struct {
	// contains filtered or unexported fields
}

ValidatorSet provides type-specific validation functions for a HAProxy version. Each method validates a model directly without JSON conversion.

func ForVersion

func ForVersion(major, minor int) *ValidatorSet

ForVersion returns the ValidatorSet for a specific HAProxy version. Returns v33 for 3.3+, v32 for 3.2, v31 for 3.1, v30 for 3.0 and below.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL