In Go HTTP handlers, why is the ResponseWriter a value but the Request a pointer?

What you get for w is a pointer to the non exported type http.response but as ResponseWriter is an interface, that’s not visible.

From server.go:

type ResponseWriter interface {
    ...
}

On the other hand, r is a pointer to a concrete struct, hence the need to pass a reference explicitly.

From request.go:

type Request struct {
    ...
}

Leave a Comment

tech