xyml

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TagBinary    = "tag:yaml.org,2002:binary"
	TagBool      = "tag:yaml.org,2002:bool"
	TagFloat     = "tag:yaml.org,2002:float"
	TagInt       = "tag:yaml.org,2002:int"
	TagMerge     = "tag:yaml.org,2002:merge"
	TagNil       = "tag:yaml.org,2002:null"
	TagString    = "tag:yaml.org,2002:str"
	TagTimestamp = "tag:yaml.org,2002:timestamp"
	TagValue     = "tag:yaml.org,2002:value"
	TagYaml      = "tag:yaml.org,2002:yaml"

	TagMap        = "tag:yaml.org,2002:map"
	TagOrderedMap = "tag:yaml.org,2002:omap"
	TagPairs      = "tag:yaml.org,2002:pairs"
	TagSet        = "tag:yaml.org,2002:set"
	TagSequence   = "tag:yaml.org,2002:seq"
)

YAML type tags.

Variables

This section is empty.

Functions

func IsBinary

func IsBinary(y *yaml.Node) bool

IsBinary returns whether the given YAML node is a binary node.

func IsBool

func IsBool(y *yaml.Node) bool

IsBool returns whether the given YAML node is a boolean node.

func IsFloat

func IsFloat(y *yaml.Node) bool

IsFloat returns whether the given YAML node is a float node.

func IsInt

func IsInt(y *yaml.Node) bool

IsInt returns whether the given YAML node is an int node.

func IsMap

func IsMap(y *yaml.Node) bool

IsMap returns whether the given YAML node is a map node.

func IsNilType

func IsNilType(y *yaml.Node) bool

IsNilType returns whether the given YAML node is a nil typed node.

func IsOrderedMap

func IsOrderedMap(y *yaml.Node) bool

IsOrderedMap returns whether the given YAML node is an ordered map node.

func IsPairs

func IsPairs(y *yaml.Node) bool

IsPairs returns whether the given YAML node is a pairs node.

func IsScalar

func IsScalar(y *yaml.Node) bool

IsScalar returns whether the given YAML node is a scalar type.

func IsSequence

func IsSequence(y *yaml.Node) bool

IsSequence returns whether the given YAML node is a sequence node.

func IsString

func IsString(y *yaml.Node) bool

IsString returns whether the given YAML node is a string node.

func IsTimestamp

func IsTimestamp(y *yaml.Node) bool

IsTimestamp returns whether the given YAML node is a timestamp node.

func MapAppend

func MapAppend(y *yaml.Node, k, v interface{}) error

MapAppend converts the given key/value args (k, v) to YAML nodes then appends them to the given map node (y).

func MapAppendNode

func MapAppendNode(y, k, v *yaml.Node) error

MapAppendNode appends the given key/value nodes (k, v) to the given map node (y).

func MapForEach

func MapForEach(y *yaml.Node, fn func(k, v *yaml.Node) error) error

MapForEach calls the given function for each key/value pair in the given YAML map node.

Returns an error if the given YAML node is not a map type, or if the passed function itself returns an error.

func MapToYamlNode

func MapToYamlNode(val interface{}) (*yaml.Node, error)

MapToYamlNode converts the given map to a YAML node.

Returns an error if the given value is not a map, if the map key type is not a scalar value, or if the map contains a value which cannot be automatically converted to a YAML node (such as a struct value).

func NewBinaryNode

func NewBinaryNode(v []byte) *yaml.Node

NewBinaryNode returns a new binary typed YAML node with the given content.

func NewBoolNode

func NewBoolNode(v bool) *yaml.Node

NewBoolNode returns a new boolean typed YAML node with the given value.

func NewFloatNode

func NewFloatNode(val float64, rep byte, prec int) *yaml.Node

NewFloatNode returns a new float typed YAML node with the given value.

func NewIntNode

func NewIntNode(val int64, base int) *yaml.Node

NewIntNode returns a new int typed YAML node with the given value.

func NewMapNode

func NewMapNode(size int) *yaml.Node

NewMapNode returns a new mapping typed YAML node presized to the given size.

func NewNullNode

func NewNullNode() *yaml.Node

NewNullNode returns a new null typed YAML node.

func NewOrderedMapNode

func NewOrderedMapNode(size int) *yaml.Node

NewOrderedMapNode returns a new ordered map typed YAML node presized to the given size.

func NewPairsNode

func NewPairsNode(size int) *yaml.Node

NewPairsNode returns a new pairs typed YAML node presized to the given size.

func NewSequenceNode

func NewSequenceNode(size int) *yaml.Node

NewSequenceNode returns a new sequence typed YAML node presized to the given size.

func NewSetNode

func NewSetNode(size int) *yaml.Node

NewSetNode returns a new set typed YAML node presized to the given size.

func NewStringNode

