xml.go 739 B

12345678910111213141516171819202122232425262728
  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 (
  6. "encoding/xml"
  7. "net/http"
  8. )
  9. // XML contains the given interface object.
  10. type XML struct {
  11. Data interface{}
  12. }
  13. var xmlContentType = []string{"application/xml; charset=utf-8"}
  14. // Render (XML) encodes the given interface object and writes data with custom ContentType.
  15. func (r XML) Render(w http.ResponseWriter) error {
  16. r.WriteContentType(w)
  17. return xml.NewEncoder(w).Encode(r.Data)
  18. }
  19. // WriteContentType (XML) writes XML ContentType for response.
  20. func (r XML) WriteContentType(w http.ResponseWriter) {
  21. writeContentType(w, xmlContentType)
  22. }