Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // GetMethod is a wrapper with expected status codes around the HTTP "GET" method GetMethod = Method{Method: "GET", ExpectedStatusCodes: []int{200}} // PostMethod is a wrapper with expected status codes around the HTTP "POST" method PostMethod = Method{Method: "POST", ExpectedStatusCodes: []int{200, 201}} // PutMethod is a wrapper with expected status codes around the HTTP "PUT" method PutMethod = Method{Method: "PUT", ExpectedStatusCodes: []int{204}} // PatchMethod is a wrapper with expected status codes around the HTTP "PATCH" method PatchMethod = Method{Method: "PATCH", ExpectedStatusCodes: []int{204}} // DeleteMethod is a wrapper with expected status codes around the HTTP "DELETE" method DeleteMethod = Method{Method: "DELETE", ExpectedStatusCodes: []int{204}} )
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date is defined because the transip api server returns date strings, not parsed by golang by default. So we need to do manual time parsing, by defining our own date struct encapsulating time.Time.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON parses date strings returned by the transip api
type Error ¶
type Error struct { // Message contains the error from the api as a string Message string `json:"error"` // StatusCode contains a HTTP status code that the api server responded with StatusCode int }
Error is used to unpack every error returned by the api
type Method ¶
type Method struct { // Method is where a HTTP method like "GET" would go Method string // ExpectedStatusCodes are the expected status codes with which // you can check if the response status code is correct ExpectedStatusCodes []int }
Method is a struct which is used by the client to present a HTTP method of choice and the expected return status codes on which you can check to see if the response is correct, thus not an error.
func (*Method) StatusCodeOK ¶
StatusCodeOK returns true when the status code is correct This method used by the rest client to check if the given status code is correct.
type Request ¶
type Request struct { // Endpoint is the api endpoint, without the server, which we will receive the request, // like: '/products' Endpoint string // Parameters is a map of strings (url.Values) that will be used to add // http query strings to the request, like '/domains?tags=123' Parameters url.Values // Body is left as an interface because the Request is not coupled to any specific Request.Body struct Body interface{} // TestMode is used when users want to tinker with the api without touching their real data TestMode bool }
Request will be used by all repositories and the client. The Request struct can be transformed to a http request with method, url and optional body.
func (*Request) GetBodyReader ¶
GetBodyReader returns an io.Reader for the json marshalled body of this request this will be used by the writer used in the client.
func (*Request) GetHTTPRequest ¶
GetHTTPRequest generates and returns a http.Request object. It does this with the Request struct and the basePath and method, that are provided by the client itself.
func (*Request) GetJSONBody ¶
GetJSONBody returns the request object as a json byte array
type Response ¶
Response will contain a body (which can be empty), status code and the Method. This struct will be used to decode a response from the api server.
func (*Response) ParseResponse ¶
ParseResponse will convert a Response struct to the given interface. When the rest response has no body it will return without filling the dest variable.
type Time ¶
Time is defined because the transip api server does not return a rfc 3339 time string and golang requires this. So we need to do manual time parsing, by defining our own time struct encapsulating time.Time.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON parses datetime strings returned by the transip api