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:
- 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.
- Using var session *mgo.Session, we declared the private MongoDB Session instance, which acts as a communication session with the database.
- Using var connectionError error, we declared a private error object. ...