title: runtime error:Invalid memory Address or nil pointer dereference-golang
body: <p>I am new to golang, am trying develop a login page with sesions. the code is building successfully but when I run in browser its saying 404 page not found.can any one help for me. Thanks in advance.
  Here is my code</p>
  
  <pre><code>// main.go
  package main
  
  import (
          _ "HarishSession/routers"
         "github.com/astaxie/beego"
        "fmt"
          "net/http"
           "html/template"
              "strings"
                "log"
                "github.com/astaxie/beego/session"
                 "sync"
  
  
      )
  
  
   var globalSessions *session.Manager
   var provides = make(map[string]Provider)
  
   func sayhelloName(w http.ResponseWriter, r *http.Request) {
              r.ParseForm()  // parse arguments, you have to call this by yourself
              fmt.Println("the information of form is",r.Form)  // print form information in server side
              fmt.Println("path", r.URL.Path)
               fmt.Println("scheme", r.URL.Scheme)
                 fmt.Println(r.Form["url_long"])
                  for k, v := range r.Form {
                     fmt.Println("key:", k)
                         fmt.Println("val:", strings.Join(v, ""))
      }
                        fmt.Fprintf(w, "Hello astaxie!") // send data to client side
  }
  
  
  
  type Manager struct {
      cookieName  string     //private cookiename
      lock        sync.Mutex // protects session
      provider    Provider
      maxlifetime int64
  }
  
  
  type Provider interface {
      SessionInit(sid string) (Session, error)
      SessionRead(sid string) (Session, error)
      SessionDestroy(sid string) error
      SessionGC(maxLifeTime int64)
  }
  type Session interface {
      Set(key, value interface{}) error //set session value
      Get(key interface{}) interface{}  //get session value
      Delete(key interface{}) error     //delete session value
      SessionID() string                //back current sessionID
  }
  
  
  
  func NewManager(provideName, cookieName string, maxlifetime int64) (*Manager, error) {
      provider, ok := provides[provideName]
      if !ok {
          return nil, fmt.Errorf("session: unknown provide %q (forgotten import?)", provideName)
      }
      return &amp;Manager{provider: provider, cookieName: cookieName, maxlifetime: maxlifetime}, nil
  }
  
  
  func login(w http.ResponseWriter, r *http.Request) {
  
  sess := globalSessions.SessionStart(w,r)
  r.ParseForm()
  
  fmt.Println("method:", r.Method)
  if r.Method == "GET" {
  t, _ := template.ParseFiles("login.tpl")
  w.Header().Set("Content-Type", "text/html")
  t.Execute(w,sess.Get("username"))
  } else {
  //logic part of log in
  fmt.Println("username:",r.Form["username"])
  fmt.Println("password:",r.Form["password"])
  http.Redirect(w,r,"/",302)
  }
  }
  
  
  
  func main() {
  var globalSessions *session.Manager
   http.HandleFunc("/", sayhelloName)
   http.HandleFunc("/login", login)
      err := http.ListenAndServe(":8080", nil) // set listen port
      if err != nil {
          log.Fatal("ListenAndServe the error is: ", err)
      }
      fmt.Println("hello")
      beego.Run()
  
  
      fmt.Println(globalSessions)
  }
  
  
  //router.go
  package routers
  
  import (
      "HarishSession/controllers"
      "github.com/astaxie/beego"
  )
  
  func init() {
      beego.Router("/", &amp;controllers.MainController{})
      beego.Router("/login", &amp;controllers.MainController{})
  }
  
  
  //default.go
  package controllers
  
  import (
      "github.com/astaxie/beego"
  )
  
  type MainController struct {
      beego.Controller
  }
  
  func (this *MainController) Get() {
      this.Data["Website"] = "beego.me"
      this.Data["Email"] = "astaxie@gmail.com"
      this.TplNames = "index.tpl"
      this.TplNames="login.tpl"
  }
  </code></pre>