You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the HTTP router changes in go1.22, many developers are considering standard library for daily use or production. Although, as of now, NotFound and MethodNotAllowed handlers are hard coded, with no way of change or overriding them.
I propose adding the option to set these two handlers.
Implementation
Referring to my PR (#67970), a new MuxOption type is introduced and two functions called WithNotFoundHandler and WithNotAllowedHandler are added.
Also, function NewServeMux is updated to accept variadic parameter of type MuxOption. This ensures backward compatibility, while allowing for customization.
To make sure the default value of ServeMux is valid as well, findHandler function is updated to use custom handlers if provided, or to use the default handlers otherwise.
The text was updated successfully, but these errors were encountered:
That issue does not suggest a solution. This one offers a clear approach, plus opening the door for more customizations of the ServeMux type in the future.
Proposal Details
With the HTTP router changes in go1.22, many developers are considering standard library for daily use or production. Although, as of now, NotFound and MethodNotAllowed handlers are hard coded, with no way of change or overriding them.
If we look at the
findHandler
function, we see:I propose adding the option to set these two handlers.
Implementation
Referring to my PR (#67970), a new
MuxOption
type is introduced and two functions calledWithNotFoundHandler
andWithNotAllowedHandler
are added.Also, function
NewServeMux
is updated to accept variadic parameter of typeMuxOption
. This ensures backward compatibility, while allowing for customization.To make sure the default value of
ServeMux
is valid as well,findHandler
function is updated to use custom handlers if provided, or to use the default handlers otherwise.The text was updated successfully, but these errors were encountered: