Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 38 lines (32 sloc) 0.715 kB
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
1 package mango
2
3 import (
4 "bytes"
9a24a38 @paulbellamy Forgot to include fmt in show_errors.go
authored
5 "fmt"
6d064af @paulbellamy Updating to compile on weekly.2012-03-04
authored
6 "html/template"
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
7 )
8
9 func ShowErrors(templateString string) Middleware {
10 if templateString == "" {
11 templateString = `
12 <html>
13 <body>
14 <p>
3c286b2 @paulbellamy Updating to new templates package for weekly.2011-08-17
authored
15 {{.Error|html}}
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
16 </p>
17 </body>
18 </html>
19 `
20 }
21
3c286b2 @paulbellamy Updating to new templates package for weekly.2011-08-17
authored
22 errorTemplate := template.Must(template.New("error").Parse(templateString))
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
23
24 return func(env Env, app App) (status Status, headers Headers, body Body) {
25 defer func() {
26 if err := recover(); err != nil {
27 buffer := bytes.NewBufferString("")
0cb0a90 @paulbellamy making show_errors more robust
authored
28 errorTemplate.Execute(buffer, struct{ Error string }{fmt.Sprintf("%s", err)})
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
29 status = 500
87f980f @paulbellamy Adding support for multiple headers
authored
30 headers = Headers{}
7f43e5e @paulbellamy Extracting some example middleware into seperate files
authored
31 body = Body(buffer.String())
32 }
33 }()
34
35 return app(env)
36 }
37 }
Something went wrong with that request. Please try again.