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 關注
- 87 瀏覽
添加回答
舉報
0/150
提交
取消