Documentation ¶
Index ¶
- Variables
- func JoinByFormat(data []string, format string) string
- func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
- type CircuitBreakerSettings
- type Client
- type DefaultRetryPolicy
- type HystrixSSEEvent
- type MockClient
- func (_m *MockClient) CreateBook(ctx context.Context, i *models.Book) (*models.Book, error)
- func (_m *MockClient) EXPECT() *_MockClientRecorder
- func (_m *MockClient) GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error)
- func (_m *MockClient) GetBookByID2(ctx context.Context, id string) (*models.Book, error)
- func (_m *MockClient) GetBooks(ctx context.Context, i *models.GetBooksInput) ([]models.Book, error)
- func (_m *MockClient) HealthCheck(ctx context.Context) error
- type NoRetryPolicy
- type RetryPolicy
- type WagClient
- func (c *WagClient) CreateBook(ctx context.Context, i *models.Book) (*models.Book, 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) SetCircuitBreakerDebug(b bool)
- func (c *WagClient) SetCircuitBreakerSettings(settings CircuitBreakerSettings)
- func (c *WagClient) WithRetryPolicy(retryPolicy RetryPolicy) *WagClient
- func (c *WagClient) WithTimeout(timeout time.Duration) *WagClient
Constants ¶
This section is empty.
Variables ¶
var DefaultCircuitBreakerSettings = CircuitBreakerSettings{
MaxConcurrentRequests: 100,
RequestVolumeThreshold: 20,
SleepWindow: 5000,
ErrorPercentThreshold: 90,
}
DefaultCircuitBreakerSettings describes the default circuit parameters.
Functions ¶
func JoinByFormat ¶
JoinByFormat joins a string array by a known format:
csv: comma separated value (default) ssv: space separated value tsv: tab separated value pipes: pipe (|) separated value
func WithRetryPolicy ¶ added in v0.2.0
func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
WithRetryPolicy returns a new context that overrides the client object's retry policy.
Types ¶
type CircuitBreakerSettings ¶ added in v0.1.3
type CircuitBreakerSettings struct { // MaxConcurrentRequests is the maximum number of concurrent requests // the client can make at the same time. Default: 100. MaxConcurrentRequests int // RequestVolumeThreshold is the minimum number of requests needed // before a circuit can be tripped due to health. Default: 20. RequestVolumeThreshold int // SleepWindow how long, in milliseconds, to wait after a circuit opens // before testing for recovery. Default: 5000. SleepWindow int // ErrorPercentThreshold is the threshold to place on the rolling error // rate. Once the error rate exceeds this percentage, the circuit opens. // Default: 90. ErrorPercentThreshold int }
CircuitBreakerSettings are the parameters that govern the client's circuit breaker.
type Client ¶
type Client interface { // GetBooks makes a GET request to /books. // Returns a list of books GetBooks(ctx context.Context, i *models.GetBooksInput) ([]models.Book, error) // CreateBook makes a POST request to /books. // Creates a book CreateBook(ctx context.Context, i *models.Book) (*models.Book, error) // GetBookByID makes a GET request to /books/{book_id}. // Returns a book GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error) // GetBookByID2 makes a GET request to /books2/{id}. // Retrieve a book GetBookByID2(ctx context.Context, id string) (*models.Book, error) // HealthCheck makes a GET request to /health/check. HealthCheck(ctx context.Context) error }
Client defines the methods available to clients of the swagger-test service.
type DefaultRetryPolicy ¶ added in v0.2.0
type DefaultRetryPolicy struct{}
DefaultRetryPolicy defines the default retry policy.
func (DefaultRetryPolicy) Backoffs ¶ added in v0.2.0
func (DefaultRetryPolicy) 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 HystrixSSEEvent ¶ added in v0.1.3
type HystrixSSEEvent struct { Type string `json:"type"` Name string `json:"name"` RequestCount int `json:"requestCount"` ErrorCount int `json:"errorCount"` ErrorPercentage int `json:"errorPercentage"` IsCircuitBreakerOpen bool `json:"isCircuitBreakerOpen"` RollingCountFailure int `json:"rollingCountFailure"` RollingCountFallbackFailure int `json:"rollingCountFallbackFailure"` RollingCountFallbackSuccess int `json:"rollingCountFallbackSuccess"` RollingCountShortCircuited int `json:"rollingCountShortCircuited"` RollingCountSuccess int `json:"rollingCountSuccess"` RollingCountThreadPoolRejected int `json:"rollingCountThreadPoolRejected"` RollingCountTimeout int `json:"rollingCountTimeout"` CurrentConcurrentExecutionCount int `json:"currentConcurrentExecutionCount"` LatencyTotalMean int `json:"latencyTotal_mean"` }
HystrixSSEEvent is emitted by hystrix-go via server-sent events. It describes the state of a circuit.
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
Mock of Client interface
func NewMockClient ¶
func NewMockClient(ctrl *gomock.Controller) *MockClient
func (*MockClient) CreateBook ¶
func (*MockClient) EXPECT ¶
func (_m *MockClient) EXPECT() *_MockClientRecorder
func (*MockClient) GetBookByID ¶
func (_m *MockClient) GetBookByID(ctx context.Context, i *models.GetBookByIDInput) (*models.Book, error)
func (*MockClient) GetBookByID2 ¶
func (*MockClient) GetBooks ¶
func (_m *MockClient) GetBooks(ctx context.Context, i *models.GetBooksInput) ([]models.Book, error)
func (*MockClient) HealthCheck ¶
func (_m *MockClient) HealthCheck(ctx context.Context) error
type NoRetryPolicy ¶ added in v0.2.0
type NoRetryPolicy struct{}
NoRetryPolicy defines a policy of never retrying a request.
func (NoRetryPolicy) Backoffs ¶ added in v0.2.0
func (NoRetryPolicy) Backoffs() []time.Duration
Backoffs returns an empty slice.
type RetryPolicy ¶ added in v0.2.0
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 WagClient ¶
type WagClient struct {
// contains filtered or unexported fields
}
WagClient is used to make requests to the swagger-test service.
func NewFromDiscovery ¶
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.
func (*WagClient) CreateBook ¶
CreateBook makes a POST request to /books. Creates a book
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
func (*WagClient) GetBookByID2 ¶
GetBookByID2 makes a GET request to /books2/{id}. Retrieve a book
func (*WagClient) HealthCheck ¶
HealthCheck makes a GET request to /health/check.
func (*WagClient) SetCircuitBreakerDebug ¶ added in v0.1.3
SetCircuitBreakerDebug puts the circuit
func (*WagClient) SetCircuitBreakerSettings ¶ added in v0.1.3
func (c *WagClient) SetCircuitBreakerSettings(settings CircuitBreakerSettings)
SetCircuitBreakerSettings sets parameters on the circuit breaker. It must be called on application startup.
func (*WagClient) WithRetryPolicy ¶ added in v0.2.0
func (c *WagClient) WithRetryPolicy(retryPolicy RetryPolicy) *WagClient
WithRetryPolicy returns a new client that will use the given retry policy for all requests.
func (*WagClient) WithTimeout ¶
WithTimeout returns a new client that has the specified timeout on all operations. To make a single request have a timeout use context.WithTimeout as described here: https://godoc.org/golang.org/x/net/context#WithTimeout.