Golang error "invalid memory address or nil pointer dereference", Why this happens? : <pre><code>package main

import (
        "fmt"
        "net/http"
)

func main() {
        http.HandleFunc("/", handler)
        http.HandleFunc("/cookie", cookie)
        http.ListenAndServe(":8080", nil)
}

func handler(w http.ResponseWriter, r *http.Request) {
            // do ...
}

func cookie(w http.ResponseWriter, r *http.Request) {
        cd, _ := r.Cookie("hello")

        if cd.Value == "username" {
               // do ...
        }
}
</code></pre>

<p>if run: </p>

<blockquote>
  <p>$ go run main.go</p>
</blockquote>

<p>no problem server is work, but in firfox when inserting "/cookie" path the problem occurs.</p>

<p>Error:</p>

<blockquote>
  <p>runtime error: invalid memory address or nil pointer dereference</p>
</blockquote>
