oiio
oiio

Reputation: 45

How to use go echo middleware?

I installed echo via

go get -u github.com/labstack/echo/v4

Its package in go.mod like

module app

go 1.15

require (
    github.com/labstack/echo v3.3.10+incompatible
    github.com/labstack/echo/v4 v4.2.0
) 

In server.go, use a middleware as

package app

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

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

It alert too few arguments in call to middleware.Logger. Other middleware also can't been used.

Upvotes: 1

Views: 4904

Answers (1)

Muhammad Iqbal Ali
Muhammad Iqbal Ali

Reputation: 86

try this

package main

import (
    "net/http"

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

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

    e.Use(middleware.Logger())

    e.GET("/", func(c echo.Context) error {
        return c.String(http.StatusOK, "Hello World")
    })

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

and in go.mod only just it

module app

go 1.15

require github.com/labstack/echo/v4 v4.2.0

Upvotes: 2

Related Questions