@@ -57,6 +57,7 @@ const (
57
57
ContentType = "Content-Type"
58
58
ContentLength = "Content-Length"
59
59
ContentBinary = "application/octet-stream"
60
+ ContentText = "text/plain"
60
61
ContentJSON = "application/json"
61
62
ContentHTML = "text/html"
62
63
ContentXHTML = "application/xhtml+xml"
@@ -88,6 +89,8 @@ type Render interface {
88
89
XML (status int , v interface {})
89
90
// Data writes the raw byte array to the http.ResponseWriter.
90
91
Data (status int , v []byte )
92
+ // Text writes the given status and plain text to the http.ResponseWriter.
93
+ Text (status int , v string )
91
94
// Error is a convenience function that writes an http status to the http.ResponseWriter.
92
95
Error (status int )
93
96
// Status is an alias for Error (writes an http status to the http.ResponseWriter)
@@ -323,6 +326,14 @@ func (r *renderer) Data(status int, v []byte) {
323
326
r .Write (v )
324
327
}
325
328
329
+ func (r * renderer ) Text (status int , v string ) {
330
+ if r .Header ().Get (ContentType ) == "" {
331
+ r .Header ().Set (ContentType , ContentText + r .compiledCharset )
332
+ }
333
+ r .WriteHeader (status )
334
+ r .Write ([]byte (v ))
335
+ }
336
+
326
337
// Error writes the given HTTP status to the current ResponseWriter
327
338
func (r * renderer ) Error (status int ) {
328
339
r .WriteHeader (status )
0 commit comments