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.
31 lines
612 B
31 lines
612 B
package render
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// XML common xml struct.
|
|
type XML struct {
|
|
Code int
|
|
Message string
|
|
Data interface{}
|
|
}
|
|
|
|
var xmlContentType = []string{"application/xml; charset=utf-8"}
|
|
|
|
// Render (XML) writes data with xml ContentType.
|
|
func (r XML) Render(w http.ResponseWriter) (err error) {
|
|
r.WriteContentType(w)
|
|
if err = xml.NewEncoder(w).Encode(r.Data); err != nil {
|
|
err = errors.WithStack(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// WriteContentType write xml ContentType.
|
|
func (r XML) WriteContentType(w http.ResponseWriter) {
|
|
writeContentType(w, xmlContentType)
|
|
}
|
|
|