Fix issue in Writing Web Applications https://go.dev/doc/articles/wiki/

Found out there is a small mistake in Writing Web Applications - The Go Programming Language

With this web server running, a visit to http://localhost:8080/view/test should show a page titled “test” containing the words “Hello world”.

Should be

With this web server running, a visit to http://localhost:8080/view/TestPage should show a page titled “test” containing the words “Hello world”.

Otherwise you get this error

2024/05/26 15:01:32 http: panic serving [::1]:52401: runtime error: invalid memory address or nil pointer dereference
goroutine 42 [running]:
net/http.(*conn).serve.func1()
        /usr/local/go/src/net/http/server.go:1898 +0xbe
panic({0x612ee40?, 0x62f4a50?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
main.viewHandler({0x6173ff0, 0xc0001be620}, 0xc0001aab30?)
        /Users/pcam/DEV/GO/GOWIKI/wiki.go:32 +0x96
net/http.HandlerFunc.ServeHTTP(0x6300130?, {0x6173ff0?, 0xc0001be620?}, 0x607961a?)
        /usr/local/go/src/net/http/server.go:2166 +0x29
net/http.(*ServeMux).ServeHTTP(0x5ed40d9?, {0x6173ff0, 0xc0001be620}, 0xc0001ba480)
        /usr/local/go/src/net/http/server.go:2683 +0x1ad
net/http.serverHandler.ServeHTTP({0xc0001946c0?}, {0x6173ff0?, 0xc0001be620?}, 0x6?)
        /usr/local/go/src/net/http/server.go:3137 +0x8e
net/http.(*conn).serve(0xc0001986c0, {0x6174458, 0xc00007ccf0})
        /usr/local/go/src/net/http/server.go:2039 +0x5e8
created by net/http.(*Server).Serve in goroutine 1
        /usr/local/go/src/net/http/server.go:3285 +0x4b4

It actually says in the article:

Let’s create some page data (as test.txt), compile our code, and try serving a wiki page.
Open test.txt file in your editor, and save the string “Hello world” (without quotes) in it.

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