You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
581 B
30 lines
581 B
package render
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Data common bytes struct.
|
|
type Data struct {
|
|
ContentType string
|
|
Data [][]byte
|
|
}
|
|
|
|
// Render (Data) writes data with custom ContentType.
|
|
func (r Data) Render(w http.ResponseWriter) (err error) {
|
|
r.WriteContentType(w)
|
|
for _, d := range r.Data {
|
|
if _, err = w.Write(d); err != nil {
|
|
err = errors.WithStack(err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// WriteContentType writes data with custom ContentType.
|
|
func (r Data) WriteContentType(w http.ResponseWriter) {
|
|
writeContentType(w, []string{r.ContentType})
|
|
}
|
|
|