Introduction

The gobson project offers Go programs a flexible serializer and deserializer for BSON documents.

gobson was implemented to support the mgo MongoDB driver for Go.

Highlights

Here are some of the features of the gobson package:

  • Standard Marshal/Unmarshal interface, as established by the standard json package
  • Standard field renaming via tags
  • Best effort type mapping when unmarshalling values (e.g. 1 on bool == true, maps like map[int]string work, etc)
  • Conditional fields (see docs), enabling zero values to be excluded from the mapping
  • Comfortable Getter and Setter interfaces, for custom (un)marshalling
  • gobson.D{A, B, ...} type, for ordered documents
  • Very thorough test suite

API documentation

The API documentation is currently available at:

  • goneat.org/lp/mgo/bson

Mailing list

Discussion related to the use and development of gobson and mgo is held in the mgo-users mailing list.

Installing

To install gobson, simply run:

go get launchpad.net/mgo/bson

Example

Here is a very simple example which dumps a Person struct. Note that the Phone field will not be included in the serialization, since its tag enables the conditional flag (",omitempty"), and the value is zeroed.

package main import ( "fmt" "launchpad.net/mgo/bson" ) type Person struct { Name string Phone string ",omitempty" } func main() { data, err := bson.Marshal(&Person{Name:"Bob"}) if err != nil { panic(err) } fmt.Printf("%q", data) }

License

gobson is made available under the Simplified BSD License.

Resources

  • API docs for mgo/bson
  • API docs for mgo
  • Mailing list
  • Email author

Releases

  • r2012.03.04 - (details)
  • r2012.01.22 - (details)
  • r2011.12.18 - (details)
  • r2011.10.29 - (details)
  • r2011.09.15 - (details)
  • r2011.08.02 - (details)
  • r2011.07.28 - (details)
  • r2011.07.15 - (details)
  • r2011.06.24 - (details)
  • r2011.05.12 - (details)
  • r2011.04.28 - (details)
  • r2011.04.24 - (details)
  • r2011.04.19 - (details)
  • r2011.04.15 - (details)
  • r2011.04.13 - (details)
  • r2011.04.09 - (details)
  • r2011.03.24 - (details)
  • r2011.03.15 - (details)
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.