mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 06:16:08 +00:00
Handle error from template.Execute
Refactored the function to make the problem more obvious, by using a guard.
This commit is contained in:
parent
c662f0f0de
commit
4f738b462b
@ -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…
x
Reference in New Issue
Block a user