Web programming tutorial example issue

I tried your tutorials about web programming and I have an issue:
https://golang.org/doc/articles/wiki/

I have copied the code provided here and did everything like it is said and when I run the code and open server it displays this message:

pi@raspberrypi:~/go/src/github.com/harisgen79/go_crash_course/08_web $ ./main
2019/05/18 14:14:01 http: panic serving [::1]:36078: runtime error: invalid memory address or nil pointer dereference
goroutine 20 [running]:
net/http.(*conn).serve.func1(0x249c6c0)
/usr/local/go/src/net/http/server.go:1769 +0xf0
panic(0x317380, 0x5fb730)
/usr/local/go/src/runtime/panic.go:522 +0x1a0
html/template.(*Template).escape(0x0, 0x0, 0x0)
/usr/local/go/src/html/template/template.go:95 +0x24
html/template.(*Template).Execute(0x0, 0x3cfd28, 0x2518000, 0x30f430, 0x0, 0x3cfe00, 0x25020e0)
/usr/local/go/src/html/template/template.go:119 +0x1c
main.renderTemplate(0x3d24c0, 0x2518000, 0x3512d8, 0x4, 0x0)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:35 +0xd0
main.viewHandler(0x3d24c0, 0x2518000, 0x24f2180)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:41 +0x74
net/http.HandlerFunc.ServeHTTP(0x36d1d0, 0x3d24c0, 0x2518000, 0x24f2180)
/usr/local/go/src/net/http/server.go:1995 +0x34
net/http.(*ServeMux).ServeHTTP(0x602f58, 0x3d24c0, 0x2518000, 0x24f2180)
/usr/local/go/src/net/http/server.go:2375 +0x1ac
net/http.serverHandler.ServeHTTP(0x249e200, 0x3d24c0, 0x2518000, 0x24f2180)
/usr/local/go/src/net/http/server.go:2774 +0x88
net/http.(*conn).serve(0x249c6c0, 0x3d2ac0, 0x240c080)
/usr/local/go/src/net/http/server.go:1878 +0x7e4
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2884 +0x298
2019/05/18 14:14:01 http: panic serving [::1]:36080: runtime error: invalid memory address or nil pointer dereference
goroutine 21 [running]:
net/http.(*conn).serve.func1(0x249c720)
/usr/local/go/src/net/http/server.go:1769 +0xf0
panic(0x317380, 0x5fb730)
/usr/local/go/src/runtime/panic.go:522 +0x1a0
html/template.(*Template).escape(0x0, 0x0, 0x0)
/usr/local/go/src/html/template/template.go:95 +0x24
html/template.(*Template).Execute(0x0, 0x3cfd28, 0x2518090, 0x30f430, 0x0, 0x3cfe00, 0x2502260)
/usr/local/go/src/html/template/template.go:119 +0x1c
main.renderTemplate(0x3d24c0, 0x2518090, 0x3512d8, 0x4, 0x0)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:35 +0xd0
main.viewHandler(0x3d24c0, 0x2518090, 0x2538080)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:41 +0x74
net/http.HandlerFunc.ServeHTTP(0x36d1d0, 0x3d24c0, 0x2518090, 0x2538080)
/usr/local/go/src/net/http/server.go:1995 +0x34
net/http.(*ServeMux).ServeHTTP(0x602f58, 0x3d24c0, 0x2518090, 0x2538080)
/usr/local/go/src/net/http/server.go:2375 +0x1ac
net/http.serverHandler.ServeHTTP(0x249e200, 0x3d24c0, 0x2518090, 0x2538080)
/usr/local/go/src/net/http/server.go:2774 +0x88
net/http.(*conn).serve(0x249c720, 0x3d2ac0, 0x2502140)
/usr/local/go/src/net/http/server.go:1878 +0x7e4
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2884 +0x298
2019/05/18 14:14:02 http: panic serving [::1]:36082: runtime error: invalid memory address or nil pointer dereference
goroutine 5 [running]:
net/http.(*conn).serve.func1(0x255e000)
/usr/local/go/src/net/http/server.go:1769 +0xf0
panic(0x317380, 0x5fb730)
/usr/local/go/src/runtime/panic.go:522 +0x1a0
html/template.(*Template).escape(0x0, 0x0, 0x0)
/usr/local/go/src/html/template/template.go:95 +0x24
html/template.(*Template).Execute(0x0, 0x3cfd28, 0x2518120, 0x30f430, 0x0, 0x3cfe00, 0x25023c0)
/usr/local/go/src/html/template/template.go:119 +0x1c
main.renderTemplate(0x3d24c0, 0x2518120, 0x3512d8, 0x4, 0x0)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:35 +0xd0
main.viewHandler(0x3d24c0, 0x2518120, 0x2538100)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:41 +0x74
net/http.HandlerFunc.ServeHTTP(0x36d1d0, 0x3d24c0, 0x2518120, 0x2538100)
/usr/local/go/src/net/http/server.go:1995 +0x34
net/http.(*ServeMux).ServeHTTP(0x602f58, 0x3d24c0, 0x2518120, 0x2538100)
/usr/local/go/src/net/http/server.go:2375 +0x1ac
net/http.serverHandler.ServeHTTP(0x249e200, 0x3d24c0, 0x2518120, 0x2538100)
/usr/local/go/src/net/http/server.go:2774 +0x88
net/http.(*conn).serve(0x255e000, 0x3d2ac0, 0x25022a0)
/usr/local/go/src/net/http/server.go:1878 +0x7e4
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2884 +0x298
2019/05/18 14:14:07 http: panic serving [::1]:36084: runtime error: invalid memory address or nil pointer dereference
goroutine 22 [running]:
net/http.(*conn).serve.func1(0x249c780)
/usr/local/go/src/net/http/server.go:1769 +0xf0
panic(0x317380, 0x5fb730)
/usr/local/go/src/runtime/panic.go:522 +0x1a0
html/template.(*Template).escape(0x0, 0x0, 0x0)
/usr/local/go/src/html/template/template.go:95 +0x24
html/template.(*Template).Execute(0x0, 0x3cfd28, 0x25181b0, 0x30f430, 0x0, 0x3cfe00, 0x2502520)
/usr/local/go/src/html/template/template.go:119 +0x1c
main.renderTemplate(0x3d24c0, 0x25181b0, 0x3512d8, 0x4, 0x0)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:35 +0xd0
main.viewHandler(0x3d24c0, 0x25181b0, 0x2538180)
/home/pi/go/src/github.com/harisgen79/go_crash_course/08_web/main.go:41 +0x74
net/http.HandlerFunc.ServeHTTP(0x36d1d0, 0x3d24c0, 0x25181b0, 0x2538180)
/usr/local/go/src/net/http/server.go:1995 +0x34
net/http.(*ServeMux).ServeHTTP(0x602f58, 0x3d24c0, 0x25181b0, 0x2538180)
/usr/local/go/src/net/http/server.go:2375 +0x1ac
net/http.serverHandler.ServeHTTP(0x249e200, 0x3d24c0, 0x25181b0, 0x2538180)
/usr/local/go/src/net/http/server.go:2774 +0x88
net/http.(*conn).serve(0x249c780, 0x3d2ac0, 0x2502400)
/usr/local/go/src/net/http/server.go:1878 +0x7e4
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2884 +0x298
^C

It just stops like this and I have to terminate it as you can see.
I’m using Raspberry Pi 3 model B. Anyone knows why is this happening?

Hi there,

I tried the link of the web programming tutorial

and it directed me to this tutorial. It just a confirmation that were on the same page.

I tried the solution, by skipping and looking to the final code. And tried running it on my Ubuntu 18 machine. And it works absolutely fine.

image

  1. What is the version of your go lang ?.
  2. What is memory cap of your hostOS?, which in your case is Raspberry (cool, didn’t know that! cheers!).

Hello, thanks for the answer.

I got it to work, turns out that I had skipped some steps which caused those “invalid memory address or nil pointer dereference” errors. It works now and looks the same as the screenshot you attached.

While we are at it, do you perhaps have some experience with combining Go and Postman. I have to make a project which includes those two and would greatly appreciate any help.

Cheers!

Cool!

I do have an api in go lang that can be run using rest and postman.

check this out. happy coding!

Thanks a lot!

As you can see I’m not actively working on it but will surely check it out.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.