Import Routes from one App/package into main App/package( like Django Url Imports)


In Django it is easy to import all Urls from one app into main App i.e

url(r"^my_route_path/", include("app.urls")),

I want to do something similar with echo to make it truly robust and re-use my web packages easily. Given a package that already has routes, i want to be able to import those routes easily.
I already can import handlers but it is not very efficient and is very similar to importing Django views.

url(r'^$', views.index, name='index'),

Golang Echo:

e.GET("/", myauth.Index).Name = "IndexUrl"

I am advocating for something similar to
Echo#Group(prefix string, m ...Middleware) *Group

for example:

Echo#GroupRoutes(prefix string, Echo#Routes() []*Route) 

and usage:

e.GroupRoutes("/myauth", myApp.Echo.Routes())

A similar question was asked here How to load routes from a JSON file? and i suppose it would take similar steps to implement it i.e.
Possible solutions

Should this be implemented as middleware? or stand-alone Echo function?
Please enlighten me on how to proceed with this.


@vishr, can you please explain to me what is going on in the “name” field of a route. I am getting close to working out a solution and would like to know how to correctly parse all the characters - especially at the end.

"method": "DELETE",
"path": "/api/*",
"name": "*Group).Use.func1"

“method”: “POST”,
“path”: “/confirmreset”,
“name”: “”


It is the route handler function as string.


Just figured it out! Sharing a supercontext(one instance of echo across packages) is enough to make all routes available without having to import or redefine anything. Too bad no one ever mentioned this.


You can share the same instance but remember they all will be part of routing, configuration, and any middleware that you may have defined.


@vishr, yes i am aware of that , and that is the behavior i desired. Most of my importable, reusable web packages just have routes and no middleware or extra configuration. The main package that starts the server has all the configurations and middleware. So i end up getting a situation where i have Django-like apps and so far it works great.


@siredwin How did you do that?


@rof20004, it is not very hard to implement a multi-app , probably an enterprise level Golang application. But it needs a good example. I can make a blog about it if you want and a link to here.


Thanks @siredwin, I am waiting :smiley:


I will post it here when I get done. My main app currently imports about 8 apps(auth, payments, renderer, blog,etc). One line each.


Thanks @siredwin, take your time :smiley: