1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-12 02:28:05 +02:00
kratos/pkg/net/http/blademaster/render/xml.go
2019-04-11 15:07:22 +08:00

32 lines
612 B
Go

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)
}