package mux import ( "net/http" "strings" ) func Group(mux *http.ServeMux, prefix string, group func(sm *http.ServeMux), middlewares ...Middleware) { groupMux := http.NewServeMux() group(groupMux) if !strings.HasSuffix(prefix, "/") { prefix += "/" } mux.Handle( prefix, http.StripPrefix(strings.TrimSuffix(prefix, "/"), Use(groupMux, middlewares...)), ) }