路由无法正常访问(articles/create)
2020/11/29 14:27:30 http: panic serving [::1]:60559: runtime error: invalid memory address or nil pointer dereference
goroutine 30 [running]:
net/http.(*conn).serve.func1(0xc0000b9a40)
/usr/local/go/src/net/http/server.go:1772 +0x139
panic(0x12c0c20, 0x1564270)
我使用的mac , go 的版本是1.14
我在网上搜索了。
这个运行时错误的原因是在”net/http”的 handler func(ResponseWriter, *Request)函数里使用了没有分配内存的指针。实际上,和C语言一样所有指针在使用前都需要做nil判断
但是我试了 把代码复制一遍,还是会遇到同样的问题。
推荐文章: