Skip to content

Commit cf77274

Browse files
committed
sub/{play,share}: cleanup uaTransport
Use interface http.RoundTripper instead of forcing expectation of *http.Transport.
1 parent 2b3e0ac commit cf77274

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sub/play/play.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111
)
1212

1313
type uaTransport struct {
14-
*http.Transport
14+
rt http.RoundTripper
1515
UserAgent string
1616
}
1717

1818
func (t *uaTransport) RoundTrip(req *http.Request) (*http.Response, error) {
1919
req.Header.Set("User-Agent", t.UserAgent)
20-
return t.Transport.RoundTrip(req)
20+
return t.rt.RoundTrip(req)
2121
}
2222

2323
func main() {
24-
http.DefaultTransport = &uaTransport{Transport: http.DefaultTransport.(*http.Transport), UserAgent: os.Args[1]}
24+
http.DefaultTransport = &uaTransport{rt: http.DefaultTransport, UserAgent: os.Args[1]}
2525

2626
code, _ := io.ReadAll(os.Stdin)
2727
resp, err := http.PostForm("https://play.golang.org/compile", url.Values{"body": {string(code)}})

sub/share/share.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import (
88
)
99

1010
type uaTransport struct {
11-
*http.Transport
11+
rt http.RoundTripper
1212
UserAgent string
1313
}
1414

1515
func (t *uaTransport) RoundTrip(req *http.Request) (*http.Response, error) {
1616
req.Header.Set("User-Agent", t.UserAgent)
17-
return t.Transport.RoundTrip(req)
17+
return t.rt.RoundTrip(req)
1818
}
1919

2020
func main() {
21-
http.DefaultTransport = &uaTransport{Transport: http.DefaultTransport.(*http.Transport), UserAgent: os.Args[1]}
21+
http.DefaultTransport = &uaTransport{rt: http.DefaultTransport, UserAgent: os.Args[1]}
2222

2323
resp, err := http.Post("https://play.golang.org/share", "text/plain; charset=utf-8", os.Stdin)
2424
if err != nil {

0 commit comments

Comments
 (0)