diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-16 16:50:36 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-16 16:50:36 +0200 |
commit | 16d003364f28d781d17c50ae00ab3937f526019c (patch) | |
tree | 33657c862ce672b6d35d7cf9528bf177ee4a5b42 | |
parent | 88b7b17a278f8cd0c8a3f269ec05990bd2863d5e (diff) |
enable easy response data access
-rw-r--r-- | call.go | 2 | ||||
-rw-r--r-- | response.go | 11 |
2 files changed, 10 insertions, 3 deletions
@@ -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) } |