Creating Golang WebServer With Echo - Part 5: Basic Authentication Middleware

preview_player
Показать описание
Tutorial series for building step by step a real life server in Golang using Echo package.

This time, adding basic authentication middleware to a grouped endpoints.

Starting code for this video:

Full code:

Stay tuned for more ;)
Рекомендации по теме
Комментарии
Автор

thank you for this echo series:) helped me a lot!!

luthfiaersyanad.
Автор

Thank you for the video. Will there be a continuation? =)

Beastie
Автор

this error is showing this code of BasicAuth :--


# 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

shivsharma
Автор

Why ur voice so sad? Are u not happy programming on GO?

npwmdvs
Автор

Awesome series, middleware.BasicAuthValidator now returns (bool, error).

g.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
// true condition
return true, nil
//false condition
return false, c.JSON(http.StatusUnauthorized, map[string]string{"message": "who are you?"})
// or you can simply let echo handle it for you {"message": "Unauthorized"}
return false, nil
}))

MorbidPasta