cleanup: typo and code

This commit is contained in:
Ankit Patial
2024-10-12 20:57:57 +05:30
parent 8035c6f7af
commit d639ea1b71
2 changed files with 12 additions and 15 deletions

View File

@@ -6,16 +6,12 @@ import (
"strings"
)
const RouteCtxKey = "ServeCTX"
type (
// Router is a wrapper around the go's standard http.ServeMux.
// It's a lean wrapper with methods to make routing easier
Router struct {
mux *http.ServeMux
middlewares []func(http.Handler) http.Handler
}
)
// Router is a wrapper around the go's standard http.ServeMux.
// It's a lean wrapper with methods to make routing easier
type Router struct {
mux *http.ServeMux
middlewares []func(http.Handler) http.Handler
}
func NewRouter() *Router {
return &Router{
@@ -26,7 +22,7 @@ func NewRouter() *Router {
// Use will register middleware(s) with router stack
func (r *Router) Use(h ...func(http.Handler) http.Handler) {
if r == nil {
panic("serve: func Use was called on nil")
panic("mux: func Use was called on nil")
}
r.middlewares = append(r.middlewares, h...)
}
@@ -81,7 +77,7 @@ func (r *Router) Trace(pattern string, h http.HandlerFunc) {
// panics.
func (r *Router) handlerFunc(method, pattern string, h http.HandlerFunc) {
if r == nil {
panic("serve: func Handle() was called on nil")
panic("mux: func Handle() was called on nil")
}
path := fmt.Sprintf("%s %s", method, pattern)
@@ -142,7 +138,7 @@ func (r *Router) Resource(pattern string, fn func(resource *Resource)) {
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if r == nil {
panic("method ServeHTTP called on nil")
panic("mux: method ServeHTTP called on nil")
}
r.mux.ServeHTTP(w, req)