次のhtml/template
ようなものがあるとします。
<html>
<body>
<p>{{SomeFunc .SomeData}}</p>
</body>
と時々SomeFunc
エラーを返します。これに対処する慣用的な方法はありますか?
に直接書き込むResponseWriter
と、エラーが発生する前にステータス コード 200 が既に書き込まれています。
var tmpl *template.Template
func Handler(w http.ResponseWriter, r *http.Request) {
err := tmpl.Execute(w, data)
// "<html><body><p>" has already been written...
// what to do with err?
}
template.Execute
できればステータス コード 400 などを返しますが、で直接使用すると、これを行う方法がわかりませんResponseWriter
。足りないものはありますか?