data.go 640 B

12345678910111213141516171819202122232425
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package render
  5. import "net/http"
  6. // Data contains ContentType and bytes data.
  7. type Data struct {
  8. ContentType string
  9. Data []byte
  10. }
  11. // Render (Data) writes data with custom ContentType.
  12. func (r Data) Render(w http.ResponseWriter) (err error) {
  13. r.WriteContentType(w)
  14. _, err = w.Write(r.Data)
  15. return
  16. }
  17. // WriteContentType (Data) writes custom ContentType.
  18. func (r Data) WriteContentType(w http.ResponseWriter) {
  19. writeContentType(w, []string{r.ContentType})
  20. }