This commit is contained in:
Zeev Diukman 2025-03-06 22:51:45 +00:00
parent 650cd1d241
commit 0b1e005c55

View file

@ -12,8 +12,8 @@ type Router struct {
}
// HostRouter associates a host with a mux.Router.
type HostRouter struct {
Host string
type DomainRouter struct {
Domain string
*mux.Router
}
@ -24,15 +24,15 @@ func NewRouter() *Router {
return r
}
func (r *HostRouter) Handler(handler http.Handler) *mux.Route {
func (r *DomainRouter) Handler(handler http.Handler) *mux.Route {
return r.Router.NewRoute().Handler(handler)
}
// NewHostRouter creates a new HostRouter for a specific host.
func (r *Router) NewHostRouter(host string) *HostRouter {
hostRouter := r.NewRoute().Host(host).Subrouter()
return &HostRouter{
Host: host,
Router: hostRouter,
// NewDomainRouter creates a new DomainRouter for a specific host.
func (r *Router) NewDomainRouter(domain string) *DomainRouter {
domainRouter := r.NewRoute().Host(domain).Subrouter()
return &DomainRouter{
Domain: domain,
Router: domainRouter,
}
}