Documentation
¶
Index ¶
- func DecodeAndValidate(r io.Reader, filename string, outPtr Validator) error
- func IsKnownAPIVersion(parentPos *ConfigPos, apiVersion String, fieldName string) 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 IsKnownAPIVersion ¶
IsKnownAPIVersion returns error if the given string is not one of the accepted abc schema versions.
parentPos is the position of the yaml object that contains the api_version field. We need this because if the api_version field is missing from the YAML, then we won't have any position information for it.
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.
Directories
¶
Path | Synopsis |
---|---|
Package model contains the structs for unmarshaled YAML files.
|
Package model contains the structs for unmarshaled YAML files. |