Skip to content

Commit

Permalink
Add httpcache code example to README.md (#2632)
Browse files Browse the repository at this point in the history
  • Loading branch information
madneal authored Jan 18, 2023
1 parent d7134b7 commit ab8b241
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,22 @@ The GitHub API has good support for conditional requests which will help
prevent you from burning through your rate limit, as well as help speed up your
application. `go-github` does not handle conditional requests directly, but is
instead designed to work with a caching `http.Transport`. We recommend using
https://github.com/gregjones/httpcache for that.
https://github.com/gregjones/httpcache for that. For example:

```go
import "github.com/gregjones/httpcache"

ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
tc := &http.Client{
Transport: &oauth2.Transport{
Base: httpcache.NewMemoryCacheTransport(),
Source: ts,
},
}
client := github.NewClient(tc)
```

Learn more about GitHub conditional requests at
https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests.
Expand Down

0 comments on commit ab8b241

Please sign in to comment.