How to load routes from a JSON file?


I read about the routeing, but I did not understand the route question as a json type file.

Is it possible to use this .JSON file to manage my routes? If so, how? After writing them. Routing


Why do you want to store your routes in a JSON file?


I found it a bit more organized


With each route (method + path) there is an associated handler, how will you load that?


Of all the frameworks that I found yours was what I liked the most. Congratulations!

Note that inside the Json file there is some data like: Methods, Path, handler inside handler it calls the main.go file and the function that is inside the correct main.go file?

I would like to create my own ex control:

Controllers /myController.go

Inside my control has a function that shows the contents of the route / mycontroller:

Func Home (c echo.Context) error {}

And make it work like this: controllers /myController.Home

I would just like to handle the routes through the JSON file and not the main file.


I don’t think it is a good idea or even possible to do it in Go, it is not a dynamic language, however if you can figure out a way to load function by a name (string), here are steps:

  • Create a JSON file with method, path and string handler
  • Decode JSON into slice of Route
  • Iterate over routes and call e.Add() to register a route with method, path and handler converted from name

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

Thanks for answering.
You’re right! I’ll test what you just exemplified to get the results.

Another question …

Is it possible to add the Ace engine template in Echo?

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

The API for templates is so simple that you can use any templating engine. We don’t have an official recipe but you can search online to find it for Ace or similar libraries.


Got it.
On the routes I just wanted to separate it from my file, main.go

Thanks for answer