candiedyaml

package
v0.0.0-...-db1d7af Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2014 License: Apache-2.0 Imports: 17 Imported by: 0

README

candiedyaml

YAML for Go

Usage

package myApp

import (
  "github.com/fraenkel/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) }

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) }

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 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)

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 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 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.

Jump to

Keyboard shortcuts

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