go-router/router.go
Zeev Diukman 05c91a474e 4
2025-03-08 17:51:19 +00:00

50 lines
1 KiB
Go

package router
import (
"net/http"
"github.com/gorilla/mux"
)
// Router wraps the mux.Router to provide additional functionality.
type Router struct {
*mux.Router
}
// HostRouter associates a host with a mux.Router.
type DomainRouter struct {
Domain string
*mux.Router
}
// NewRouter creates and returns a new Router with strict slash behavior.
func NewRouter() *Router {
r := &Router{}
r.Router = mux.NewRouter().StrictSlash(true)
return r
}
func (r *DomainRouter) Handler(handler http.Handler) *mux.Route {
return r.Router.NewRoute().Handler(handler)
}
// NewDomainRouter creates a new DomainRouter for a specific host.
// func (r *Router) NewHostRouter(domain string, rule string) *DomainRouter {
// domainRouter := &DomainRouter{
// Domain: "",
// Router: nil,
// }
// switch rule {
// case "Domain":
// {
// domainRouter.Router = r.NewRoute().Host(domain).Subrouter()
// }
// default:
// {
// domainRouter.Router = r.NewRoute().Host(domain).Subrouter()
// }
// }
// return domainRouter
// }