ytbx

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PreserveKeyOrderInJSON = false

PreserveKeyOrderInJSON specifies whether a special library is used to decode JSON input to preserve the order of keys in maps even though that is not part of the JSON specification.

Functions

func GetIdentifierFromNamedList

func GetIdentifierFromNamedList(list []interface{}) string

GetIdentifierFromNamedList returns the identifier key used in the provided list, or an empty string if there is none. The identifier key is either 'name', 'key', or 'id'.

func GetType

func GetType(value interface{}) string

GetType returns the type of the input value with a YAML specific view

func Grab

func Grab(obj interface{}, pathString string) (interface{}, error)

Grab get the value from the provided YAML tree using a path to traverse through the tree structure

func HumanReadableLocation

func HumanReadableLocation(location string) string

HumanReadableLocation returns a human readable location with proper coloring

func HumanReadableLocationInformation

func HumanReadableLocationInformation(inputFile InputFile) string

HumanReadableLocationInformation create a nicely decorated information about the provided input location. It will output the absolut path of the file (rather than the possibly relative location), or it will show the URL in the usual look-and-feel of URIs.

func IsComplexSlice

func IsComplexSlice(slice []interface{}) bool

IsComplexSlice returns whether the slice contains (hash)map entries, otherwise the slice is called a simple list.

func IsStdin

func IsStdin(location string) bool

IsStdin checks whether the provided input location refers to the dash character which usually serves as the replacement to point to STDIN rather than a file.

func LoadDocuments

func LoadDocuments(input []byte) ([]interface{}, error)

LoadDocuments reads the provided input data slice as a YAML, JSON, or TOML file with potential multiple documents. It only acts as a dispatcher and depending on the input will either use `LoadTOMLDocuments`, `LoadJSONDocuments`, or `LoadYAMLDocuments`.

func LoadFiles

func LoadFiles(locationA string, locationB string) (InputFile, InputFile, error)

LoadFiles concurrently loads two files from the provided locations

func LoadJSONDocuments

func LoadJSONDocuments(input []byte) ([]interface{}, error)

LoadJSONDocuments reads the provided input data slice as a YAML file with potential multiple documents. Each document in the JSON stream results in an entry of the result slice. This function performs two decoding passes over the input data slice, the first one to detect the respective types in use. And a second one to properly unmarshal the data in the most suitable Go types available. JSON does not support key orders in maps.

func LoadTOMLDocuments

func LoadTOMLDocuments(input []byte) ([]interface{}, error)

LoadTOMLDocuments reads the provided input data slice as a TOML file, which can only have one document. For the sake of having similar sounding functions and the same signatures, the function uses the plural in its name and returns a list of results even though it will only contain one entry. All map entries inside the result document are converted into YAML MapSlice types to make it compatible with the rest of the package.

func LoadYAMLDocuments

func LoadYAMLDocuments(input []byte) ([]interface{}, error)

LoadYAMLDocuments reads the provided input data slice as a YAML file with potential multiple documents. Each document in the YAML stream results in an entry of the result slice. This function performs two decoding passes over the input data slice, the first one to detect the respective types in use. And a second one to properly unmarshal the data in the most suitable Go types available so that key orders in hashes are preserved.

func SimplifyList

func SimplifyList(input []yaml.MapSlice) []interface{}

SimplifyList will cast a slice of YAML MapSlices into a slice of interfaces.

Types

type DecoderProxy

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

DecoderProxy can either be used with the standard JSON Decoder, or the specialised JSON library fork that supports preserving key order

func NewDecoderProxy

func NewDecoderProxy(keepOrder bool, r io.Reader) *DecoderProxy

NewDecoderProxy creates a new decoder proxy which either works in ordered mode or standard mode.

func (*DecoderProxy) Decode

func (d *DecoderProxy) Decode(v interface{}) error

Decode is a delegate function that calls JSON Decoder `Decode`

type InputFile

type InputFile struct {
	Location  string
	Note      string
	Documents []interface{}
}

InputFile represents the actual input file (either local, or fetched remotely) that needs to be processed. It can contain multiple documents, where a document is a map or a list of things.

func LoadFile

func LoadFile(location string) (InputFile, error)

LoadFile processes the provided input location to load it as one of the supported document formats, or plain text if nothing else works.

type InvalidPathString

type InvalidPathString struct {
	Style       PathStyle
	PathString  string
	Explanation string
}

InvalidPathString represents the error that a path string is not a valid Dot-style or GoPatch path syntax and does not match a provided document.

func (*InvalidPathString) Error

func (e *InvalidPathString) Error() string

type KeyNotFoundInMapError

type KeyNotFoundInMapError struct {
	MissingKey    string
	AvailableKeys []string
}

KeyNotFoundInMapError represents an error when a key in a map was expected, but could not be found.

func (*KeyNotFoundInMapError) Error

func (e *KeyNotFoundInMapError) Error() string

type NoNamedEntryListError

type NoNamedEntryListError struct {
}

NoNamedEntryListError represents the situation where a list was expected to be a named-entry list, but one or more entries were not maps.

func (*NoNamedEntryListError) Error

func (e *NoNamedEntryListError) Error() string

type Path

type Path struct {
	DocumentIdx  int
	PathElements []PathElement
}

Path points to a section in a data struture by using names to identify the location. Example:

---
sizing:
  api:
    count: 2

For example, `sizing.api.count` points to the key `sizing` of the root element and in there to the key `api` and so on and so forth.

func ListPaths

func ListPaths(location string, style PathStyle) ([]Path, error)

ListPaths returns all paths in the documents using the provided choice of path style.

func NewPathWithIndexedListElement

func NewPathWithIndexedListElement(path Path, idx int) Path

NewPathWithIndexedListElement returns a new path based on a given path adding a new of type list entry using the index.

func NewPathWithNamedElement

func NewPathWithNamedElement(path Path, name interface{}) Path

NewPathWithNamedElement returns a new path based on a given path adding a new of type entry in map using the name.

func NewPathWithNamedListElement

func NewPathWithNamedListElement(path Path, identifier interface{}, name interface{}) Path

NewPathWithNamedListElement returns a new path based on a given path adding a new of type entry in a named-entry list by using key and name.

func NewPathWithPathElement

func NewPathWithPathElement(path Path, pathElement PathElement) Path

NewPathWithPathElement returns a new path based on a given path adding a new path element.

func ParseDotStylePathString

func ParseDotStylePathString(path string, obj interface{}) (Path, error)

ParseDotStylePathString returns a path by parsing a string representation which is assumed to be a Dot-Style path.

func ParseGoPatchStylePathString

func ParseGoPatchStylePathString(path string) (Path, error)

ParseGoPatchStylePathString returns a path by parsing a string representation which is assumed to be a GoPatch style path.

func ParsePathString

func ParsePathString(pathString string, obj interface{}) (Path, error)

ParsePathString returns a path by parsing a string representation of a path, which can be one of the supported types.

func (Path) String

func (path Path) String() string

func (*Path) ToDotStyle

func (path *Path) ToDotStyle() string

ToDotStyle returns the path as a Dot-Style string.

func (*Path) ToGoPatchStyle

func (path *Path) ToGoPatchStyle() string

ToGoPatchStyle returns the path as a GoPatch style string.

type PathElement

type PathElement struct {
	Idx  int
	Key  string
	Name string
}

PathElement represents one part of a path, which can either address an entry in a map (by name), a named-entry list entry (key and name), or an entry in a list (by index).

type PathStyle

type PathStyle int

PathStyle is a custom type for supported path styles

const (
	DotStyle PathStyle = iota
	GoPatchStyle
)

Supported styles are the Dot-Style (used by Spruce for example) and GoPatch Style which is used by BOSH

Jump to

Keyboard shortcuts

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