尝试使用 Go 的 Echo 框架进行基本身份验证。找到了几段代码,但目前还没有完整的代码集。
到目前为止有这个基本程序
package main
import (
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"net/http"
)
func main() {
var html string;
// Echo instance
e := echo.New()
// Route => handler
e.GET("/", func(c echo.Context) error {
e.Group("/").Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
if username == "user" && password == "password" {
html ="Authenticated"
return true, nil
}
return false, nil
}))
return c.HTML(http.StatusOK, html)
})
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
它提示输入用户名和密码,但经过身份验证后我得到
未找到信息”
使用 Echo 框架的基本身份验证的任何建议或工作代码链接将不胜感激。
沧海一幻觉
牧羊人nacy
撒科打诨
随时随地看视频慕课网APP
相关分类