candiedyaml

package module
v0.0.0-...-a41693b Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: Apache-2.0 Imports: 16 Imported by: 479

README

GoDoc

candiedyaml


DEPRECATION NOTICE

The candiedyaml library is no longer under active development and will soon be moved to the cloudfoundry-attic GitHub organization. We recommend the use of an alternative library such as gopkg.in/yaml.v2 instead.


YAML for Go

A YAML 1.1 parser with support for YAML 1.2 features

Usage

package myApp

import (
  "github.com/cloudfoundry-incubator/candiedyaml"
  "fmt"
  "os"
)

func main() {
  file, err := os.Open("path/to/some/file.yml")
  if err != nil {
    println("File does not exist:", err.Error())
    os.Exit(1)
  }
  defer file.Close()

  document := new(interface{})
  decoder := candiedyaml.NewDecoder(file)
  err = decoder.Decode(document)
  
  if err != nil {
    println("Failed to decode document:", err.Error())
  }
  
  println("parsed yml into interface:", fmt.Sprintf("%#v", document))
  
  fileToWrite, err := os.Create("path/to/some/new/file.yml")
  if err != nil {
    println("Failed to open file for writing:", err.Error())
    os.Exit(1)
  }
  defer fileToWrite.Close()

  encoder := candiedyaml.NewEncoder(fileToWrite)
  err = encoder.Encode(document)

  if err != nil {
    println("Failed to encode document:", err.Error())
    os.Exit(1)
  }
  
  return
}

Documentation

Index

Constants

View Source
const (
	BOM_UTF8    = "\xef\xbb\xbf"
	BOM_UTF16LE = "\xff\xfe"
	BOM_UTF16BE = "\xfe\xff"
)

* Byte order marks.

View Source
const (
	INPUT_RAW_BUFFER_SIZE = 1024

	/*
	 * The size of the input buffer.
	 *
	 * It should be possible to decode the whole raw buffer.
	 */
	INPUT_BUFFER_SIZE = (INPUT_RAW_BUFFER_SIZE * 3)

	OUTPUT_BUFFER_SIZE = 512

	OUTPUT_RAW_BUFFER_SIZE = (OUTPUT_BUFFER_SIZE*2 + 2)

	INITIAL_STACK_SIZE = 16
	INITIAL_QUEUE_SIZE = 16
)
View Source
const MAX_NUMBER_LENGTH = 9

Variables

This section is empty.

Functions

func Marshal

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

func Run_parser

func Run_parser(cmd string, args []string)

func Unmarshal

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

Types

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) (err error)

func (*Decoder) UseNumber

func (d *Decoder) UseNumber()

type Encoder

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

An Encoder writes JSON objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

type Marshaler

type Marshaler interface {
	MarshalYAML() (tag string, value interface{}, err error)
}

type Number

type Number string

A Number represents a JSON number literal.

func (Number) Float64

func (n Number) Float64() (float64, error)

Float64 returns the number as a float64.

func (Number) Int64

func (n Number) Int64() (int64, error)

Int64 returns the number as an int64.

func (Number) String

func (n Number) String() string

String returns the literal text of the number.

type ParserError

type ParserError struct {
	ErrorType   YAML_error_type_t
	Context     string
	ContextMark YAML_mark_t
	Problem     string
	ProblemMark YAML_mark_t
}

func (*ParserError) Error

func (e *ParserError) Error() string

type UnexpectedEventError

type UnexpectedEventError struct {
	Value     string
	EventType yaml_event_type_t
	At        YAML_mark_t
}

func (*UnexpectedEventError) Error

func (e *UnexpectedEventError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalYAML(tag string, value interface{}) error
}

type YAML_error_type_t

type YAML_error_type_t int

* Many bad things could happen with the parser and emitter.

type YAML_mark_t

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

* The pointer position.

func (YAML_mark_t) String

func (m YAML_mark_t) String() string

Jump to

Keyboard shortcuts

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