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)
}
}
If I give a valide template I got "successfull" : "A Go Web Server" on the Header, but if I give no existing tempalte I got 502 Bad Gateway and this on the header
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
I want to know if there is a way to send the Error that I got through a header, I mean
templates/VastPlayer/TempVide_.txt: no such file or directory
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…