func NewStringNode(v string) *yaml.Node

NewStringNode returns a new string typed YAML node with the given value.

func NewTimestampNode

func NewTimestampNode(v time.Time) *yaml.Node

NewTimestampNode returns a new timestamp typed YAML node with the given value.

func RequireBinary

func RequireBinary(y *yaml.Node) error

RequireBinary returns an error if the given node is not of type binary.

func RequireBool

func RequireBool(y *yaml.Node) error

RequireBool returns an error if the given node is not of type bool.

func RequireFloat

func RequireFloat(y *yaml.Node) error

RequireFloat returns an error if the given node is not of type float.

func RequireInt

func RequireInt(y *yaml.Node) error

RequireInt returns an error if the given node is not of type int.

func RequireMap

func RequireMap(y *yaml.Node) error

RequireMap returns an error if the given node is not a mapping node.

func RequireNilType

func RequireNilType(y *yaml.Node) error

RequireNilType returns an error if the given node is not of type null.

func RequireOrderedMap

func RequireOrderedMap(y *yaml.Node) error

RequireOrderedMap returns an error if the given node is not of type omap.

func RequirePairs

func RequirePairs(y *yaml.Node) error

RequirePairs returns an error if the given node is not of type pairs.

func RequireScalar

func RequireScalar(y *yaml.Node) error

RequireScalar returns an error if the given node is not a scalar node.

func RequireSequence

func RequireSequence(y *yaml.Node) error

RequireSequence returns an error if the given node is not a sequence node.

func RequireString

func RequireString(y *yaml.Node) error

RequireString returns an error if the given node is not of type string.

func RequireTimestamp

func RequireTimestamp(y *yaml.Node) error

RequireTimestamp returns an error if the given node is not of type timestamp.

func ScalarToYamlNode

func ScalarToYamlNode(val interface{}) (*yaml.Node, error)

ScalarToYamlNode converts the given scalar node to a YAML node.

Returns an error if the given value cannot be converted to a YAML scalar node.

func SequenceAppend

func SequenceAppend(y *yaml.Node, v interface{}) error

SequenceAppend converts the given value (v) to a YAML node, then appends it to the given list node (y).

func SequenceAppendNode

func SequenceAppendNode(y, v *yaml.Node) error

SequenceAppendNode appends the given YAML node value to the given sequence node.

func SequenceForEach

func SequenceForEach(y *yaml.Node, fn func(v *yaml.Node) error) error

SequenceForEach calls the given function for each value in the given YAML sequence node.

Returns an error if the given YAML node is not a sequence type, or if the passed function itself returns an error.

func SliceToYamlNode

func SliceToYamlNode(val interface{}) (*yaml.Node, error)

SliceToYamlNode converts the given slice or array value into a YAML sequence.

Returns an error if the given value is not an array or slice, or if the array/slice contains a value that cannot be automatically converted to a YAML node (such as a struct value).

func ToBinary

func ToBinary(y *yaml.Node) ([]byte, error)

ToBinary attempts to parse the given node as a base64 encoded binary value.

func ToBoolean

func ToBoolean(y *yaml.Node) (bool, error)

ToBoolean attempts to parse the given node as a boolean value.

func ToFloat

func ToFloat(y *yaml.Node) (float64, error)

ToFloat attempts to parse the given node as a float value.

func ToInt

func ToInt(y *yaml.Node, base int) (int64, error)

ToInt attempts to parse the given node as a int value.

func ToScalarValue

func ToScalarValue(y *yaml.Node) (interface{}, error)

ToScalarValue attempts to parse the given YAML node into a scalar value.

Handles types:

!!binary
!!bool
!!float
!!int
!!null
!!str
!!timestamp

func ToString

func ToString(y *yaml.Node) (string, error)

ToString attempts to parse the given YAML node as a string.

func ToTime

func ToTime(y *yaml.Node, format string) (time.Time, error)

ToTime attempts to parse the given YAML node as a timestamp using the given format.

func ToTime3339Nano

func ToTime3339Nano(y *yaml.Node) (time.Time, error)

ToTime3339Nano calls ToTime with the RFC3339Nano time format.

func ToYamlNode

func ToYamlNode(val interface{}) (*yaml.Node, error)

ToYamlNode converts arbitrary typed data to a YAML node.

Note: This method is a shorthand call for all 3 of ScalarToYamlNode, SliceToYamlNode, and MapToYamlNode. As such it follows the same rules and cannot handle user defined types such as structs.

Types

type Marshaler

type Marshaler interface {
	// ToYAML provides a way to convert non-builtin types to YAML nodes using the
	// utilities in the xyml package.
	ToYAML() (*yaml.Node, error)
}

Marshaler provides a way for xyml's YAML utilities to convert custom types into YAML nodes suitable for use with go-yaml v3.

Jump to

Keyboard shortcuts

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