yamlx

package
v2.14.7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(filename string, v any, options ...Option) error

Load is a shortcut function to read YAML data directly from a file.

func Marshal

func Marshal(in any) (out []byte, err error)

Marshal serializes the value provided into a YAML document. The structure of the generated document will reflect the structure of the value itself. Maps and pointers (to struct, string, int, etc.) are accepted as the in value.

See yaml.Marshal for detail docs.

func Unmarshal

func Unmarshal(in []byte, v any, options ...Option) error

Unmarshal decodes the first document found within the in byte slice and assigns decoded values into the out value.

Maps and pointers (to a struct, string, int, etc.) are accepted as out values. If an internal pointer within a struct is not initialized, the yaml package will initialize it if necessary for unmarshalling the provided data. The out parameter must not be nil.

See yaml.Unmarshal for detail docs.

Note that this package adds extra features on the standard YAML syntax, such as "reading environment variables", "file including", "reference using gjson JSON path expression", "reference using named variables", "function calling", etc.

Types

type FuncMap

type FuncMap map[string]any

FuncMap is the type of the map defining the mapping from names to functions. Each function must have either a single return value, or two return values of which the second is an error. In case the second return value evaluates to a non-nil error during execution, the execution terminates and the error will be returned.

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option customizes the behavior of the extended YAML parser.

func EnableEnv

func EnableEnv() Option

EnableEnv enables reading environment variables. By default, it is disabled for security considerations.

func EnableInclude

func EnableInclude() Option

EnableInclude enables including other files. By default, it is disabled for security considerations.

func WithFuncMap

func WithFuncMap(funcMap FuncMap) Option

WithFuncMap specifies additional functions to use with the "@@fn" directive.

func WithIncludeDirs

func WithIncludeDirs(dirs ...string) Option

WithIncludeDirs optionally specifies the directories to find include files. By default, the current working directory is used to search include files.

Jump to

Keyboard shortcuts

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