seems to work
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-09-28 14:27:03 +10:00
parent 95a48a89a6
commit 6c7d447c56
6 changed files with 162 additions and 61 deletions

View File

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

View File

@@ -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

View File

@@ -263,8 +263,8 @@ type ComputeBoard struct {
type ComputeMbTempStats struct {
XMLName xml.Name `xml:"computeMbTempStats"`
Dn string `xml:"dn,attr,omitempty"`
FmTempSenIo string `xml:"fmTempSenIo,attr,omitempty"`
FmTempSenRear string `xml:"fmTempSenRear,attr,omitempty"`
FmTempSenIo float64 `xml:"fmTempSenIo,attr,omitempty"`
FmTempSenRear float64 `xml:"fmTempSenRear,attr,omitempty"`
}
// MemoryArray represents an array of memory units.