There are 3 ways people use to close a response body and I call them The Good, The Bad and The Ugly way.

The Ugly

It is not rare to find code like this:

    resp,err := http.Get("https://mysite.com")
    defer resp.Body.Close()
    if err != nil {
        // handle error    
        return e...

Suppose you have a slice declared as:

names := []string{"Manyanda", "Abhishek", "Pawel", "Eoin", "Jameel", "Vincent", "Jason", "Massimo"}

and a printSlice function that prints the first count element of the passed in slice implemented like this:

func printSlice(slice []*string, count int)...

Go is not an object-oriented language, however, it allows you to implement both Methods and Functions. A Method is simply a Function with a receiver.

GO Methods vs Functions

Look at the code below:

package main

import (
    "fmt"
)

type Contact struct {
    name    string
    surna...