-1

I am new to go and still trying to figure out a few things.

func handler(w http.ResponseWriter, r *http.Request) {
}

Why is w not a pointer and on the other hand r is, since the handler function will end up writing into w and only read from r?

John Difool
  • 5,204
  • 4
  • 40
  • 70

1 Answers1

2

This question has already been answered in this post, but to keep it short.

w http.ResponseWriter is actually an interface that's backed by a non-exported pointer.

Whereas r *http.Request is an actual exposed struct.

I'd recommend following the above link to learn more why this is.

Community
  • 1
  • 1
jacob
  • 4,195
  • 1
  • 21
  • 28