Handle error from template.Execute

Refactored the function to make the problem more obvious, by using a
guard.
pull/7894/head
Daniel Nephin 5 years ago
parent c662f0f0de
commit 4f738b462b

@ -169,20 +169,21 @@ type templatedIndexFS struct {
func (fs *templatedIndexFS) Open(name string) (http.File, error) {
file, err := fs.fs.Open(name)
if err == nil && name == "/index.html" {
content, _ := ioutil.ReadAll(file)
file.Seek(0, 0)
t, err := template.New("fmtedindex").Parse(string(content))
if err != nil {
return nil, err
}
var out bytes.Buffer
err = t.Execute(&out, fs.templateVars())
file = newTemplatedFile(&out, file)
if err != nil || name != "/index.html" {
return file, err
}
return file, err
content, _ := ioutil.ReadAll(file)
file.Seek(0, 0)
t, err := template.New("fmtedindex").Parse(string(content))
if err != nil {
return nil, err
}
var out bytes.Buffer
if err := t.Execute(&out, fs.templateVars()); err != nil {
return nil, err
}
return newTemplatedFile(&out, file), nil
}
// endpoint is a Consul-specific HTTP handler that takes the usual arguments in

Loading…
Cancel
Save