rivertags

package
v0.27.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

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 (reflect.Value.FieldByIndex)
	Flags Flags    // Flags assigned to field
}

Field is a tagged field within a struct.

func Get

func Get(ty reflect.Type) []Field

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"`

With the exception of the `river:",label"` tag, 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) IsAttr

func (f Field) IsAttr() bool

IsAttr returns whether f is for an attribute.

func (Field) IsBlock

func (f Field) IsBlock() bool

IsBlock returns whether f is for a block.

func (Field) IsOptional

func (f Field) IsOptional() bool

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

	FlagOptional // FlagOptional marks a field optional for decoding/encoding
	FlagLabel    // FlagLabel will store block labels in the field
)

Valid flags.

func (Flags) GoString

func (f Flags) GoString() string

GoString returns the %#v format of Flags.

func (Flags) String

func (f Flags) String() string

String returns the flags as a string.

Jump to

Keyboard shortcuts

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