Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
bdd145b0
Commit
bdd145b0
authored
Apr 21, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better error handling when executing templates
parent
0cbaed24
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
middleware/browse/browse.go
middleware/browse/browse.go
+6
-4
middleware/templates/templates.go
middleware/templates/templates.go
+5
-1
No files found.
middleware/browse/browse.go
View file @
bdd145b0
...
...
@@ -3,6 +3,7 @@
package
browse
import
(
"bytes"
"fmt"
"html/template"
"io/ioutil"
...
...
@@ -122,8 +123,6 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
}
defer
file
.
Close
()
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
files
,
err
:=
file
.
Readdir
(
-
1
)
if
err
!=
nil
{
return
http
.
StatusForbidden
,
err
...
...
@@ -182,11 +181,14 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
Items
:
fileinfos
,
}
// TODO: Don't write to w until we know there wasn't an error
err
=
bc
.
Template
.
Execute
(
w
,
listing
)
// TODO: Use pooled buffers to reduce allocations
var
buf
bytes
.
Buffer
err
=
bc
.
Template
.
Execute
(
&
buf
,
listing
)
if
err
!=
nil
{
return
http
.
StatusInternalServerError
,
err
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
buf
.
WriteTo
(
w
)
return
http
.
StatusOK
,
nil
}
...
...
middleware/templates/templates.go
View file @
bdd145b0
package
templates
import
(
"bytes"
"net/http"
"path"
"text/template"
...
...
@@ -47,10 +48,13 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
}
// Execute it
err
=
tpl
.
Execute
(
w
,
ctx
)
// TODO: Use pooled buffers to reduce allocations
var
buf
bytes
.
Buffer
err
=
bc
.
Template
.
Execute
(
&
buf
,
ctx
)
if
err
!=
nil
{
return
http
.
StatusInternalServerError
,
err
}
buf
.
WriteTo
(
w
)
return
http
.
StatusOK
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment