yaml

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package yaml provides an API for YAML serialization that can automatically infers types.

Index

Constants

This section is empty.

Variables

View Source
var (
	True           = []byte("true")
	False          = []byte("false")
	Null           = []byte("null")
	BoundaryMarker = []byte("---\n")
)
View Source
var (
	ErrEmptyInput  = errors.New("empty input")
	ErrInvalidRune = errors.New("invalid rune")
)

Functions

func Marshal

func Marshal(obj interface{}) ([]byte, error)

Marshal formats an object into a slice of bytes of YAML.

func Unmarshal

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

Unmarshal parses a slice of bytes into an object using a few simple type inference rules. This package is useful when your program needs to parse data, that you have no a priori awareness of its structure or type. If no input is given, then returns ErrEmptyInput. If the first rune is invalid, then returns ErrInvalidRune.

  • true => true (bool)
  • false => false (bool)
  • null => nil
  • [...] => []interface{}
  • -... => []interface{}
  • {...} => map[string]interface{}
  • "..." => string
  • otherwise trys to parse as float

func UnmarshalType

func UnmarshalType(b []byte, outputType reflect.Type) (interface{}, error)

UnmarshalType parses a slice of bytes into an object of a given type. If no input is given, then returns ErrEmptyInput. If the first rune in the slice of bytes is invalid, then returns ErrInvalidRune.

Types

type ErrInvalidKind

type ErrInvalidKind struct {
	Value    reflect.Type
	Expected []reflect.Kind
}

func (ErrInvalidKind) Error

func (e ErrInvalidKind) Error() string

Jump to

Keyboard shortcuts

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