refactor/idiomatic-handlers-middlewares #25
Loading…
Reference in New Issue
No description provided.
Delete Branch "refactor/idiomatic-handlers-middlewares"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The
api.Ctx
type has been dropped in favor ofcontext.Context
, we just provide a helpers to fetch values from the context:api.GetRequest(context.Context)
api.GetResponseWriter(context.Context)
api.GetAuth()
Note that the
GetAuth()
returns a pointer, allowing for direct manipulation by middlewares (c.f.WithContext()
).Handlers
Handler signature used to be unclear thus non-idiomatic.
The complete signature has an optional first input argument that is can be provided or omitted at will.
The new signature is uses a mandatory
context.Context
that is from the http.Request:Middlewares
The
api.Adapater
type has been removed in favor of the idiomaticfunc(http.Handler) http.Handler
.Auth middlewares have been replaced by contextual middlewares:
WithAuth()
becomesWithContext()
there is no additional argument all is in the request's context.With()
: standard middlewares wrap the entire http connection these are for logging, recovering, etc.WithContext()
: contextual middlewares only wrap the service handler for the request and has a request's context filled with useful data :api.GetRequest()
,api.GetResponseWriter()
,api.GetAuth()