2 ZH_Basicauth
Lunny Xiao edited this page 2019-11-27 09:08:08 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Basicauth 中间件提供了Http Basic认证是一个 Tango 的中间件。

安装

go get gitea.com/tango/basicauth

示例

type AuthAction struct {}
func (a *AuthAction) Get() string {
    return "200"
}

func main() {
    tg := tango.Classic()
    tg.Use(basicauth.New(user, pass))
    tg.Get("/", new(AuthAction))
}

如果不希望某个Action进行认证则只要把basiauth.NoAuth作为匿名成员即可。

type NoAuthAction struct {
    basicauth.NoAuth
}
func (a *NoAuthAction) Get() string {
    return "200"
}

func main() {
    tg := tango.Classic()
    tg.Use(basicauth.New(user, pass))
    tg.Get("/", new(NoAuthAction))
}