echo icon indicating copy to clipboard operation
echo copied to clipboard

Echo#Group Bug

Open imroc opened this issue 9 years ago • 3 comments

Description

this is not work:

e.Group("/admin",EnterAdmin)

but this works:

e.Group("/admin")
e.Use(EnterAdmin)

it`s the newes commit,this is wired,why?

imroc avatar Feb 20 '17 15:02 imroc

Below below works for me:

package main

import (
	"github.com/labstack/echo"
	m "github.com/labstack/echo/middleware"
)

func main() {
	e := echo.New()
	g := e.Group("/group", m.Logger())
	g.Use(m.Logger())
	g.GET("", func(c echo.Context) error {
		return c.JSON(200, "Hello, World!")
	})
	e.Logger.Fatal(e.Start(":1323"))
}

Please check your middleware.

vishr avatar Feb 21 '17 23:02 vishr

Below should work. I think Group() itself provides just namespace for url, not endpoint.

package main

import (
	"net/http"

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

func main() {
	e := echo.New()
	e.Use(middleware.Logger())

	v1 := e.Group("/v1")
	 v1.GET("/echo", func(c echo.Context) error {
		return c.String(http.StatusOK, "echo V1 API")
	})

	e.Logger.Fatal(e.Start(":1323"))
}

when you access to localhost:1323/v1/echo , you'll get string like echo V1 API .

yoshi42662 avatar Mar 16 '17 07:03 yoshi42662

thx

imroc avatar Mar 17 '17 02:03 imroc