-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on oauth2 package (#96)
The only reason I use this is to set a static header on HTTP requests, but it is easy enough to do this with a custom Transport implementation.
- Loading branch information
Showing
5 changed files
with
34 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
module github.com/bluekeyes/patch2pr | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/bluekeyes/go-gitdiff v0.7.2 | ||
github.com/google/go-github/v60 v60.0.0 | ||
github.com/shurcooL/githubv4 v0.0.0-20210922025249-6831e00d857f | ||
golang.org/x/oauth2 v0.18.0 | ||
) | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/go-querystring v1.1.0 // indirect | ||
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect | ||
golang.org/x/net v0.22.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
golang.org/x/oauth2 v0.19.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package internal | ||
|
||
import "net/http" | ||
|
||
type tokenRoundTripper struct { | ||
base http.RoundTripper | ||
token string | ||
} | ||
|
||
func (trt *tokenRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { | ||
rCopy := r.Clone(r.Context()) | ||
rCopy.Header.Set("Authorization", "Bearer "+trt.token) | ||
return trt.base.RoundTrip(rCopy) | ||
} | ||
|
||
// NewTokenClient returns an [http.Client] that sets the bearer token in the | ||
// Authorization header of all requests. | ||
func NewTokenClient(token string) *http.Client { | ||
return &http.Client{ | ||
Transport: &tokenRoundTripper{ | ||
base: http.DefaultTransport, | ||
token: token, | ||
}, | ||
} | ||
} |