This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -186,8 +185,8 @@ func (c *Client) doRequest(ctx context.Context, in, out interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("doRequest sending following XML request:")
|
||||
fmt.Println(string(data[:]))
|
||||
//fmt.Println("doRequest sending following XML request:")
|
||||
//fmt.Println(string(data[:]))
|
||||
|
||||
r, err := http.NewRequest("POST", c.apiUrl.String(), bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
@@ -209,8 +208,8 @@ func (c *Client) doRequest(ctx context.Context, in, out interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("doRequest received following response:")
|
||||
fmt.Println(string(body[:]))
|
||||
//fmt.Println("doRequest received following response:")
|
||||
//fmt.Println(string(body[:]))
|
||||
|
||||
return xml.Unmarshal(body, &out)
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
// As of now XML marshaling in Go always uses start and end tags,
|
||||
// which results in XML elements like the one below.
|
||||
//
|
||||
// <Person name="me"></Person>
|
||||
// <Person name="me"></Person>
|
||||
//
|
||||
// Above XML elements cannot be parsed by the remote Cisco UCS API endpoint,
|
||||
// and such API calls result in parse error returned to the client.
|
||||
@@ -41,13 +41,15 @@ import (
|
||||
// hopefully one day make into the language as a feature.
|
||||
//
|
||||
// https://groups.google.com/forum/#!topic/golang-nuts/guG6iOCRu08
|
||||
//
|
||||
// Update by Nathan: update regex to also match caret when searching for tags to update
|
||||
func xmlMarshalWithSelfClosingTags(in interface{}) ([]byte, error) {
|
||||
data, err := xml.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`<([^/][\w\s\"\=\-\/]*)>\s*<(\/\w*)>`)
|
||||
re := regexp.MustCompile(`<([^/][\w\s\"\=\-\/\^]*)>\s*<(\/\w*)>`)
|
||||
newData := re.ReplaceAllString(string(data), "<$1/>")
|
||||
|
||||
return []byte(newData), nil
|
||||
|
Reference in New Issue
Block a user