From 32b2fc73955109717f33f71762071810e179ea9e Mon Sep 17 00:00:00 2001 From: madneal Date: Wed, 18 Jan 2023 22:05:54 +0800 Subject: [PATCH 1/2] add httpcache code sample refer to #2631 --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 030fd090d9a..7824d35038f 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,22 @@ 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. +```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. From 1af16dbffcc112403b22c52218c4bc8498666a6d Mon Sep 17 00:00:00 2001 From: madneal Date: Wed, 18 Jan 2023 22:05:54 +0800 Subject: [PATCH 2/2] add httpcache code sample refer to #2631 --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 030fd090d9a..7824d35038f 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,22 @@ 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. +```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.