package main
import (
"fmt"
"net/http"
"html/template"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
t, err := template.ParseFiles("templates/index.html")
t.ExecuteTemplate(w, "index", nil)
if err != nil {
fmt.Fprint(w, err.Error())
return
}
}
func main() {
fmt.Println("Lsterning on port:3000")
http.Handle("/assets",http.StripPrefix("/assets",http.FileServer(http.Dir("./assets/"))))
http.HandleFunc("/", indexHandler)
http.ListenAndServe(":3000", nil)
}
пишу по уроку. вот происходит ошибка - "Данные не получены ERR_EMPTY_RESPONSE"- ссылается на
2015/12/26 22:29:10 http: panic serving [::1]:49981: runtime error: invalid memo
ry address or nil pointer dereference
goroutine 33 [running]:
net/http.(*conn).serve.func1(0xc0820f0160, 0x395608, 0xc082134000)
c:/go/src/net/http/server.go:1287 +0xbc
html/template.(*Template).lookupAndEscapeTemplate(0x0, 0x7a43a0, 0x5, 0x0, 0x0,0x0)
c:/go/src/html/template/template.go:125 +0x6a
html/template.(*Template).ExecuteTemplate(0x0, 0x26000e0, 0xc0820f0210, 0x7a43a0, 0x5, 0x0, 0x0, 0x0, 0x0)
c:/go/src/html/template/template.go:114 +0x52
main.indexHandler(0x2600058, 0xc0820f0210, 0xc08210e1c0)
C:/gopath/src/sale/main.go:11 +0x118
net/http.HandlerFunc.ServeHTTP(0x83e590, 0x2600058, 0xc0820f0210, 0xc08210e1c0)
c:/go/src/net/http/server.go:1422 +0x41
net/http.(*ServeMux).ServeHTTP(0xc0820563c0, 0x2600058, 0xc0820f0210, 0xc08210e1c0)
c:/go/src/net/http/server.go:1699 +0x184
net/http.serverHandler.ServeHTTP(0xc082004300, 0x2600058, 0xc0820f0210, 0xc08210e1c0)
c:/go/src/net/http/server.go:1862 +0x1a5
net/http.(*conn).serve(0xc0820f0160)
c:/go/src/net/http/server.go:1361 +0xbf5
created by net/http.(*Server).Serve
c:/go/src/net/http/server.go:1910 +0x3fd