mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
chore: add example for openapi/swagger authentication (#4004)
This commit is contained in:
@ -45,5 +45,14 @@ func main() {
|
||||
new(Hello),
|
||||
)
|
||||
})
|
||||
// if api.json requires authentication, add openApiBasicAuth handler
|
||||
s.BindHookHandler(s.GetOpenApiPath(), ghttp.HookBeforeServe, openApiBasicAuth)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
func openApiBasicAuth(r *ghttp.Request) {
|
||||
if !r.BasicAuth("OpenApiAuthUserName", "OpenApiAuthPass", "Restricted") {
|
||||
r.ExitAll()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user