gin/render/text.go
Manu Mtz-Almeida 2d8f0a4801 Performance improvements when rendering
- Fast path for JSON, XML and plain text rendering
2015-05-07 12:44:52 +02:00

26 lines
569 B
Go

package render
import (
"fmt"
"net/http"
)
type plainTextRender struct{}
func (_ plainTextRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
format := data[0].(string)
values := data[1].([]interface{})
WritePlainText(w, code, format, values)
return nil
}
func WritePlainText(w http.ResponseWriter, code int, format string, values []interface{}) {
WriteHeader(w, code, "text/plain")
// we assume w.Write can not fail, is that right?
if len(values) > 0 {
fmt.Fprintf(w, format, values...)
} else {
w.Write([]byte(format))
}
}