我有一个用Go编写的服务,使用包。net/http
http.HandleFunc("/hello", Hello)
log.Fatal(http.ListenAndServe(":8080", nil))
目前为止,一切都好。在 里面,代码存根如下:func Hello
func Hello(w http.ResponseWriter, r *http.Request) {
c, err := r.Cookie("token")
if err != nil {
if err == http.ErrNoCookie {
// If the cookie is not set, return an unauthorized status
w.WriteHeader(http.StatusUnauthorized)
log.WithFields(log.Fields{
"fnc": "Hello",
}).Fatal(err)
return
//exit status 1 < Server stops here.
}
w.WriteHeader(http.StatusBadRequest)
log.WithFields(log.Fields{
"fnc": "Hello",
}).Fatal(err)
return
}
问题是当代码流到达请求中找不到cookie的地方时,程序/服务器在返回语句之后存在,控制台显示,并且在客户端收到错误 ErrNoCookie exit status 1 Error: read ECONNRESET
但是,作为一项服务,我希望它继续运行并响应后续请求。
我做错了什么?
慕森王
慕田峪4524236
随时随地看视频慕课网APP
相关分类