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

Browsing to http://localhost:8080/ will list you the name of all the databases that exist in the MongoDB cluster and will look as shown in the following screenshot:

Let’s look at the program we have written:

  1. Using import ( "fmt" "log" "net/http" "strings" mgo "gopkg.in/mgo.v2" ), we imported gopkg.in/mgo.v2 with the package alias name as mgo.
  2. Using var session *mgo.Session, we declared the private MongoDB Session instance, which acts as a communication session with the database.
  3. Using var connectionError error, we declared a private error object. ...

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