Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
31
pkg/utils/xml_resp.go
Normal file
31
pkg/utils/xml_resp.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user