validator

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package validator provides struct validation utilities with custom validators.

Package validator provides struct validation utilities with custom validators.

Package validator provides struct validation utilities with custom validators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateJSON

func ValidateJSON(data []byte) (map[string]any, error)

ValidateJSON validates that the input is valid JSON and returns properties map.

Types

type PropertiesValidator

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

PropertiesValidator validates asset properties based on asset type.

func NewPropertiesValidator

func NewPropertiesValidator() *PropertiesValidator

NewPropertiesValidator creates a new properties validator with default limits.

func (*PropertiesValidator) ValidateProperties

func (v *PropertiesValidator) ValidateProperties(assetType string, properties map[string]any) PropertyErrors

ValidateProperties validates properties based on asset type.

type PropertyError

type PropertyError struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

PropertyError represents a property validation error.

type PropertyErrors

type PropertyErrors []PropertyError

PropertyErrors is a collection of property validation errors.

func (PropertyErrors) Error

func (e PropertyErrors) Error() string

Error implements the error interface.

type TargetType

type TargetType string

TargetType represents the type of scan target.

const (
	TargetTypeDomain   TargetType = "domain"
	TargetTypeIPv4     TargetType = "ipv4"
	TargetTypeIPv6     TargetType = "ipv6"
	TargetTypeCIDR     TargetType = "cidr"
	TargetTypeURL      TargetType = "url"
	TargetTypeHostPort TargetType = "host_port"
	TargetTypeUnknown  TargetType = "unknown"
)

type TargetValidationResult

type TargetValidationResult struct {
	Valid      []ValidatedTarget `json:"valid"`
	Invalid    []ValidatedTarget `json:"invalid"`
	TotalCount int               `json:"total_count"`
	ValidCount int               `json:"valid_count"`
	HasErrors  bool              `json:"has_errors"`
	BlockedIPs []string          `json:"blocked_ips,omitempty"`
}

TargetValidationResult contains the results of validating multiple targets.

func (*TargetValidationResult) GetTargetsByType

func (r *TargetValidationResult) GetTargetsByType(targetType TargetType) []ValidatedTarget

GetTargetsByType returns targets filtered by type.

func (*TargetValidationResult) GetValidTargetStrings

func (r *TargetValidationResult) GetValidTargetStrings() []string

GetValidTargetStrings returns only the valid target strings.

type TargetValidator

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

TargetValidator validates and classifies scan targets.

func NewTargetValidator

func NewTargetValidator(opts ...TargetValidatorOption) *TargetValidator

NewTargetValidator creates a new TargetValidator with options.

func (*TargetValidator) ValidateSingleTarget

func (v *TargetValidator) ValidateSingleTarget(target string) ValidatedTarget

ValidateSingleTarget validates and classifies a single target.

func (*TargetValidator) ValidateTargets

func (v *TargetValidator) ValidateTargets(targets []string) *TargetValidationResult

ValidateTargets validates a list of targets and returns classified results.

type TargetValidatorOption

type TargetValidatorOption func(*TargetValidator)

TargetValidatorOption is a functional option for TargetValidator.

func WithAllowInternalIPs

func WithAllowInternalIPs(allow bool) TargetValidatorOption

WithAllowInternalIPs allows internal IP addresses (10.x, 172.16.x, 192.168.x).

func WithAllowLocalhost

func WithAllowLocalhost(allow bool) TargetValidatorOption

WithAllowLocalhost allows localhost addresses.

func WithMaxTargets

func WithMaxTargets(max int) TargetValidatorOption

WithMaxTargets sets the maximum number of targets allowed.

type ValidatedTarget

type ValidatedTarget struct {
	Original string     `json:"original"`
	Type     TargetType `json:"type"`
	Value    string     `json:"value"`
	Port     int        `json:"port,omitempty"`
	IsValid  bool       `json:"is_valid"`
	Error    string     `json:"error,omitempty"`
}

ValidatedTarget represents a validated and classified target.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError represents a single field validation error.

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of validation errors.

func (ValidationErrors) Error

func (v ValidationErrors) Error() string

Error implements the error interface.

type Validator

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

Validator wraps the go-playground validator with custom validations.

func New

func New() *Validator

New creates a new Validator with custom validators registered.

func (*Validator) Validate

func (v *Validator) Validate(s interface{}) error

Validate validates a struct and returns ValidationErrors if validation fails.

Jump to

Keyboard shortcuts

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