Handle error from template.Execute
Refactored the function to make the problem more obvious, by using a guard.
This commit is contained in:
parent
545bd766e7
commit
ff99f6466f
|
@ -169,7 +169,10 @@ type templatedIndexFS struct {
|
|||
|
||||
func (fs *templatedIndexFS) Open(name string) (http.File, error) {
|
||||
file, err := fs.fs.Open(name)
|
||||
if err == nil && name == "/index.html" {
|
||||
if err != nil || name != "/index.html" {
|
||||
return file, err
|
||||
}
|
||||
|
||||
content, _ := ioutil.ReadAll(file)
|
||||
file.Seek(0, 0)
|
||||
t, err := template.New("fmtedindex").Parse(string(content))
|
||||
|
@ -177,12 +180,10 @@ func (fs *templatedIndexFS) Open(name string) (http.File, error) {
|
|||
return nil, err
|
||||
}
|
||||
var out bytes.Buffer
|
||||
err = t.Execute(&out, fs.templateVars())
|
||||
|
||||
file = newTemplatedFile(&out, file)
|
||||
if err := t.Execute(&out, fs.templateVars()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, err
|
||||
return newTemplatedFile(&out, file), nil
|
||||
}
|
||||
|
||||
// endpoint is a Consul-specific HTTP handler that takes the usual arguments in
|
||||
|
|
Loading…
Reference in New Issue