Skip to content

Commit

Permalink
feat: updating the docs for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby committed Nov 15, 2024
1 parent 09f195c commit 49e8441
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,48 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)

## Bridgekeeper is a request throttler for http.Client
## Bridgekeeper is an HTTP Request Limiter and Retrier

Bridgekeeper replaces the hard implementation of `http.Client` with an
implementation of a shared interface such that anything implementing the
`bk.Client` interface can use Bridgekeeper to throttle API requests through
configuration.

### Using Bridgekeeper

```go
go get -u go.devnw.com/bk@latest
go get -u go.devnw.com/bk/v2@latest
```

### Example
### HTTP Client Example

```go
client := bk.New(
ctx, // Your application context
http.DefaultClient, // Your HTTP Client
http.DefaultClient.Do, // Your HTTP Client Do function (http.Client.Do)
time.Millisecond, // Delay between requests
5, // Retry count
10, // Concurrent request limit
http.DefaultClient.Timeout, // Request timeout
)

resp, err := client.Do(http.NewRequest(http.MethodGet, "localhost:5555"))
if err != nil {
log.Fatal(err)
}
```

## Client Interface

Bridgekeeper implements the interface shown below
### HTTP Round Tripper Example

```go
type Client interface {
Do(request *http.Request) (*http.Response, error)
}
client := bk.New(
ctx, // Your application context
http.DefaultTransport.RoundTrip, // Your HTTP Transport
time.Millisecond, // Delay between requests
5, // Retry count
10, // Concurrent request limit
http.DefaultClient.Timeout, // Request timeout
)

resp, err := client.RoundTrip(http.NewRequest(http.MethodGet, "localhost:5555"))
if err != nil {
log.Fatal(err)
}
```

This interface is also implemented by `http.Client`.
> NOTE: Bridgekeeper Returns a Do / RoundTrip Compliant HTTP Client
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ go 1.23
retract v2.0.1

retract v2.0.0

retract v1.0.1

retract v1.0.0

0 comments on commit 49e8441

Please sign in to comment.