Skip to content

Commit 1af16db

Browse files
committed
add httpcache code sample refer to google#2631
1 parent 34cc7b4 commit 1af16db

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ application. `go-github` does not handle conditional requests directly, but is
211211
instead designed to work with a caching `http.Transport`. We recommend using
212212
https://github.com/gregjones/httpcache for that.
213213

214+
```go
215+
import "github.com/gregjones/httpcache"
216+
217+
ts := oauth2.StaticTokenSource(
218+
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
219+
)
220+
tc := &http.Client{
221+
Transport: &oauth2.Transport{
222+
Base: httpcache.NewMemoryCacheTransport(),
223+
Source: ts,
224+
},
225+
}
226+
client := github.NewClient(tc)
227+
```
228+
229+
214230
Learn more about GitHub conditional requests at
215231
https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests.
216232

0 commit comments

Comments
 (0)