Go Environment Variables

Go Environment Variables

To show environment variables run this command:

Go env

MongoDB Connection

Here is a script that connects to mongoDB

package main

import (


func main() {
    uri := "localhost:27017"

    // connect to mongodb
    session, err := mgo.Dial(uri)
    if err != nil {
        log.Fatal("Couldn't connect to db.", err)

    else {

    defer session.Close()   

Golang compiler is fussy i.e. if you put else on a new line you will have a warning message.