Description
Hi, in short, what I was looking for is to customize some code from the http.Request object. Since it is a struct and the HttpClient.Do() accepts a struct, we can not, if it was an interface it would be possible.
What version of Go are you using (go version
)?
$ go version go version go1.13.8 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
Not Applicable
// CustomReq is a struct that extends http.Request
req := &CustomReq{}
http.Client{}.Do(req)
Well as we know, Golang has limitations towards OOP, so the above code does not work because *CustomRequest is not considered an *http.Request so it can not be passed to the Do() method.
One solution to these problems in Go is using methods that accept an interface and not a Struct.
Is there any chance to make Do accept an interface and not a struct? I am facing the issue of wanting to customize the bytes being sent in a request(overriding Write()) but since the Do() function accepts an interface I just can't do that.
I think it is not that rare to want to implement our own code but at this time the only way I see to achieve this is to implement the "closest" interface which would be the http.RoundTripper, but that would be too much overhead if I only want to customize the bytes being sent in a request.