【发布时间】:2018-07-19 18:41:56
【问题描述】:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/cookie", cookie)
http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
// do ...
}
func cookie(w http.ResponseWriter, r *http.Request) {
cd, _ := r.Cookie("hello")
if cd.Value == "username" {
// do ...
}
}
如果运行:
$ 运行 main.go
服务器正常工作没有问题,但在 firfox 中插入“/cookie”路径时出现问题。
错误:
运行时错误:无效的内存地址或 nil 指针取消引用
【问题讨论】:
标签: go