O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works…

Once we run the program, the HTTP server will start locally listening on port 8080.

Next, browsing to http://localhost:8080/employees will give you the list of all employees from the MongoDB employee collection:

Let’s look at the changes we introduced in the program:

  1. Using import ( "encoding/json" "log" "net/http" "github.com/gorilla/mux" mgo "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson"), we imported an additional gopkg.in/mgo.v2/bson package, which is a BSON specification for Go, and the encoding/json package, which we used to marshal the object list, which we got from MongoDB, to JSON.
  2. Next, we defined a readDocuments handler, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required