Skip to content
This repository was archived by the owner on Jul 29, 2023. It is now read-only.
This repository was archived by the owner on Jul 29, 2023. It is now read-only.

Discussion: Subrouting #12

@moraes

Description

@moraes

I detected two kinds of subrouting that we may want to support:

  1. Convenience setup for path and name prefix: when defining several routes that share a path or name prefix, it is nice to have a way to define the shared prefix once, then define the remaining based on that "subroute". It's avoids repeating yourself and also makes a bit easier to refactor a route setup;
  2. Mount (or "import") routes defined in a different package: as requested in Feature proposal: Better router/handler composition (*Router.Mount()) mux#136, this allows packages to define their routes independently. Then a main package imports the defined routers or setup mounting points for them;

These are somewhat related. The first one is simply "nice to have"; the second is not a so common use case, but why not? In any case, the first can be used by the second when mounting a foreign router in a given path. The docs for Mount() illustrate it better:

// Mount imports all routes from the given router into this one.
//
// Combined with Sub() and Name(), it is possible to submount a router
// defined in a different package using pattern and name prefixes:
//
//     r := New()
//     s := r.Sub("/admin").Name("admin:").Mount(admin.Router)
func (r *Router) Mount(router *Router) *Router {

These two kinds of subrouting require the three router methods exemplified in the docs above: Sub() (which creates a subrouter for a pattern prefix), Name() (sets a name prefix for the routes), and Mount() (imports routes defined elsewhere).

Given this initial draft, I invite you to share your thoughts about the subject.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions