Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiddlewareFunc version error #1517

Closed
yekai1003 opened this issue Feb 29, 2020 · 4 comments
Closed

MiddlewareFunc version error #1517

yekai1003 opened this issue Feb 29, 2020 · 4 comments
Labels

Comments

@yekai1003
Copy link

Issue Description

cannot use session.Middleware(sessions.NewCookieStore(([]byte)("secret"))) (type "github.com/labstack/echo/v4".MiddlewareFunc) as type "github.com/labstack/echo".MiddlewareFunc

package main

import (

	"github.com/gorilla/sessions"
	"github.com/labstack/echo"
	"github.com/labstack/echo-contrib/session"
	"github.com/labstack/echo/middleware"
)
func main() {
	EchoObj = echo.New()
	EchoObj.Use(middleware.Logger()) //安装日志中间件
	EchoObj.Use(middleware.Recover())
	EchoObj.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))

	EchoObj.Use(middleware.GzipWithConfig(middleware.GzipConfig{
		Level: 5,
	}))
	EchoObj.Logger.Fatal(EchoObj.Start(":8080")) //启动服务
}

Version/commit

@ffenix113
Copy link
Contributor

Please use github.com/labstack/echo/v4 instead of github.com/labstack/echo.
Session middleware uses v4 but your code does not. That's why you have an error.

@stale
Copy link

stale bot commented May 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@daniial79
Copy link

daniial79 commented Mar 7, 2023

Im trying to fix cors origin error using middleware lib but I can not pass middleware.CORS() to Use funcfion of e thouhg I am using v4 of echo . the error I face is in below:

cannot use middleware.CORS() (value of type "github.com/labstack/echo".MiddlewareFunc) as "github.com/labstack/echo/v4".MiddlewareFunc value in argument to e.UsecompilerIncompatibleAssign

package middleware

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

func CorsHandler(e *echo.Echo) {
	e.Use(middleware.CORS())
}

@aldas
Copy link
Contributor

aldas commented Mar 7, 2023

Change "github.com/labstack/echo/middleware" to "github.com/labstack/echo/v4/middleware"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants