yaml

package
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopyYAML

func DeepCopyYAML(x yaml.MapSlice) yaml.MapSlice

DeepCopyYAML deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

func DeepCopyYAMLValue

func DeepCopyYAMLValue(x interface{}) interface{}

DeepCopyYAMLValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

func GuessJSONStream

func GuessJSONStream(r io.Reader, size int) (io.Reader, []byte, bool)

GuessJSONStream scans the provided reader up to size, looking for an open brace indicating this is JSON. It will return the bufio.Reader it creates for the consumer.

func IsJSONBuffer

func IsJSONBuffer(buf []byte) bool

IsJSONBuffer scans the provided buffer, looking for an open brace indicating this is JSON.

func NestedBool

func NestedBool(obj yaml.MapSlice, fields ...string) (bool, bool, error)

NestedBool returns the bool value of a nested field. Returns false if value is not found and an error if not a bool.

func NestedFieldCopy

func NestedFieldCopy(obj yaml.MapSlice, fields ...string) (interface{}, bool, error)

NestedFieldCopy returns a deep copy of the value of a nested field. Returns false if the value is missing. No error is returned for a nil field.

Note: fields passed to this function are treated as keys within the passed object; no array/slice syntax is supported.

func NestedFieldNoCopy

func NestedFieldNoCopy(obj yaml.MapSlice, fields ...string) (interface{}, bool, error)

NestedFieldNoCopy returns a reference to a nested field. Returns false if value is not found and an error if unable to traverse obj.

Note: fields passed to this function are treated as keys within the passed object; no array/slice syntax is supported.

func NestedFloat64

func NestedFloat64(obj yaml.MapSlice, fields ...string) (float64, bool, error)

NestedFloat64 returns the float64 value of a nested field. Returns false if value is not found and an error if not a float64.

func NestedInt64

func NestedInt64(obj yaml.MapSlice, fields ...string) (int64, bool, error)

NestedInt64 returns the int64 value of a nested field. Returns false if value is not found and an error if not an int64.

func NestedMap

func NestedMap(obj yaml.MapSlice, fields ...string) (yaml.MapSlice, bool, error)

NestedMap returns a deep copy of yaml.MapSlice value of a nested field. Returns false if value is not found and an error if not a yaml.MapSlice.

func NestedSlice

func NestedSlice(obj yaml.MapSlice, fields ...string) ([]interface{}, bool, error)

NestedSlice returns a deep copy of []interface{} value of a nested field. Returns false if value is not found and an error if not a []interface{}.

func NestedString

func NestedString(obj yaml.MapSlice, fields ...string) (string, bool, error)

NestedString returns the string value of a nested field. Returns false if value is not found and an error if not a string.

func NestedStringMap

func NestedStringMap(obj yaml.MapSlice, fields ...string) (map[string]string, bool, error)

NestedStringMap returns a copy of map[string]string value of a nested field. Returns false if value is not found and an error if not a yaml.MapSlice or contains non-string values in the map.

func NestedStringSlice

func NestedStringSlice(obj yaml.MapSlice, fields ...string) ([]string, bool, error)

NestedStringSlice returns a copy of []string value of a nested field. Returns false if value is not found and an error if not a []interface{} or contains non-string items in the slice.

func NewDocumentDecoder

func NewDocumentDecoder(r io.ReadCloser) io.ReadCloser

NewDocumentDecoder decodes YAML documents from the provided stream in chunks by converting each document (as defined by the YAML spec) into its own chunk. io.ErrShortBuffer will be returned if the entire buffer could not be read to assist the caller in framing the chunk.

func RemoveNestedField

func RemoveNestedField(obj *yaml.MapSlice, fields ...string)

RemoveNestedField removes the nested field from the obj.

func SetNestedField

func SetNestedField(obj *yaml.MapSlice, value interface{}, fields ...string) error

SetNestedField sets the value of a nested field to a deep copy of the value provided. Returns an error if value cannot be set because one of the nesting levels is not a yaml.MapSlice.

func SetNestedMap

func SetNestedMap(obj *yaml.MapSlice, value yaml.MapSlice, fields ...string) error

SetNestedMap sets the yaml.MapSlice value of a nested field. Returns an error if value cannot be set because one of the nesting levels is not a yaml.MapSlice.

func SetNestedSlice

func SetNestedSlice(obj *yaml.MapSlice, value []interface{}, fields ...string) error

SetNestedSlice sets the slice value of a nested field. Returns an error if value cannot be set because one of the nesting levels is not a yaml.MapSlice.

func SetNestedStringMap

func SetNestedStringMap(obj *yaml.MapSlice, value map[string]string, fields ...string) error

SetNestedStringMap sets the map[string]string value of a nested field. Returns an error if value cannot be set because one of the nesting levels is not a yaml.MapSlice.

func SetNestedStringSlice

func SetNestedStringSlice(obj *yaml.MapSlice, value []string, fields ...string) error

SetNestedStringSlice sets the string slice value of a nested field. Returns an error if value cannot be set because one of the nesting levels is not a yaml.MapSlice.

func ToJSON

func ToJSON(data []byte) ([]byte, error)

ToJSON converts a single YAML document into a JSON document or returns an error. If the document appears to be JSON the YAML decoding path is not used (so that error messages are JSON specific).

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals the given data If v is a *map[string]interface{}, *[]interface{}, or *interface{} numbers are converted to int64 or float64

Types

type JSONSyntaxError

type JSONSyntaxError struct {
	Offset int64
	Err    error
}

func (JSONSyntaxError) Error

func (e JSONSyntaxError) Error() string

type LineReader

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

func (*LineReader) Read

func (r *LineReader) Read() ([]byte, error)

Read returns a single line (with '\n' ended) from the underlying reader. An error is returned iff there is an error with the underlying reader.

type Reader

type Reader interface {
	Read() ([]byte, error)
}

type YAMLDecoder

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

YAMLDecoder reads chunks of objects and returns ErrShortBuffer if the data is not sufficient.

func (*YAMLDecoder) Close

func (d *YAMLDecoder) Close() error

func (*YAMLDecoder) Read

func (d *YAMLDecoder) Read(data []byte) (n int, err error)

Read reads the previous slice into the buffer, or attempts to read the next chunk. TODO: switch to readline approach.

type YAMLOrJSONDecoder

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

YAMLOrJSONDecoder attempts to decode a stream of JSON documents or YAML documents by sniffing for a leading { character.

func NewYAMLOrJSONDecoder

func NewYAMLOrJSONDecoder(r io.Reader, bufferSize int) *YAMLOrJSONDecoder

NewYAMLOrJSONDecoder returns a decoder that will process YAML documents or JSON documents from the given reader as a stream. bufferSize determines how far into the stream the decoder will look to figure out whether this is a JSON stream (has whitespace followed by an open brace).

func (*YAMLOrJSONDecoder) Decode

func (d *YAMLOrJSONDecoder) Decode(into interface{}) error

Decode unmarshals the next object from the underlying stream into the provide object, or returns an error.

type YAMLReader

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

func NewYAMLReader

func NewYAMLReader(r *bufio.Reader) *YAMLReader

func (*YAMLReader) Read

func (r *YAMLReader) Read() ([]byte, error)

Read returns a full YAML document.

type YAMLSyntaxError

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

func (YAMLSyntaxError) Error

func (e YAMLSyntaxError) Error() string

type YAMLToJSONDecoder

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

YAMLToJSONDecoder decodes YAML documents from an io.Reader by separating individual documents. It first converts the YAML body to JSON, then unmarshals the JSON.

func NewYAMLToJSONDecoder

func NewYAMLToJSONDecoder(r io.Reader) *YAMLToJSONDecoder

NewYAMLToJSONDecoder decodes YAML documents from the provided stream in chunks by converting each document (as defined by the YAML spec) into its own chunk, converting it to JSON via yaml.YAMLToJSON, and then passing it to json.Decoder.

func (*YAMLToJSONDecoder) Decode

func (d *YAMLToJSONDecoder) Decode(into interface{}) error

Decode reads a YAML document as JSON from the stream or returns an error. The decoding rules match json.Unmarshal, not yaml.Unmarshal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL