The following code:
func main() {
resp := &http.Response{
StatusCode: 200,
// ... etc
}
j, err := json.Marshal(struct {
*http.Response
Body []byte
Request *http.Request
}{Response: resp, Body: []byte("ABC")})
if err != nil {
panic(err)
}
fmt.Println(string(j))
}
Works as expected; the http.Request struct contains some fields that can't be marshaled (func, channel), but it overrides the Request field:
% go run test.go
{
[..]
"StatusCode": 200,
[..]
}
But staticcheck errors:
% staticcheck test.go
test.go:15:25: trying to marshal unsupported type func() (io.ReadCloser, error), via x.Request.GetBody (SA1026)
staticcheck (devel, v0.7.0-0.dev.0.20260409232628-ba2c20843b32)
The following code:
Works as expected; the
http.Requeststruct contains some fields that can't be marshaled (func, channel), but it overrides the Request field:But staticcheck errors:
staticcheck (devel, v0.7.0-0.dev.0.20260409232628-ba2c20843b32)