validator

package
v0.0.0-...-3483356 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnknownKey            = NewErrorCategory("unknown-key", LevelError)
	RequiredKey           = NewErrorCategory("required-key", LevelError)
	KeyConflict           = NewErrorCategory("key-conflict", LevelError)
	InvalidValue          = NewErrorCategory("invalid-value", LevelError)
	DeprecatedKey         = NewErrorCategory("deprecated-key", LevelWarning)
	UnsatisfiedDependency = NewErrorCategory("unsatisfied-dependency", LevelError)
	InvalidReference      = NewErrorCategory("invalid-reference", LevelError)
)

Functions

This section is empty.

Types

type Context

type Context struct {
	Options
	AllFields    model.FieldsMap
	AllUnitFiles []model.UnitFile
}

type ErrorCategory

type ErrorCategory struct {
	Name  string
	Level Level
}

func NewErrorCategory

func NewErrorCategory(name string, level Level) ErrorCategory

func (ErrorCategory) Err

func (c ErrorCategory) Err(validatorName string, group, key string, line, column int, message string) *ValidationError

func (ErrorCategory) ErrForField

func (c ErrorCategory) ErrForField(validatorName, errName string, field model.Field,
	line, column int, message string) *ValidationError

func (ErrorCategory) ErrSlice

func (c ErrorCategory) ErrSlice(validatorName, errName string,
	field model.Field, line, column int, message string) []ValidationError

func (ErrorCategory) ErrWithName

func (c ErrorCategory) ErrWithName(validatorName, errName, group, key string,
	line, column int, message string) *ValidationError

type Level

type Level string
const (
	LevelError   Level = "error"
	LevelWarning Level = "warning"
)

type Location

type Location struct {
	FilePath string
	Line     int
	Column   int
}

type Options

type Options struct {
	CheckReferences bool
}

type Rule

type Rule = func(validator Validator, unit model.UnitFile, field model.Field) []ValidationError

type ValidationError

type ValidationError struct {
	ErrorCategory
	Location
	Error         error
	ValidatorName string
	Group         string
	Key           string
	ErrorName     string
}

func (ValidationError) String

func (err ValidationError) String() string

type ValidationErrors

type ValidationErrors map[string][]ValidationError

func (ValidationErrors) AddError

func (errors ValidationErrors) AddError(filePath string, err ...ValidationError)

func (ValidationErrors) HasErrors

func (errors ValidationErrors) HasErrors() bool

func (ValidationErrors) Merge

func (ValidationErrors) WhereLevel

func (errors ValidationErrors) WhereLevel(level Level) []ValidationError

type Validator

type Validator interface {
	Name() string
	Context() Context
	Validate(unit model.UnitFile) []ValidationError
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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