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 (
    "fmt"
    "log"

    "gopkg.in/mgo.v2"
    "gopkg.in/mgo.v2/bson"
)

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 {
    fmt.Println("Connected")

    }
    defer session.Close()   
}

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