Echo: [Question] Modify a router on-the-fly?

Created on 19 Aug 2020  路  1Comment  路  Source: labstack/echo

Description

Is there a way to modify a route while server is running ?

I'm planing to create a interface to developers build our own API from "blocks" and I need a way to dynamically Add, Remove or Modify a route on-the-fly, I tested many web frameworks in Go and Javascript and always has a way to create a route but never a way to remove...

Checklist

  • [x] Dependencies installed
  • [x] No typos
  • [x] Searched existing issues and docs

Working code to debug

There is a way to dynamically add a new route on-the-fly see it:

package main

import (
    "net/http"

    "github.com/labstack/echo/v4"
    "github.com/labstack/echo/v4/middleware"
)

func main() {
    // Echo instance
    e := echo.New()

    // Middleware
    e.Use(middleware.Logger())
    e.Use(middleware.Recover())

    // Routes
    e.GET("/add", func(c echo.Context) error {
        e.GET("/ping", Ping)
        return c.String(http.StatusOK, "Added Ping!")
    })

    // Start server
    e.Logger.Fatal(e.Start(":8080"))
}

// Ping ...
func Ping(c echo.Context) error {
    return c.String(http.StatusOK, "Pong!")
}

Version/commit

Currently using Echo v4.1.16

Refs: #1026 #1612

question

Most helpful comment

Isn't that already answered in #1612? The same restrictions still apply.

So short answer is: No, routes cannot be modified after starting the server and the routing tree has been built.

>All comments

Isn't that already answered in #1612? The same restrictions still apply.

So short answer is: No, routes cannot be modified after starting the server and the routing tree has been built.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dre1080 picture dre1080  路  4Comments

vishr picture vishr  路  3Comments

mmindenhall picture mmindenhall  路  4Comments

spielstein picture spielstein  路  3Comments

alexzorin picture alexzorin  路  3Comments