Documentation ¶
Overview ¶
Package rivertags decodes a struct type into river object and structural tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct { Name []string // Name of tagged field. Index []int // Index into field. Use [reflectutil.GetOrAlloc] to retrieve a Value. Flags Flags // Flags assigned to field. }
Field is a tagged field within a struct.
func Get ¶
Get returns the list of tagged fields for some struct type ty. Get panics if ty is not a struct type.
Get examines each tagged field in ty for a river key. The river key is then parsed as containing a name for the field, followed by a required comma-separated list of options. The name may be empty for fields which do not require a name. Get will ignore any field that is not tagged with a river key.
Get will treat anonymous struct fields as if the inner fields were fields in the outer struct.
Examples of struct field tags and their meanings:
// Field is used as a required block named "my_block". Field struct{} `river:"my_block,block"` // Field is used as an optional block named "my_block". Field struct{} `river:"my_block,block,optional"` // Field is used as a required attribute named "my_attr". Field string `river:"my_attr,attr"` // Field is used as an optional attribute named "my_attr". Field string `river:"my_attr,attr,optional"` // Field is used for storing the label of the block which the struct // represents. Field string `river:",label"` // Attributes and blocks inside of Field are exposed as top-level fields. Field struct{} `river:",squash"` Blocks []struct{} `river:"my_block_prefix,enum"`
With the exception of the `river:",label"` and `river:",squash" tags, all tagged fields must have a unique name.
The type of tagged fields may be any Go type, with the exception of `river:",label"` tags, which must be strings.
func (Field) IsEnum ¶ added in v0.32.0
IsEnum returns whether f represents an enum of blocks, where only one block is set at a time.
func (Field) IsOptional ¶
IsOptional returns whether f is optional.
type Flags ¶
type Flags uint
Flags is a bitmap of flags associated with a field on a struct.
const ( FlagAttr Flags = 1 << iota // FlagAttr treats a field as attribute FlagBlock // FlagBlock treats a field as a block FlagEnum // FlagEnum treats a field as an enum of blocks FlagOptional // FlagOptional marks a field optional for decoding/encoding FlagLabel // FlagLabel will store block labels in the field FlagSquash // FlagSquash will expose inner fields from a struct as outer fields. )
Valid flags.