Documentation
¶
Index ¶
- Constants
- func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
- type Client
- type ExponentialRetryPolicy
- type GetAuthorsIter
- type GetAuthorsWithPutIter
- type GetBooksIter
- type NoRetryPolicy
- type RetryPolicy
- type SingleRetryPolicy
- type WagClient
- func (c *WagClient) CreateBook(ctx context.Context, i *models.Book) (*models.Book, error)
- func (c *WagClient) GetAuthors(ctx context.Context, i *models.GetAuthorsInput) (*models.AuthorsResponse, error)
- func (c *WagClient) GetAuthorsWithPut(ctx context.Context, i *models.GetAuthorsWithPutInput) (*models.AuthorsResponse, error)
- func (c *WagClient) GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error)
- func (c *WagClient) GetBookByID2(ctx context.Context, id string) (*models.Book, error)
- func (c *WagClient) GetBooks(ctx context.Context, i *models.GetBooksInput) ([]models.Book, error)
- func (c *WagClient) HealthCheck(ctx context.Context) error
- func (c *WagClient) LowercaseModelsTest(ctx context.Context, i *models.LowercaseModelsTestInput) error
- func (c *WagClient) NewGetAuthorsIter(ctx context.Context, i *models.GetAuthorsInput) (GetAuthorsIter, error)
- func (c *WagClient) NewGetAuthorsWithPutIter(ctx context.Context, i *models.GetAuthorsWithPutInput) (GetAuthorsWithPutIter, error)
- func (c *WagClient) NewGetBooksIter(ctx context.Context, i *models.GetBooksInput) (GetBooksIter, error)
- func (c *WagClient) PutBook(ctx context.Context, i *models.Book) (*models.Book, error)
- func (c *WagClient) SetLogger(l wcl.WagClientLogger)
- func (c *WagClient) SetRetryPolicy(retryPolicy RetryPolicy)
- func (c *WagClient) SetTimeout(timeout time.Duration)
Constants ¶
const Version = "9.0.0"
Version of the client.
const VersionHeader = "X-Client-Version"
VersionHeader is sent with every request.
Variables ¶
This section is empty.
Functions ¶
func WithRetryPolicy ¶
func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
WithRetryPolicy returns a new context that overrides the client object's retry policy.
Types ¶
type Client ¶
type Client interface { // GetAuthors makes a GET request to /authors // Gets authors // 200: *models.AuthorsResponse // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetAuthors(ctx context.Context, i *models.GetAuthorsInput) (*models.AuthorsResponse, error) NewGetAuthorsIter(ctx context.Context, i *models.GetAuthorsInput) (GetAuthorsIter, error) // GetAuthorsWithPut makes a PUT request to /authors // Gets authors, but needs to use the body so it's a PUT // 200: *models.AuthorsResponse // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetAuthorsWithPut(ctx context.Context, i *models.GetAuthorsWithPutInput) (*models.AuthorsResponse, error) NewGetAuthorsWithPutIter(ctx context.Context, i *models.GetAuthorsWithPutInput) (GetAuthorsWithPutIter, error) // GetBooks makes a GET request to /books // Returns a list of books // 200: []models.Book // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetBooks(ctx context.Context, i *models.GetBooksInput) ([]models.Book, error) NewGetBooksIter(ctx context.Context, i *models.GetBooksInput) (GetBooksIter, error) // CreateBook makes a POST request to /books // Creates a book // 200: *models.Book // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. CreateBook(ctx context.Context, i *models.Book) (*models.Book, error) // PutBook makes a PUT request to /books // Puts a book // 200: *models.Book // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. PutBook(ctx context.Context, i *models.Book) (*models.Book, error) // GetBookByID makes a GET request to /books/{book_id} // Returns a book // 200: *models.Book // 400: *models.BadRequest // 401: *models.Unathorized // 404: *models.Error // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error) // GetBookByID2 makes a GET request to /books2/{id} // Retrieve a book // 200: *models.Book // 400: *models.BadRequest // 404: *models.Error // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetBookByID2(ctx context.Context, id string) (*models.Book, error) // HealthCheck makes a GET request to /health/check // // 200: nil // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. HealthCheck(ctx context.Context) error // LowercaseModelsTest makes a POST request to /lowercaseModelsTest/{pathParam} // testing that we can use a lowercase name for a model // 200: nil // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. LowercaseModelsTest(ctx context.Context, i *models.LowercaseModelsTestInput) error }
Client defines the methods available to clients of the swagger-test service.
type ExponentialRetryPolicy ¶
type ExponentialRetryPolicy struct{}
ExponentialRetryPolicy defines an exponential retry policy
func (ExponentialRetryPolicy) Backoffs ¶
func (ExponentialRetryPolicy) Backoffs() []time.Duration
Backoffs returns five backoffs with exponentially increasing wait times between requests: 100, 200, 400, 800, and 1600 milliseconds +/- up to 5% jitter.
type GetAuthorsIter ¶
GetAuthorsIter defines the methods available on GetAuthors iterators.
type GetAuthorsWithPutIter ¶
GetAuthorsWithPutIter defines the methods available on GetAuthorsWithPut iterators.
type GetBooksIter ¶
GetBooksIter defines the methods available on GetBooks iterators.
type NoRetryPolicy ¶
type NoRetryPolicy struct{}
NoRetryPolicy defines a policy of never retrying a request.
func (NoRetryPolicy) Backoffs ¶
func (NoRetryPolicy) Backoffs() []time.Duration
Backoffs returns an empty slice.
type RetryPolicy ¶
type RetryPolicy interface { // Backoffs returns the number and timing of retry attempts. Backoffs() []time.Duration // Retry receives the http request, as well as the result of // net/http.Client's `Do` method. Retry(*http.Request, *http.Response, error) bool }
RetryPolicy defines a retry policy.
type SingleRetryPolicy ¶
type SingleRetryPolicy struct{}
SingleRetryPolicy defines a retry that retries a request once
func (SingleRetryPolicy) Backoffs ¶
func (SingleRetryPolicy) Backoffs() []time.Duration
Backoffs returns that you should retry the request 1second after it fails.
type WagClient ¶
type WagClient struct {
// contains filtered or unexported fields
}
WagClient is used to make requests to the swagger-test service.
func New ¶
func New(basePath string, logger wcl.WagClientLogger, transport *http.RoundTripper) *WagClient
New creates a new client. The base path, logger, and http transport are configurable. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.
func NewFromDiscovery ¶
func NewFromDiscovery(logger wcl.WagClientLogger, transport *http.RoundTripper) (*WagClient, error)
NewFromDiscovery creates a client from the discovery environment variables. This method requires the three env vars: SERVICE_SWAGGER_TEST_HTTP_(HOST/PORT/PROTO) to be set. Otherwise it returns an error. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.
func (*WagClient) CreateBook ¶
CreateBook makes a POST request to /books Creates a book 200: *models.Book 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) GetAuthors ¶
func (c *WagClient) GetAuthors(ctx context.Context, i *models.GetAuthorsInput) (*models.AuthorsResponse, error)
GetAuthors makes a GET request to /authors Gets authors 200: *models.AuthorsResponse 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) GetAuthorsWithPut ¶
func (c *WagClient) GetAuthorsWithPut(ctx context.Context, i *models.GetAuthorsWithPutInput) (*models.AuthorsResponse, error)
GetAuthorsWithPut makes a PUT request to /authors Gets authors, but needs to use the body so it's a PUT 200: *models.AuthorsResponse 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) GetBookByID ¶
func (c *WagClient) GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error)
GetBookByID makes a GET request to /books/{book_id} Returns a book 200: *models.Book 400: *models.BadRequest 401: *models.Unathorized 404: *models.Error 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) GetBookByID2 ¶
GetBookByID2 makes a GET request to /books2/{id} Retrieve a book 200: *models.Book 400: *models.BadRequest 404: *models.Error 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) GetBooks ¶
GetBooks makes a GET request to /books Returns a list of books 200: []models.Book 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) HealthCheck ¶
HealthCheck makes a GET request to /health/check
200: nil 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) LowercaseModelsTest ¶
func (c *WagClient) LowercaseModelsTest(ctx context.Context, i *models.LowercaseModelsTestInput) error
LowercaseModelsTest makes a POST request to /lowercaseModelsTest/{pathParam} testing that we can use a lowercase name for a model 200: nil 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) NewGetAuthorsIter ¶
func (c *WagClient) NewGetAuthorsIter(ctx context.Context, i *models.GetAuthorsInput) (GetAuthorsIter, error)
NewgetAuthorsIter constructs an iterator that makes calls to getAuthors for each page.
func (*WagClient) NewGetAuthorsWithPutIter ¶
func (c *WagClient) NewGetAuthorsWithPutIter(ctx context.Context, i *models.GetAuthorsWithPutInput) (GetAuthorsWithPutIter, error)
NewgetAuthorsWithPutIter constructs an iterator that makes calls to getAuthorsWithPut for each page.
func (*WagClient) NewGetBooksIter ¶
func (c *WagClient) NewGetBooksIter(ctx context.Context, i *models.GetBooksInput) (GetBooksIter, error)
NewgetBooksIter constructs an iterator that makes calls to getBooks for each page.
func (*WagClient) PutBook ¶
PutBook makes a PUT request to /books Puts a book 200: *models.Book 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) SetLogger ¶
func (c *WagClient) SetLogger(l wcl.WagClientLogger)
SetLogger allows for setting a custom logger
func (*WagClient) SetRetryPolicy ¶
func (c *WagClient) SetRetryPolicy(retryPolicy RetryPolicy)
SetRetryPolicy sets a the given retry policy for all requests.
func (*WagClient) SetTimeout ¶
SetTimeout sets a timeout on all operations for the client. To make a single request with a shorter timeout than the default on the client, use context.WithTimeout as described here: https://godoc.org/golang.org/x/net/context#WithTimeout.