add auth middleware to server mux
This commit is contained in:
parent
3bccf2187f
commit
be64000bff
|
@ -54,9 +54,17 @@ var DRecordAccess Directive = func(args ...string) Middleware {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var JWTDirective Directive = func(args ...string) Middleware {
|
||||||
|
return JwtAuth
|
||||||
|
}
|
||||||
|
var BasicAuthDirective Directive = func(args ...string) Middleware {
|
||||||
|
return BasicAuth
|
||||||
|
}
|
||||||
var DirectiveMap = map[string]Directive{
|
var DirectiveMap = map[string]Directive{
|
||||||
"Set-Header": Set_Header,
|
"Set-Header": Set_Header,
|
||||||
"Add-Header": Add_Header,
|
"Add-Header": Add_Header,
|
||||||
"Gzip_Response": Gzip_Response,
|
"Gzip_Response": Gzip_Response,
|
||||||
"Record-Access": DRecordAccess,
|
"Record-Access": DRecordAccess,
|
||||||
|
"Jwt-Auth": JWTDirective,
|
||||||
|
"Basic-Auth": BasicAuthDirective,
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,6 +309,12 @@ func NewServeMux(c *model.HttpServerConfig) *ServerMux {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.AddDirective("Record-Access")
|
s.AddDirective("Record-Access")
|
||||||
|
if c.AuthType == "jwt" {
|
||||||
|
s.AddDirective("Jwt-Auth")
|
||||||
|
}
|
||||||
|
if c.AuthType == "basic" {
|
||||||
|
s.AddDirective("Basic-Auth")
|
||||||
|
}
|
||||||
// 遍历配置中的所有指令
|
// 遍历配置中的所有指令
|
||||||
for _, directive := range c.Directives {
|
for _, directive := range c.Directives {
|
||||||
// 将指令添加到 ServerMux 的指令处理中间件链中
|
// 将指令添加到 ServerMux 的指令处理中间件链中
|
||||||
|
|
Loading…
Reference in New Issue