不能使用func-literal(类型func(string,string,echo.Context)bool)作为类型



我想使用echo框架在golang中应用基本身份验证。我有以下错误:

"#命令行参数

\main.go:44:29:不能使用func literal(类型func(string,string,echo.Context(bool(作为类型中间件。的参数中的BasicAuthValidator中间件。BasicAuth";

我的代码:

package main
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"net/http"
)

// main function
func main(){
e := echo.New()
g := e.Group("/home")
g.Use(middleware.BasicAuth(func (username, password string, c echo.Context) bool {
if(username=="iamsns" && password=="Iamsns355@"){
return true
} else {
return false
}

}))
g.POST("/login", getHome)

e.Start(":8008")
}

根据文档中间件。BasicAuthValidator被定义为func(string, string, echo.Context) (bool, error)而不是func(string, string, echo.Context) bool。您需要更改签名才能返回error

相关内容

最新更新