runtime error: invalid memory address or nil pointer dereference

Нужно подключиться к шаблону и заполнить форму через сайт (Логин и пароль), но выдается след. ошибка.

package main

import (
"fmt"


"net/http"
  "html/template"
  "database/sql"
_   "github.com/go-sql-driver/mysql"
)

func index(w http.ResponseWriter, r *http.Request) {
  t, err := template.ParseFiles("templates/index.html")

  if err !=nil {
    fmt.Fprintf(w, err.Error())
  }
  t.ExecuteTemplate(w, "index", index)
}

func authorization(w http.ResponseWriter, r *http.Request) {
  title := r.FormValue("title")
  anons := r.FormValue("anons")

  db,err := sql.Open("mysql", "mysql:mysql@tcp(127.0.0.1:3306)/golang")
  if err != nil {
    panic(err)
    }
    defer db.Close()
    // Установка данных
    insert, err := db.Query(fmt.Sprintf("INSERT INTO `articles` (`title`, `anons`) VALUES('%s', '%s')", title, anons))
      if err !=nil {
        panic(err)
      }
      defer insert.Close()

      http.Redirect(w, r, "/", http.StatusSeeOther)
 }

func handleFunc() {
  http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
  http.HandleFunc("/", index)
  http.HandleFunc("/authorization", authorization)

  http.ListenAndServe(":8080", nil)
}

func main() {
  handleFunc()

Ответы (0 шт):