func main() { http.HandleFunc("/", foo) log.Println("Listening...") http.ListenAndServe(":6001", nil)}func foo(w http.ResponseWriter, r *http.Request) { w.Header().Set("successfull", "A Go Web Server") fi := path.Join("templates/VastPlayer", "TempVide_.txt") tmpl, err := template.ParseFiles(fi) if err != nil { w.Header().Set("Error", err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) } if err := tmpl.Execute(w, ""); err != nil { w.Header().Set("Error", err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) }}如果我给出一个 valide 模板,我得到“成功”:“A Go Web 服务器”在标头上,但如果我没有给出现有的 tempalte,我得到 502 Bad Gateway 和这个在标头上HTTP/1.1 502 Bad GatewayServer: nginx/1.8.0Date: Mon, 06 Jul 2015 15:19:31 GMTContent-Type: text/htmlContent-Length: 574Connection: keep-alive我想知道是否有办法发送我通过标头获得的错误,我的意思是templates/VastPlayer/TempVide_.txt:没有这样的文件或目录
1 回答
哆啦的时光机
TA贡献1779条经验 获得超6个赞
发送
w.Header().Add("Status", "200")
w.Header().Add("Body", "Book Added Successfully")
接收
fmt.Println("response Status:", resp.Header.Get("Status"))
fmt.Println("response Body:", resp.Header.Get("Body"))
- 1 回答
- 0 关注
- 143 浏览
添加回答
举报
0/150
提交
取消
