Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime error: invalid memory address or nil pointer dereference #58

Open
zyjia opened this issue Oct 8, 2019 · 4 comments
Open

runtime error: invalid memory address or nil pointer dereference #58

zyjia opened this issue Oct 8, 2019 · 4 comments

Comments

@zyjia
Copy link

zyjia commented Oct 8, 2019

环境:ubuntu 16.04 go语言:go version go1.13.1 linux/amd64
错误信息:
parse mysql config once. filePath: /home/tonyzhang/data/web/go/top/Config/mysql.toml
2019/10/08 13:03:40 err
2019/10/08 13:03:40 http: panic serving 192.168.99.198:5810: runtime error: invalid memory address or nil pointer dereference
goroutine 21 [running]:
net/http.(*conn).serve.func1(0xc0000bcc80)
/home/tonyzhang/data/go/src/net/http/server.go:1767 +0x139
panic(0x7fe6c0, 0xba3450)
/home/tonyzhang/data/go/src/runtime/panic.go:679 +0x1b2
text/template.errRecover(0xc000165b48)
/home/tonyzhang/data/go/src/text/template/exec.go:164 +0x1cb
panic(0x7fe6c0, 0xba3450)
/home/tonyzhang/data/go/src/runtime/panic.go:679 +0x1b2
text/template.(*Template).execute(0x0, 0x902920, 0xc000152000, 0x0, 0x0, 0x0, 0x0)
/home/tonyzhang/data/go/src/text/template/exec.go:218 +0x1c1
text/template.(*Template).Execute(...)
/home/tonyzhang/data/go/src/text/template/exec.go:204
main.main.func1(0x909960, 0xc000152000, 0xc000144000)
/home/tonyzhang/data/web/go/top/App/Server.go:72 +0xc7
net/http.HandlerFunc.ServeHTTP(0x88ff88, 0x909960, 0xc000152000, 0xc000144000)
/home/tonyzhang/data/go/src/net/http/server.go:2007 +0x44
net/http.(*ServeMux).ServeHTTP(0xbb09c0, 0x909960, 0xc000152000, 0xc000144000)
/home/tonyzhang/data/go/src/net/http/server.go:2387 +0x1bd
net/http.serverHandler.ServeHTTP(0xc000112000, 0x909960, 0xc000152000, 0xc000144000)
/home/tonyzhang/data/go/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0000bcc80, 0x90a620, 0xc00013a000)
/home/tonyzhang/data/go/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
/home/tonyzhang/data/go/src/net/http/server.go:2927 +0x38e

@wenjiecq
Copy link

TopList/App/Server.go

Lines 63 to 73 in d7a1599

http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("../Html/css/"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("../Html/js/"))))
// 首页
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t, err := template.ParseFiles("../Html/hot.html")
if err != nil {
log.Println("err")
}
t.Execute(res, nil)
})

后面的相对路径换成绝对路径,window下测试可以使用

@zyjia
Copy link
Author

zyjia commented Oct 17, 2019

TopList/App/Server.go

Lines 63 to 73 in d7a1599

http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("../Html/css/"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("../Html/js/"))))
// 首页
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t, err := template.ParseFiles("../Html/hot.html")
if err != nil {
log.Println("err")
}
t.Execute(res, nil)
})

后面的相对路径换成绝对路径,window下测试可以使用
谢谢,可以用了,就是有点别扭

@sexyflaw
Copy link

sexyflaw commented Dec 2, 2019

感谢评论区

@xuze1993
Copy link

有效!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants