add auth middleware to server mux

This commit is contained in:
程广 2025-05-29 17:17:14 +08:00
parent 3bccf2187f
commit be64000bff
2 changed files with 14 additions and 0 deletions

View File

@ -54,9 +54,17 @@ var DRecordAccess Directive = func(args ...string) Middleware {
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{
"Set-Header": Set_Header,
"Add-Header": Add_Header,
"Gzip_Response": Gzip_Response,
"Record-Access": DRecordAccess,
"Jwt-Auth": JWTDirective,
"Basic-Auth": BasicAuthDirective,
}

View File

@ -309,6 +309,12 @@ func NewServeMux(c *model.HttpServerConfig) *ServerMux {
}
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 {
// 将指令添加到 ServerMux 的指令处理中间件链中