data.go
This file
Path
render/data.go
31 lines · 742 bytes · Go
Last changed by
fix(render): write content length in Data.Render (#4206)Denis Galeevbefore adoption5c00df8
History of this fileTake it
1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package render67import (8 "net/http"9 "strconv"10)1112// Data contains ContentType and bytes data.13type Data struct {14 ContentType string15 Data []byte16}1718// Render (Data) writes data with custom ContentType.19func (r Data) Render(w http.ResponseWriter) (err error) {20 r.WriteContentType(w)21 if len(r.Data) > 0 {22 w.Header().Set("Content-Length", strconv.Itoa(len(r.Data)))23 }24 _, err = w.Write(r.Data)25 return26}2728// WriteContentType (Data) writes custom ContentType.29func (r Data) WriteContentType(w http.ResponseWriter) {30 writeContentType(w, []string{r.ContentType})31}