Skip to content
Discussion options

You must be logged in to vote

try this

package main

import (
	"log/slog"

	"github.com/labstack/echo/v5"
)

func main() {
	e := echo.New()
	
	ri := e.GET("/users/:id", func(c *echo.Context) error {
		return c.String(200, "Hello, World!")
	})

	uri := ri.Reverse(123)

	slog.Info("Reverse route URI generated", "uri", uri)
}

or

package main

import (
	"log/slog"
	"net/http"

	"github.com/labstack/echo/v5"
)

func main() {
	e := echo.New()

	ri, _ := e.AddRoute(echo.Route{
		Method: http.MethodGet,
		Path:   "/users/:id",
		Name:   "get_user_by_id",
		Handler: func(c *echo.Context) error {
			return c.String(200, "Hello, World!")
		},
	})

	uri := ri.Reverse(123)
	uri2, _ := e.Router().Routes().Reverse("get_user_by_id", 100

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@m-rishikesh
Comment options

Answer selected by m-rishikesh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants