Documentation
¶
Overview ¶
Package formschema is the form-shaped half of every settings section: a schema of typed fields, the decoder that reads a section's YAML node by that schema, and the marks that tell the settings document which scalars are safe to show.
Index ¶
- Constants
- func MarkPlain(n *yaml.Node)
- type Field
- type FieldError
- type Kind
- type Schema
- type Value
- type Values
- func (vs Values) Bool(key string) (value, ok bool)
- func (vs Values) Duration(key string) (time.Duration, bool)
- func (vs Values) Int(key string) (int64, bool)
- func (vs Values) Secret(key string) (string, bool)
- func (vs Values) String(key string) (string, bool)
- func (vs Values) StringList(key string) ([]string, bool)
Constants ¶
const ( PlainTag = "!plain" UnchangedTag = "!unchanged" )
PlainTag marks a value a schema decoded as safe to show; UnchangedTag is what a read shows and a Save sends in place of a value kept as stored.
Variables ¶
This section is empty.
Functions ¶
func MarkPlain ¶
MarkPlain retags n, and every scalar beneath it, PlainTag. A section owner calls it for each non-Secret scalar it accepts without Decode, after reading the values: yaml.v3's node.Decode refuses a !plain scalar as a bool or int. It never follows an alias. A sequence element holding a Secret field must carry an id key, so a Save can match it to its stored secret.
Types ¶
type Field ¶
type Field struct {
Key, Label, Help string
// Default is the value Decode applies when the key is absent, in the
// key's own YAML spelling; "" means no default.
Default string
// Enum lists an Enum field's accepted values.
Enum []string
// Min and Max bound an Int, or a DurationMs in milliseconds, inclusively.
// Set both, with Min <= Max, or neither: both zero leave it unbounded,
// and one alone bounds the other side at zero.
Min, Max int64
Kind Kind
// Required refuses an absent key, and for String and Secret an empty one.
Required bool
}
Field is one key of a section.
type FieldError ¶
type FieldError struct{ Path, Message string }
FieldError is one refused value: Path is relative to the node Decode was given until Prefix makes it absolute.
func Prefix ¶
func Prefix(prefix string, errs []FieldError) []FieldError
Prefix returns errs with each path made absolute under prefix: a path starting with an index joins without a dot, and an empty path is prefix.
type Kind ¶
type Kind uint8
Kind is how a field's scalar text is read.
The kinds a Field's text is read as; the zero Kind is none of them.
func (Kind) MarshalText ¶
MarshalText answers the kind's snake_case name and refuses the zero Kind.
func (*Kind) UnmarshalText ¶
UnmarshalText reads a snake_case kind name, refusing every other spelling.
type Schema ¶
type Schema struct{ Fields []Field }
Schema is a section's flat fields, in form order.
func (Schema) Decode ¶
func (s Schema) Decode(n *yaml.Node) (Values, []FieldError)
Decode reads n, a section's mapping (nil when the section is absent), by the schema. Every scalar is read from its text by its field's Kind, whatever its YAML tag, and a null is absent. Unknown and repeated keys, anchors and aliases, and values failing their field's rules are field errors at section-relative paths. Each scalar it reads for a non-Secret field is retagged PlainTag in n, whatever errors other fields have.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is one decoded field.
type Values ¶
Values holds a section's decoded fields by key, defaults included; an absent key without a default has no entry.