goyaml
2813
Comment:
|
2815
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
<<TableOfContents>> |
|
Line 4: | Line 6: |
encode and decode YAML values. | encode and decode YAML values. It was developed within Canonical as part of the [[https://juju.ubuntu.com|juju]] project, and is based on a pure Go port of the well-known [[http://pyyaml.org/wiki/LibYAML|libyaml]] C library to parse and generate YAML data quickly and reliably. |
Line 6: | Line 10: |
It was developed within Canonical as part of an experiment related to using the Go language with the [[https://launchpad.net/ensemble|Ensemble]] project. |
== Compatibility == |
Line 9: | Line 12: |
goyaml internally uses the C [[http://pyyaml.org/wiki/LibYAML|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 (huh?), and multi-document unmarshalling. These features are not hard to add, and will be introduced as necessary. |
Line 17: | Line 21: |
http://goneat.org/pkg/goyaml | http://godoc.org/launchpad.net/goyaml |
Line 21: | Line 25: |
Here is a simple example which connects to !ZooKeeper, waits for the session to be established, and attempts to create a node: |
Here is a simple example: |
Line 27: | Line 30: |
"goyaml" | "launchpad.net/goyaml" |
Line 40: | Line 43: |
B struct{C int; D []int "/f"} | B struct{C int; D []int ",flow"} |
Line 45: | Line 48: |
Line 47: | Line 51: |
panic(err.String()) | panic(err) |
Line 52: | Line 56: |
if err != nil { panic(err) } |
|
Line 58: | Line 65: |
panic(err.String()) | panic(err) |
Line 63: | Line 70: |
if err != nil { panic(err) } |
|
Line 107: | Line 117: |
Using goinstall doesn't yet work in this case because goyaml depends on cgo, so for now we'll simply go ahead and build it manually. First, grab the code from Launchpad: |
To make use of goyaml, just run the following command: |
Line 112: | Line 119: |
$ bzr branch lp:goyaml }}} Then, build and install it: {{{ $ make install |
$ go get launchpad.net/goyaml |
Line 124: | Line 126: |
$ goinstall launchpad.net/gocheck | $ go get launchpad.net/gocheck |
Line 130: | Line 132: |
$ gotest | $ go test |
Line 139: | Line 141: |
This project is being developed under the [[https://launchpad.net/ensemble|Ensemble]] project at [[http://www.canonical.com|Canonical]]. | This project is being developed under the [[https://juju.ubuntu.com|juju]] project at [[http://www.canonical.com|Canonical]]. |
Line 141: | Line 143: |
To get in touch, send a message to the Ensemble mailing list at: <ensemble@lists.ubuntu.com> | To get in touch, send a message to the juju mailing list at: <juju-dev@lists.ubuntu.com> |
Contents
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 the juju project, and is based on a pure Go port of the well-known libyaml C library to parse and generate YAML data quickly and reliably.
Compatibility
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 (huh?), 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:
Example
Here is a simple example:
package main import ( "launchpad.net/goyaml" "fmt" ) var data = ` a: Easy! b: c: 2 d: [3, 4] ` type T struct { A string B struct{C int; D []int ",flow"} } func main() { t := T{} err := goyaml.Unmarshal([]byte(data), &t) if err != nil { panic(err) } fmt.Printf("--- t:\n%v\n\n", t) d, err := goyaml.Marshal(&t) if err != nil { panic(err) } 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) } fmt.Printf("--- m:\n%v\n\n", m) d, err = goyaml.Marshal(&m) if err != nil { panic(err) } 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! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 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:
$ go get launchpad.net/goyaml
Running tests
To run tests, first install gocheck with:
$ go get launchpad.net/gocheck
Then run gotest as usual:
$ go test
License
goyaml is licensed under the LGPL.
Contact
This project is being developed under the juju project at Canonical.
To get in touch, send a message to the juju mailing list at: <juju-dev@lists.ubuntu.com>
goyaml (last edited 2014-12-09 23:25:57 by foka)