另客网go项目公用的代码库

xml.go 540B

1234567891011121314151617181920212223242526
  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. type XML struct {
  10. Data interface{}
  11. }
  12. var xmlContentType = []string{"application/xml; charset=utf-8"}
  13. func (r XML) Render(w http.ResponseWriter) error {
  14. r.WriteContentType(w)
  15. return xml.NewEncoder(w).Encode(r.Data)
  16. }
  17. func (r XML) WriteContentType(w http.ResponseWriter) {
  18. writeContentType(w, xmlContentType)
  19. }