Files
cloud-services/pkg/utils/xml_resp.go

32 lines
677 B
Go

package utils
import (
"encoding/xml"
"net/http"
"fiskerinc.com/modules/common"
)
// ErrorXMLResult makes error result
func ErrorXMLResult(status int, message string) common.XMLError {
return common.XMLError{
Error: http.StatusText(status),
Message: message,
}
}
// RespXML sends back XML response.
func RespXML(w http.ResponseWriter, status int, resp interface{}) {
js, _ := xml.Marshal(resp)
w.Header().Set("Content-Type", "application/xml")
w.WriteHeader(status)
w.Write(js)
}
// RespXMLError XML error response
func RespXMLError(w http.ResponseWriter, status int, message string) {
resp := ErrorXMLResult(status, message)
RespXML(w, status, &resp)
}