| Spotlight on external Go libraries |
| 3 Jun 2011 |
| Tags: community, libraries |
| |
| Andrew Gerrand |
| |
| * Introduction |
| |
| While the Go authors have been working hard at improving Go's standard library, |
| the greater community has created a growing ecosystem of external libraries. |
| In this post we look at some popular Go libraries and how they can be used. |
| |
| [[http://labix.org/mgo][Mgo]] (pronounced "mango") is a MongoDB database driver. |
| [[http://www.mongodb.org/][MongoDB]] is a [[http://en.wikipedia.org/wiki/Document-oriented_database][document-oriented database]] |
| with a long list of features suitable for [[http://www.mongodb.org/display/DOCS/Use%2BCases][a broad range of uses]]. |
| The mgo package provides a rich, idiomatic Go API for working with MongoDB, |
| from basic operations such as inserting and updating records to the more |
| advanced [[http://www.mongodb.org/display/DOCS/MapReduce][MapReduce]] and |
| [[http://www.mongodb.org/display/DOCS/GridFS][GridFS]] features. |
| Mgo has a bunch of cool features including automated cluster discovery and |
| result pre-fetching - see the [[http://labix.org/mgo][mgo homepage]] for |
| details and example code. |
| For working with large data sets Go, MongoDB, |
| and mgo are a powerful combination. |
| |
| [[https://github.com/dchest/authcookie][Authcookie]] is a web library for |
| generating and verifying user authentication cookies. |
| It allows web servers to hand out cryptographically secure tokens tied to |
| a specific user that will expire after a specified time period. |
| It has a simple API that makes it straightforward to add authentication |
| to existing web applications. |
| See the [[https://github.com/dchest/authcookie/blob/master/README.md][README file]] |
| for details and example code. |
| |
| [[http://code.google.com/p/go-charset][Go-charset]] provides support for |
| converting between Go's standard UTF-8 encoding and a variety of character sets. |
| The go-charset package implements a translating io.Reader and io.Writer |
| so you can wrap existing Readers and Writers (such as network connections |
| or file descriptors), |
| making it easy to communicate with systems that use other character encodings. |
| |
| [[https://github.com/madari/go-socket.io][Go-socket.io]] is a Go implementation |
| of [[http://socket.io/][Socket.IO]], |
| a client/server API that allows web servers to push messages to web browsers. |
| Depending on the capabilities of the user's browser, |
| Socket.IO uses the best transport for the connection, |
| be it modern websockets, AJAX long polling, |
| or some [[http://socket.io/#transports][other mechanism]]. |
| Go-socket.io bridges the gap between Go servers and rich JavaScript clients |
| for a wide range of browsers. |
| To get a feel for go-socket.io see the [[https://github.com/madari/go-socket.io/blob/master/example/example.go][chat server example]]. |
| |
| It's worth mentioning that these packages are [[https://golang.org/cmd/goinstall/][goinstallable]]. |
| With an up-to-date Go [[https://golang.org/doc/install.html][installation]] |
| you can install them all with a single command: |
| |
| goinstall launchpad.net/mgo \ |
| github.com/dchest/authcookie \ |
| go-charset.googlecode.com/hg/charset \ |
| github.com/madari/go-socket.io |
| |
| Once goinstalled, the packages can be imported using those same paths: |
| |
| import ( |
| "launchpad.net/mgo" |
| "github.com/dchest/authcookie" |
| "go-charset.googlecode.com/hg/charset" |
| "github.com/madari/go-socket.io" |
| ) |
| |
| Also, as they are now a part of the local Go system, |
| we can inspect their documentation with [[https://golang.org/cmd/godoc/][godoc]]: |
| |
| godoc launchpad.net/mgo Database # see docs for Database type |
| |
| Of course, this is just the tip of the iceberg; |
| there are more great Go libraries listed on the [[http://godashboard.appspot.com/package][package dashboard]] |
| and many more to come. |