Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: transport.go: strange assignment func(pc *persistConn) cancelRequest(error) to func(error) #33634

Closed
gdi63 opened this issue Aug 13, 2019 · 1 comment

Comments

@gdi63
Copy link

gdi63 commented Aug 13, 2019

Does it really work? Does func(error) type match to method of persistConn

type Transport struct {
reqCanceler map[*Request]func(error)

func (t *Transport) replaceReqCanceler(r *Request, fn func(error)) bool {
t.reqCanceler[r] = fn

func (pc *persistConn) cancelRequest(err error) {

func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err error) {
if !pc.t.replaceReqCanceler(req.Request, pc.cancelRequest) {

@smasher164
Copy link
Member

Yes, it matches. See https://golang.org/ref/spec#Method_values.
Here is a playground example to demonstrate this behavior: https://play.golang.org/p/yHJtcrG4H0d.
For questions about Go, see https://golang.org/wiki/Questions.

@golang golang locked and limited conversation to collaborators Aug 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants