diff --git a/context.go b/context.go index b54db507..1ab182c6 100644 --- a/context.go +++ b/context.go @@ -320,10 +320,8 @@ func (c *Context) XML(code int, obj interface{}) { // Writes the given string into the response body. func (c *Context) String(code int, format string, values ...interface{}) { - c.Render(code, render.String{ - Format: format, - Data: values}, - ) + c.writermem.WriteHeader(code) + render.WriteString(c.Writer, format, values) } // Returns a HTTP redirect to the specific location. diff --git a/render/text.go b/render/text.go index 97d60bb5..22a8c99a 100644 --- a/render/text.go +++ b/render/text.go @@ -18,14 +18,18 @@ type String struct { var plainContentType = []string{"text/plain; charset=utf-8"} func (r String) Render(w http.ResponseWriter) error { + WriteString(w, r.Format, r.Data) + return nil +} + +func WriteString(w http.ResponseWriter, format string, data []interface{}) { header := w.Header() if _, exist := header["Content-Type"]; !exist { header["Content-Type"] = plainContentType } - if len(r.Data) > 0 { - fmt.Fprintf(w, r.Format, r.Data...) + if len(data) > 0 { + fmt.Fprintf(w, format, data...) } else { - io.WriteString(w, r.Format) + io.WriteString(w, format) } - return nil }