gojek / heimdall

An enhanced HTTP client for Go
http://gojek.tech
Apache License 2.0
2.63k stars 214 forks source link

Allow creating retrier with a function #29

Closed medakk closed 6 years ago

medakk commented 6 years ago

This PR allows you to create a Retrier without creating a struct to satisfy the interface, just a function. Similar to http.Handler and http.HandlerFunc

Example:

linearRetrier := NewRetrierFunc(func(retry int) time.Duration {
    if retry <= 0 {
        return 0 * time.Millisecond
    }
    return time.Duration(retry) * time.Millisecond
})
client := heimdall.NewHTTPClient(timeout)
client.SetRetrier(retrier)
rShetty commented 6 years ago

@medakk Can you add this to docs too ?

medakk commented 6 years ago

Comments for go doc are present. Do you mean the project's README.md?

rShetty commented 6 years ago

@medakk Yes, README

medakk commented 6 years ago

Doc has been added.

rShetty commented 6 years ago

@medakk Thanks will merge.