0

I want to apply Basic authentication in golang using echo framework. I have following error :

"# command-line-arguments

.\main.go:44:29: cannot use func literal (type func(string, string, echo.Context) bool) as type middleware.BasicAuthValidator in argument to middleware.BasicAuth"

my code:

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")
}
jub0bs
  • 60,866
  • 25
  • 183
  • 186

1 Answers1

1

According to the docs middleware.BasicAuthValidator is defined as func(string, string, echo.Context) (bool, error) not func(string, string, echo.Context) bool. You need to change the signature to also return an error.

Dylan Reimerink
  • 5,874
  • 2
  • 15
  • 21