September 2017
Intermediate to advanced
466 pages
9h 33m
English
The name of the utility will be showMongo.go and it will be presented in three parts. The utility will connect to a MongoDB instance, read a collection, and display the documents of the collection as a web page. Note that showMongo.go is based on the Go code of template.go.
The first part of the web application is the following:
package main
import (
"fmt"
"html/template"
"labix.org/v2/mgo"
"net/http"
"os"
"time"
)
var DatabaseName string
var collectionName string
type Document struct {
P1 int
P2 int
P3 int
P4 int
P5 int
}
Read now
Unlock full access