Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Screenshot (123)

why i'm not able to create URI it says that URI is not the function of echo instance also i cant use .Name property, how to make a URI in v5 also do i need to make routing like this

_, err := e.AddRoute(echo.Route{
	Method: http.MethodGet,
	Path:   "/users/:id",
	Name:   "user_details",
	Handler: func(c *echo.Context) error {
		return c.String(http.StatusOK, fmt.Sprintf("User ID: %s", c.Param("id")))
	},
	Middlewares: nil,
})

i'm confused

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

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)

	slog.Info("Reverse route URI generated", "uri", uri, "uri2", uri2)
}
You must be logged in to vote
1 reply
@m-rishikesh
Comment options

Screenshot (124)

i want to ask i was referring to the echo docs there it was written that u can make URI like echo.URI but i'm not able to make it, does it is wrong

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.