aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2022-10-16 16:50:36 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2022-10-16 16:50:36 +0200
commit16d003364f28d781d17c50ae00ab3937f526019c (patch)
tree33657c862ce672b6d35d7cf9528bf177ee4a5b42
parent88b7b17a278f8cd0c8a3f269ec05990bd2863d5e (diff)
enable easy response data access
-rw-r--r--call.go2
-rw-r--r--response.go11
2 files changed, 10 insertions, 3 deletions
diff --git a/call.go b/call.go
index 547141f..54a3ba3 100644
--- a/call.go
+++ b/call.go
@@ -49,7 +49,7 @@ func (c *Client) Call(call Call) (*Response, error) {
return nil, err
}
- response := &Response{}
+ response := &Response{Data: &json.RawMessage{}}
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
return nil, err
}
diff --git a/response.go b/response.go
index aaf256a..fc9859f 100644
--- a/response.go
+++ b/response.go
@@ -1,9 +1,16 @@
package inwx
+import "encoding/json"
+
// A Response contains the Status of a response to a Call
// as well as the response parameters.
// Data is nil if there are no response parameters.
type Response struct {
- StatusCode Status `json:"code"`
- Data any `json:"resData"`
+ StatusCode Status `json:"code"`
+ Data *json.RawMessage `json:"resData"`
+}
+
+// Into unmarshals the Response into a Call specific response struct.
+func (r *Response) Into(resp any) error {
+ return json.Unmarshal(*r.Data, resp)
}