Go 博客
Spotlight on external Go libraries
2011/06/03
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.
Mgo (pronounced "mango") is a MongoDB database driver. MongoDB is a document-oriented database with a long list of features suitable for 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 MapReduce and GridFS features. Mgo has a bunch of cool features including automated cluster discovery and result pre-fetching - see the mgo homepage for details and example code. For working with large data sets Go, MongoDB, and mgo are a powerful combination.
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 README file for details and example code.
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.
Go-socket.io is a Go implementation of 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 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 chat server example.
It's worth mentioning that these packages are goinstallable. With an up-to-date Go 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 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 package dashboard and many more to come.
相关文章
- Go 2, here we come!
- Nine years of Go
- Participate in the 2018 Go User Survey
- Participate in the 2018 Go Company Questionnaire
- Go 2 Draft Designs
- Go 2017 Survey Results
- Hello, 中国!
- Participate in the 2017 Go User Survey
- Eight years of Go
- Community Outreach Working Group
- Contribution Workshop
- Contributors Summit
- Toward Go 2
- Go 2016 Survey Results
- Participate in the 2016 Go User Survey and Company Questionnaire
- Go, Open Source, Community
- GopherChina Trip Report
- Four years of Go
- Get thee to a Go meetup
- Go turns three
- 组织 Go 代码
- Getting to know the Go community
- The Go Programming Language turns two
- The Go image/draw package
- The Go image package
- Third-party libraries: goprotobuf and beyond