gin/render/data.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

21 lines
462 B
Go

package render
import "net/http"
type dataRender struct{}
func (_ dataRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
contentType := data[0].(string)
bytes := data[1].([]byte)
WriteData(w, code, contentType, bytes)
return nil
}
func WriteData(w http.ResponseWriter, code int, contentType string, data []byte) {
if len(contentType) > 0 {
w.Header().Set("Content-Type", contentType)
}
w.WriteHeader(code)
w.Write(data)
}