diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-16 15:02:49 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-16 15:02:49 +0200 |
commit | 2ede7f2b2cf2a6b7344b5943a78d7852efa5e025 (patch) | |
tree | 22240dfb90ea9759bcd6ac0e0c5b48b0eb3b1bed | |
parent | a3d0d5f7544fe38ae76438d46c530ce066664865 (diff) |
move errors and responses out of call.go
-rw-r--r-- | call.go | 21 | ||||
-rw-r--r-- | errors.go | 15 | ||||
-rw-r--r-- | response.go | 9 |
3 files changed, 24 insertions, 21 deletions
@@ -3,7 +3,6 @@ package inwx import ( "bytes" "encoding/json" - "fmt" "net" "net/http" ) @@ -21,26 +20,6 @@ type Call interface { expectedStatus() []Status } -// 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"` -} - -// ErrUnexpectedStatus indicates that a Call was responded to -// but the Status doesn't match any of the expected Statuses of the Call. -type ErrUnexpectedStatus struct { - Expected []Status - Got Status -} - -func (e *ErrUnexpectedStatus) Error() string { - const format = "unexpected status code: expected %v, got %v" - return fmt.Sprintf(format, e.Expected, e.Got) -} - // Call sends a Call to the API endpoint and waits for a response or an error. // It returns net.ErrClosed if the Client is closed. func (c *Client) Call(call Call) (*Response, error) { diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..25e9e0c --- /dev/null +++ b/errors.go @@ -0,0 +1,15 @@ +package inwx + +import "fmt" + +// ErrUnexpectedStatus indicates that a Call was responded to +// but the Status doesn't match any of the expected Statuses of the Call. +type ErrUnexpectedStatus struct { + Expected []Status + Got Status +} + +func (e *ErrUnexpectedStatus) Error() string { + const format = "unexpected status code: expected %v, got %v" + return fmt.Sprintf(format, e.Expected, e.Got) +} diff --git a/response.go b/response.go new file mode 100644 index 0000000..aaf256a --- /dev/null +++ b/response.go @@ -0,0 +1,9 @@ +package inwx + +// 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"` +} |