I'm new to golang. As the documentation said
Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. The Context should be the first parameter, typically named ctx
but I found, in the typical http request handle function, a http.Request
object has .Context()
method can retrieve the context which http request assoicate with.
So why recommand use context as first parameter in theses function. Is that reasonable in this situation?
I know that is not a restrict rule. But I wan't to know why the HandlerFunc
is func(ResponseWriter, *Request)
instead of func(context.Context, ResponseWriter, *Request)
Apparently, HandlerFunc
break the recommandation.