Refactors render.go
This commit is contained in:
parent
615c62d736
commit
8f31fbc502
@ -17,28 +17,21 @@ type (
|
|||||||
Render(http.ResponseWriter, int, ...interface{}) error
|
Render(http.ResponseWriter, int, ...interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON binding
|
|
||||||
jsonRender struct{}
|
jsonRender struct{}
|
||||||
|
|
||||||
// XML binding
|
|
||||||
xmlRender struct{}
|
xmlRender struct{}
|
||||||
|
|
||||||
// Plain text
|
plainTextRender struct{}
|
||||||
plainRender struct{}
|
|
||||||
|
|
||||||
// HTML Plain text
|
|
||||||
htmlPlainRender struct{}
|
htmlPlainRender struct{}
|
||||||
|
|
||||||
// Redirects
|
|
||||||
redirectRender struct{}
|
redirectRender struct{}
|
||||||
|
|
||||||
// Redirects
|
|
||||||
htmlDebugRender struct {
|
htmlDebugRender struct {
|
||||||
files []string
|
files []string
|
||||||
globs []string
|
globs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// form binding
|
|
||||||
HTMLRender struct {
|
HTMLRender struct {
|
||||||
Template *template.Template
|
Template *template.Template
|
||||||
}
|
}
|
||||||
@ -47,8 +40,8 @@ type (
|
|||||||
var (
|
var (
|
||||||
JSON = jsonRender{}
|
JSON = jsonRender{}
|
||||||
XML = xmlRender{}
|
XML = xmlRender{}
|
||||||
Plain = plainRender{}
|
|
||||||
HTMLPlain = htmlPlainRender{}
|
HTMLPlain = htmlPlainRender{}
|
||||||
|
Plain = plainTextRender{}
|
||||||
Redirect = redirectRender{}
|
Redirect = redirectRender{}
|
||||||
HTMLDebug = &htmlDebugRender{}
|
HTMLDebug = &htmlDebugRender{}
|
||||||
)
|
)
|
||||||
@ -76,17 +69,16 @@ func (_ xmlRender) Render(w http.ResponseWriter, code int, data ...interface{})
|
|||||||
return encoder.Encode(data[0])
|
return encoder.Encode(data[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ plainRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
|
func (_ plainTextRender) Render(w http.ResponseWriter, code int, data ...interface{}) (err error) {
|
||||||
writeHeader(w, code, "text/plain")
|
writeHeader(w, code, "text/plain")
|
||||||
format := data[0].(string)
|
format := data[0].(string)
|
||||||
args := data[1].([]interface{})
|
args := data[1].([]interface{})
|
||||||
var err error
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
_, err = w.Write([]byte(fmt.Sprintf(format, args...)))
|
_, err = w.Write([]byte(fmt.Sprintf(format, args...)))
|
||||||
} else {
|
} else {
|
||||||
_, err = w.Write([]byte(format))
|
_, err = w.Write([]byte(format))
|
||||||
}
|
}
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ htmlPlainRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
|
func (_ htmlPlainRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user