yamlpack

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TemplateFunc

type TemplateFunc func([]byte, interface{}) ([]byte, error)

TemplateFunc is processed with RenderWithTemplateFunc

type Viper

type Viper viper.Viper

Viper is an alias of viper.Viper (github.com/spf13/viper)

type YamlPack

type YamlPack interface {
	AllSections() []*YamlSection
	ListYamls() []string
	GetString(string) string
	GetStringSlice(string) []string
	GetBool(string) bool
	Sub(string) *viper.Viper
}

YamlPack provides a set of functionality to process composite yaml documents

type YamlSection

type YamlSection struct {
	Bytes         []byte
	OriginalBytes []byte // Pre-template functions
	Viper         *viper.Viper
	TemplateFunc  TemplateFunc
}

YamlFile stores raw file bytes and Viper struct

func Filter

func Filter(in []*YamlSection, filters []string) ([]*YamlSection, error)

Filter removes *YamlSections from a list based on text filters

func (*YamlSection) AllSettings

func (section *YamlSection) AllSettings() (ret map[string]interface{}, err error)

AllSettings returns a value map derived from the *YamlSection data

func (*YamlSection) GetBool

func (section *YamlSection) GetBool(identifier string) bool

GetBool returns a boolean value from a doted notation key

func (*YamlSection) GetString

func (section *YamlSection) GetString(identifier string) string

GetString returns a string value from a doted notation key

func (*YamlSection) GetStringSlice

func (section *YamlSection) GetStringSlice(identifier string) []string

GetStringSlice returns a string slice from a doted notation key

func (*YamlSection) Render

func (section *YamlSection) Render(vals interface{}) error

Render applies the sections configured template with the provided values

func (*YamlSection) RenderWithTemplateFunc

func (section *YamlSection) RenderWithTemplateFunc(tmplFunc TemplateFunc, vals interface{}) error

Render applies the provided template function to the *YamlSection with the provided values

func (*YamlSection) String

func (ys *YamlSection) String() string

String returns the sections processed data as a string

func (*YamlSection) Sub

func (section *YamlSection) Sub(identifier string) (*YamlSection, error)

Sub returns a *YamlSection instance from a yaml key identified by doted notation

func (*YamlSection) Unmarshal

func (section *YamlSection) Unmarshal(entry interface{}) (err error)

Unmarshal processes *YamlSection data into the provided data structure Missing values or destination structure elements are ignored

func (*YamlSection) UnmarshalStrict

func (section *YamlSection) UnmarshalStrict(entry interface{}) (err error)

UnmarshalStrict processes *YamlSection data into the provided data structure This is the strict version which has DisallowUnknownFields enabled

func (*YamlSection) Yaml

func (ys *YamlSection) Yaml() (string, error)

Yaml returns the "data" value as a string DEPRECATED: this is used only in yaml2vars and will be removed in the future

type Yp

type Yp struct {
	sync.RWMutex
	Files               map[string][]*YamlSection
	Handlers            map[string]func(string) error
	DefaultTemplateFunc TemplateFunc
}

Yp is a yamlpack instance

func New

func New() *Yp

New returns a newly created and initialized *Yp

func (*Yp) AllSections

func (yp *Yp) AllSections() []*YamlSection

AllSections returns an array containing all yaml sections

func (*Yp) ApplyDefaultTemplate

func (yp *Yp) ApplyDefaultTemplate(name string, vals interface{}) error

ApplyDefaultTemplate runs the default template function but only errors on parse failures

func (*Yp) ApplyDefaultTemplateStrict

func (yp *Yp) ApplyDefaultTemplateStrict(name string, vals interface{}) error

ApplyDefaultTemplateStrict runs the default template function and errors on any failure such as missing data

func (*Yp) ApplyFilters

func (yp *Yp) ApplyFilters(s string, filters []string) error

ApplyFilters removes *YamlSections from a yamlpack instance based on text filter data

func (*Yp) ApplyTemplate

func (yp *Yp) ApplyTemplate(name string, tmplFunc TemplateFunc, vals interface{}) error

ApplyTemplate executes RenderWithTemplateFunc on every section in a yamlpack instance

func (*Yp) DeregisterHandler

func (yp *Yp) DeregisterHandler(name string)

DeregisterHandler removed a previously registered handler if it exists

func (*Yp) Import

func (yp *Yp) Import(s string, r io.Reader) error

Import takes a location identifier (URI, file path, etc..) and an io.Reader imported data is added to the yamlPack instance

func (*Yp) ImportFile

func (yp *Yp) ImportFile(s string) error

Import reads data from a single YAML file and adds its data to this *Yp instance

func (*Yp) ImportWithTemplateFuncAndFilters

func (yp *Yp) ImportWithTemplateFuncAndFilters(identifier string, r io.Reader, tf TemplateFunc, filters []string) error

ImportWithTemplateFuncAndFilters offers a way to import yaml from an io.Reader, applies a template, and filters sections based on a string array

func (*Yp) ListYamls

func (yp *Yp) ListYamls() []string

ListYamls returns a list of yaml section names as defined by metadata.name

func (*Yp) RegisterHandler

func (yp *Yp) RegisterHandler(name string, f func(string) error) error

RegisterHandler adds a handler to this instance

func (*Yp) YamlParse

func (yp *Yp) YamlParse(name string) error

YamlParse adds viper instances to imported file sections

Jump to

Keyboard shortcuts

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