chore: add example for openapi/swagger authentication (#4004)

This commit is contained in:
wanna
2024-12-05 15:49:50 +08:00
committed by GitHub
parent c0f2ef7348
commit 5fa33411fc
3 changed files with 39 additions and 0 deletions

View File

@ -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
}
}