Documentation ¶
Index ¶
- Variables
- func DecodeAndValidate(r io.Reader, filename string, outPtr Validator) error
- func IsValidRegexGroupName(s String, fieldName string) error
- func NonEmptySlice[T any](pos *ConfigPos, s []T, fieldName string) error
- func NotZero[T comparable](pos *ConfigPos, t T, fieldName string) error
- func NotZeroModel[T comparable](pos *ConfigPos, x valWithPos[T], fieldName string) error
- func OneOf[T comparable](parentPos *ConfigPos, x valWithPos[T], allowed []T, fieldName string) error
- func UnmarshalPlain(n *yaml.Node, outPtr any, outPos *ConfigPos, extraYAMLFields ...string) error
- func ValidateEach[T Validator](s []T) error
- func ValidateUnlessNil(v Validator) error
- type Bool
- type ConfigPos
- type Int
- type String
- type Validator
- type ValidatorUpgrader
Constants ¶
This section is empty.
Variables ¶
var ErrLatestVersion = errors.New("this is the latest version")
ErrLatestVersion is a sentinel error returned from Upgrade() meaning that there is no further upgrading to be done because the current version is already the latest version.
Functions ¶
func DecodeAndValidate ¶
DecodeAndValidate unmarshals the YAML text in the given Reader into the given pointer-to-struct, and calls Validate() on it. Returns any unmarshaling error or validation error.
func IsValidRegexGroupName ¶
IsValidRegexGroupName returns whether the given string will be accepted by the regexp library as an RE2 group name.
func NonEmptySlice ¶
NonEmptySlice returns error if the given slice is empty.
func NotZero ¶
func NotZero[T comparable](pos *ConfigPos, t T, fieldName string) error
NotZero returns error if the given value is equal to the zero value for type T.
func NotZeroModel ¶
func NotZeroModel[T comparable](pos *ConfigPos, x valWithPos[T], fieldName string) error
NotZeroModel returns error if the given model's value is equal to the zero value for type T.
func OneOf ¶
func OneOf[T comparable](parentPos *ConfigPos, x valWithPos[T], allowed []T, fieldName string) error
OneOf returns error if x.Val is not one of the given allowed choices.
func UnmarshalPlain ¶
UnmarshalPlain unmarshals the yaml node n into the struct pointer outPtr, as if it did not have an UnmarshalYAML method. This lets you still use the default unmarshaling logic to populate the fields of your struct, while adding custom logic before and after.
outPtr must be a pointer to a struct which will be modified by this function.
pos will be modified by this function to contain the position of this yaml node within the input file.
The `yaml:"..."` tags of the outPtr struct are used to determine the set of valid fields. Unexpected fields in the yaml are treated as an error. To allow extra yaml fields that don't correspond to a field of outPtr, provide their names in extraYAMLFields. This allows some fields to be handled specially.
func ValidateEach ¶
ValidateEach calls Validate() on each element of the input and returns all errors encountered.
func ValidateUnlessNil ¶
ValidateUnlessNil is intended to be used in a model Validate() method. Semantically it means "if this model field is present (non-nil), then validate it. If not present, then skip validation." This is useful for polymorphic models like Step that have many possible child types, only one of which will be set.
Types ¶
type Bool ¶
type Bool = valWithPos[bool]
Bool represents a boolean field in a model, together with its location in the input file.
type ConfigPos ¶
ConfigPos stores the position of an config value so error messages post-validation can point to problems. The zero value means "position unknown or there is no position."
This is theoretically agnostic to input format; we could decide to support alternative serialization formats besides YAML in the future.
func YAMLPos ¶
func YAMLPos(n *yaml.Node) *ConfigPos
YAMLPos constructs a position struct based on a YAML parse cursor.
type Int ¶
type Int = valWithPos[int]
Int represents an integer field in a model, together with its location in the input file.
type String ¶
type String = valWithPos[string]
String represents a string field in a model, together with its location in the input file.
type Validator ¶
type Validator interface {
Validate() error
}
Validator is any model struct that has a validate method. It's useful for "higher order" validation functions like "validate each entry in a list".
type ValidatorUpgrader ¶ added in v0.2.0
type ValidatorUpgrader interface { Validator // Upgrade converts an old version of a YAML struct into newer version for // example, from api_version v1 to v2. If the struct is already the most // recent version, it returns (nil,LatestVersion). // // An error other than LatestVersion means that the model cannot be converted // because either: // // 1. something weird happened // 2. the YAML struct uses features in an old version that are not supported in newer // versions. Upgrade(context.Context) (ValidatorUpgrader, error) }
ValidatorUpgrader is the interface implemented by every kind of YAML struct (templates, golden tests, manifests, etc).