gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

xml.go (730B)


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