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)
}
}
如果我给出一个有效的模板,我会在标题上得到“successfull”:“A Go Web Server”,但是如果我没有给出现有的模板,我会在标题上得到 502 Bad Gateway 和 this
HTTP/1.1 502 Bad Gateway
Server: nginx/1.8.0
Date: Mon, 06 Jul 2015 15:19:31 GMT
Content-Type: text/html
Content-Length: 574
Connection: keep-alive
我想知道是否有办法发送我通过标头获得的错误,我的意思是
模板/VastPlayer/TempVide_.txt:没有这样的文件或目录
蝴蝶不菲
相关分类