Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 15:54
    hemanthkotaprolu starred labstack/echo
  • 15:34
    tgrosinger commented #2390
  • 14:33
    taha-au starred labstack/echo
  • 10:58
    aryan-more closed #2388
  • 10:44
    dinncer starred labstack/echo
  • 09:57
    330324jby starred labstack/echo
  • 09:52
    godaner starred labstack/echo
  • 09:50
    GodL9211 starred labstack/echo
  • 08:13
    lifthus starred labstack/echo
  • 07:41
    EmilioMirasola starred labstack/echo
  • 05:15
    aldas commented #2390
  • 03:52
    ibook86 starred labstack/echo
  • 00:10
    tgrosinger opened #2390
  • Jan 29 19:48
    ggalihpp-jubelio closed #2389
  • Jan 29 19:48
    ggalihpp-jubelio commented #2389
  • Jan 29 19:42
    ggalihpp-jubelio commented #2389
  • Jan 29 19:28
    aldas commented #2388
  • Jan 29 19:27
    aldas commented #2388
  • Jan 29 19:16
    mojixcoder commented #2389
  • Jan 29 19:14
    aldas commented #2389
Something like this doesn't seem to return anything
func GETTER(path string, params []string, paramValues []string) string {
    e := echo.New()
    req := httptest.NewRequest(http.MethodGet, path, nil)
    rec := httptest.NewRecorder()

    c := e.NewContext(req, rec)


    //res := rec.Result()
    defer rec.Result().Body.Close()

    return rec.Body.String()
1 reply
is there a good Guide to get started with Echo??
1 reply
Emil Nikolov
Is there a way to enumerate all routes of an echo router? Something similar to chi.Walk() - https://github.com/go-chi/chi/blob/d32a83448b5f43e42bc96487c6b0b3667a92a2e4/tree.go#L827
Martti T.
e.Routes() gives you all registered routes (with default router). does not include vhost ones
Hi, how to pass the echo logging middleware that can be used by other packages, when we write the application ?
Martti T.
how i can testing my routes?
func login(c echo.Context) error {
    validate := validator.New()
    u := new(Auth)
    if err := c.Bind(u); err != nil {
        return echo.NewHTTPError(http.StatusBadRequest)
    err := validate.Struct(u)

    if err != nil {
        return echo.NewHTTPError(http.StatusBadRequest)
    user , err := domain.GetAuthByUsername(u.Username,u.Password)

    if user.Id == 0  {
          return echo.ErrUnauthorized
    claims := &jwtCustomClaims{ user.Username,*user.Active,*user.Admin,user.Roles,
            ExpiresAt: time.Now().Add(time.Hour * 72).Unix(),
    token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

    t, err := token.SignedString([]byte(os.Getenv("ACCESS_SECRET")))
    if err != nil {
        return err

    return c.JSON(http.StatusOK, echo.Map{
        "token": t,"roles":user.Roles,"username": user.Username,
func startAuthRouters(app *echo.Echo){
    auth := app.Group("/auth/login")
    auth.POST("", login)
package controllers

import (

func TestAuth(t *testing.T) {
    // t.Parallel()
    // Start()
    t.Run("Controllers ECHO", func(t *testing.T) {

        req := httptest.NewRequest(echo.POST, "/auth/login",nil)
        rec := httptest.NewRecorder()

        // // req.Header.Set("Content-Type", "application/json")
        // // req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
        // c.SetPath("/auth/login")
        // h := login(c)
        // fmt.Println(h)
        // fmt.Println(rec)
        // assert.Equal(t, http.StatusBadRequest, rec.Code)
        assert.Equal(t, http.StatusBadRequest, rec.Code)

Martti T.
func TestHandler(t *testing.T) {
    e := echo.New()
    req := httptest.NewRequest(http.MethodGet, "/", nil)
    rec := httptest.NewRecorder()
    c := e.NewContext(req, rec)

    handler := func(c echo.Context) error {
        return c.String(http.StatusOK, "OK")

    err := handler(c)

    assert.NoError(t, err)
    assert.Equal(t, http.StatusOK, rec.Code)
Martti T.

lets say your code is

type authService interface {
    GetAuthByUsername(username string, password string) (string, error)
type AuthRoutes struct {
    auth authService

func (a AuthRoutes) login(c echo.Context) error {
    auth, err := a.auth.GetAuthByUsername("user", "pass")
    if err != nil {
        return err
    return c.JSON(http.StatusCreated, map[string]string{"auth": auth})

then you would create something like that for test

type authServiceMock struct {

func (m *authServiceMock) GetAuthByUsername(username string, password string) (string, error) {
    args := m.Called(username, password)
    return args.String(0), args.Error(1)

func TestHandler(t *testing.T) {
    e := echo.New()
    req := httptest.NewRequest(http.MethodGet, "/", nil)
    rec := httptest.NewRecorder()
    c := e.NewContext(req, rec)

    serviceMock := new(authServiceMock)
    serviceMock.On("GetAuthByUsername", "user", "pass").Return("myauth", nil)
    auth := AuthRoutes{auth: serviceMock}

    err := auth.login(c)

    assert.NoError(t, err)
    assert.Equal(t, http.StatusCreated, rec.Code)


in that way you can mock that auth service inside your handler

mock.mock is from testify "github.com/stretchr/testify/mock"

hi guys. I am using the proxy module and am proxying some "blocking requests" meaning requests that live for 5 minutes. my clients (that are connecting to the echo proxy) are killing them if they don't need them anymore, but on the echo proxy side, those requests seem to stay open. is that a bug, or expected behaviour?

how can I make sure that those cancelled requests are properly cleaned up?

ah wait, I think there might be something seriously wrong with my code...
ok yeah I was using ModifyResopnse and I didn't close the response.body, which caused the issue
sorry for the noise!
Martti T.
It is probably better to ask questions in https://github.com/labstack/echo/discussions I do not think there are many people actively monitoring this chat.
is there any way to use the proxy middleware dynamically? say i have the route /proxy/server1/foo I want to proxy http://server1/foo and if I have /proxy/server2/foo I want to proxy http://server2/foo. server1 and server2 can be anything in this scenario
nevermind, figured it out
José María Martín
Hi! Is there any way to make the 'Timeout' middleware to generate a JSON response? And set custom headers for the response?
Hi Team i have a piece of code which tries to read the session storage. I can confirm that sessions are getting saved but whenever its trying to read the session length of session values are always empty. Any suggestion how i can fix this
Hello all

i am trying to implement echo with gorm
came across a doubt
does golang support any like <T extends grom.model>

type (
    SampleModel struct {
    DBLayer[c grom.model] struct {
    SampleLogic struct {
        DBLayer[SampleModel] // Getting a error here that SampleModel does not implement gorm.Model

Sorry for golang specific question. Couldn't understand where to ask

Yoan Blanc
Go doesn't have type inheritance.
a gorm.Model is nothing special, https://pkg.go.dev/gorm.io/gorm#Model
Hi, I wanna recommend you this m3u8 downloader :https://streamfab.com/drm-m3u8-downloader.htm
Olaf Conradi
When using the same handler on different groups, is there a way to tell which group the request belongs to? Or should I manually parse the path to find out? Example:
    people := e.Group("/p")
    group := e.Group("/g")
    service := e.Group("/s")
    org := e.Group("/o")
    app := e.Group("/a")

Basically each endpoint has the same set of paths behind it /:name/something, and /:name/somethingelse, etc
and the logic is the same, but the actor is different