Differences between revisions 5 and 6
Revision 5 as of 2011-02-06 23:45:46
Size: 3035
Editor: niemeyer
Revision 6 as of 2011-02-18 08:37:37
Size: 3049
Editor: niemeyer
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
    http://goneat.org/pkg/goyaml     http://goneat.org/pkg/launchpad.net/goyaml

What is it?

The goyaml package enables Go programs to very comfortably encode and decode YAML values.

It was developed within Canonical as part of an experiment related to using the Go language with the Ensemble project.

goyaml internally uses the C libyaml library to parse and generate YAML data fast and reliably. It ships with all the necessary files, though, and has no external dependencies besides Go itself.


goyaml is almost compatible with YAML 1.1, including support for anchors, tags, etc. There are still a few missing bits, such as document merging, base-60 floats (WTF), and multi-document unmarshalling. These features are not hard to add, and will be introduced as necessary.

API documentation

The API documentation is currently available at:


Here is a simple example which connects to ZooKeeper, waits for the session to be established, and attempts to create a node:

package main

import (

var data = `
a: Easy!
  c: 2
  d: [3, 4]

type T struct {
    A string
    B struct{C int; D []int "/f"}

func main() {
    t := T{}

    err := goyaml.Unmarshal([]byte(data), &t)
    if err != nil { panic(err.String()) }
    fmt.Printf("--- t:\n%v\n\n", t)

    d, err := goyaml.Marshal(&t)
    if err != nil { panic(err.String()) }
    fmt.Printf("--- t dump:\n%s\n\n", string(d))

    m := make(map[interface{}]interface{})

    err = goyaml.Unmarshal([]byte(data), &m)
    if err != nil { panic(err.String()) }
    fmt.Printf("--- m:\n%v\n\n", m)

    d, err = goyaml.Marshal(&m)
    if err != nil { panic(err.String()) }
    fmt.Printf("--- m dump:\n%s\n\n", string(d))

This example will generate the following output:

--- t:
{Easy! {2 [3 4]}}

--- t dump:
a: Easy!
  c: 2
  d: [3, 4]

--- m:
map[a:Easy! b:map[c:2 d:[3 4]]]

--- m dump:
a: Easy!
  c: 2
  - 3
  - 4

Source code

To obtain the source code, use Bazaar to download it from Launchpad:

$ bzr branch lp:goyaml

Reporting bugs

Please report bugs at:

How to build and install goyaml

To make use of goyaml, just run the following command:

$ goinstall launchpad.net/goyaml

Running tests

To run tests, first install gocheck with:

$ goinstall launchpad.net/gocheck

Then run gotest as usual:

$ gotest


goyaml is licensed under the LGPL.


This project is being developed under the Ensemble project at Canonical.

To get in touch, send a message to the Ensemble mailing list at: <ensemble@lists.ubuntu.com>

goyaml (last edited 2014-12-09 23:25:57 by foka)