Steelix is an HTTP client reinforcement using resiliency strategy.
Steelix wraps native golang HTTP client with some resiliency strategies. There are two resiliency strategies available, retry and circuit breaker.
go get -u github.com/indrasaputra/steelix
Struct steelix.Client
wraps http.Client
. Therefore, users should prepare their own http.Client
, then use constructor to create an instance of steelix.Client
.
To use retry and circuit breaker strategy, provide the respective configurations.
For more information, visit documentation in godoc.
package main
import (
"net/http"
"time"
"github.com/indrasaputra/backoff"
"github.com/indrasaputra/steelix"
)
func main() {
b := &backoff.ConstantBackoff{
BackoffInterval: 200 * time.Millisecond,
JitterInterval: 50 * time.Millisecond,
}
rc := &steelix.RetryConfig{
Backoff: b,
MaxRetry: 3,
}
bc := &steelix.BreakerConfig{
Name: "steelix-breaker",
MinRequests: 10,
MinConsecutiveFailures: 5,
FailurePercentage: 20,
}
client := steelix.NewClient(http.DefaultClient, rc, bc)
// omitted
}
Then, use Do(req *http.Request)
method to send an HTTP request.
req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080", nil)
resp, err := client.Do(req)