Documentation ¶
Index ¶
- type Client
- func (hhc *Client) AddPlugin(p heimdall.Plugin)
- func (hhc *Client) Delete(url string, headers http.Header) (*http.Response, error)
- func (hhc *Client) Do(request *http.Request) (*http.Response, error)
- func (hhc *Client) Get(url string, headers http.Header) (*http.Response, error)
- func (hhc *Client) Patch(url string, body io.Reader, headers http.Header) (*http.Response, error)
- func (hhc *Client) Post(url string, body io.Reader, headers http.Header) (*http.Response, error)
- func (hhc *Client) Put(url string, body io.Reader, headers http.Header) (*http.Response, error)
- type Option
- func WithCommandName(name string) Option
- func WithErrorPercentThreshold(errorPercentThreshold int) Option
- func WithFallbackFunc(fn fallbackFunc) Option
- func WithHTTPClient(client heimdall.Doer) Option
- func WithHTTPTimeout(timeout time.Duration) Option
- func WithHystrixTimeout(timeout time.Duration) Option
- func WithMaxConcurrentRequests(maxConcurrentRequests int) Option
- func WithRequestVolumeThreshold(requestVolumeThreshold int) Option
- func WithRetrier(retrier heimdall.Retriable) Option
- func WithRetryCount(retryCount int) Option
- func WithSleepWindow(sleepWindow int) Option
- func WithStatsDCollector(addr, prefix string) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the hystrix client implementation
type Option ¶
type Option func(*Client)
Option represents the hystrix client options
func WithCommandName ¶
WithCommandName sets the hystrix command name
func WithErrorPercentThreshold ¶
WithErrorPercentThreshold sets hystrix error percent threshold
func WithFallbackFunc ¶
func WithFallbackFunc(fn fallbackFunc) Option
WithFallbackFunc sets the fallback function
func WithHTTPClient ¶
WithHTTPClient sets a custom http client for hystrix client
Example ¶
m := &mockClient{} c := NewClient(WithHTTPClient(m)) req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil) if err != nil { panic(err) } _, _ = c.Do(req)
Output: mock client called
func WithHTTPTimeout ¶
WithHTTPTimeout sets hystrix timeout
Example ¶
c := NewClient(WithHTTPTimeout(5 * time.Second)) req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil) if err != nil { panic(err) } res, err := c.Do(req) if err != nil { panic(err) } fmt.Println("Response status : ", res.StatusCode)
Output: Response status : 200
Example (Expired) ¶
c := NewClient(WithHTTPTimeout(1 * time.Millisecond)) req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil) if err != nil { panic(err) } res, err := c.Do(req) if err != nil { fmt.Println("error:", err) return } fmt.Println("Response status : ", res.StatusCode)
Output:
func WithHystrixTimeout ¶
WithHystrixTimeout sets hystrix timeout
func WithMaxConcurrentRequests ¶
WithMaxConcurrentRequests sets hystrix max concurrent requests
func WithRequestVolumeThreshold ¶
WithRequestVolumeThreshold sets hystrix request volume threshold
func WithRetrier ¶
WithRetrier sets the strategy for retrying
Example ¶
c := NewClient(WithHTTPTimeout(1*time.Millisecond), WithRetryCount(3), WithRetrier(&mockRetrier{})) req, err := http.NewRequest(http.MethodGet, "https://www.link.doesnt.exist.io/", nil) if err != nil { panic(err) } res, err := c.Do(req) if err != nil { fmt.Println("error") return } fmt.Println("Response status : ", res.StatusCode)
Output: retry attempt 0 retry attempt 1 retry attempt 2 retry attempt 3 error
func WithRetryCount ¶
WithRetryCount sets the retry count for the Client
Example ¶
c := NewClient(WithHTTPTimeout(1*time.Millisecond), WithRetryCount(3)) req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil) if err != nil { panic(err) } res, err := c.Do(req) if err != nil { fmt.Println("error:", err) return } fmt.Println("Response status : ", res.StatusCode)
Output:
func WithSleepWindow ¶
WithSleepWindow sets hystrix sleep window
func WithStatsDCollector ¶
WithStatsDCollector exports hystrix metrics to a statsD backend
Example ¶
c := NewClient(WithStatsDCollector("localhost:8125", "myapp.hystrix")) req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil) if err != nil { panic(err) } res, err := c.Do(req) if err != nil { panic(err) } fmt.Println("Response status : ", res.StatusCode)
Output: Response status : 200