Documentation
¶
Overview ¶
Package response provides the Responder interface for (*voki.Voki).CallResponder
Custom response types should be declared for specific API endpoints.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Responder ¶
type Responder interface {
Respond() Responder
}
Responder is used to define objects that can be unmarshalled into by (*voki.Voki).CallResponder.
type Response ¶
Response declares fields used by most of my API servers.
They will probably not apply to your environment, if so declare structs that implement the Responder interface, so that you can use them with (*voki.Voki).CallResponder.
Example:
// Instantiate a new *http.Client
client := http.DefaultClient
defer client.CloseIdleConnections()
// Instantiate a new *voki.Voki.
v := voki.New(client, ...) // Replace ... with your API server details
// MyResponse must match some or all of the fields returned by the API
// endpoint
type MyResponse struct {
response.Response
Data struct {
MyString string
}
}
var myResponse MyResponse
// Replace "/v1/myresource" by the API endpoint you are trying to reach
// relative to the connection informations defined in voki.New(...).
//
// Note that in this case, calling v.CallResponder and v.Unmarshal
// accomplishes the same goal, but only because MyResponse implements
// response.Responder.
if err := v.CallResponder(http.MethodGet, "/v1/myresource", nil, false, &myResponse); err != nil {
log.Fatal(err)
}
fmt.Println(myResponse.StatusCode) // Output: 200
type ResponseWithError ¶ added in v1.2.0
Click to show internal directories.
Click to hide internal directories.