You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know where dose the variable api come from?
funcMyMiddleware(ctx huma.Context, nextfunc(ctx huma.Context)) {
// If there is a query parameter "error=true", then return an errorifctx.Query("error") =="true" {
// WHERE DOSE THE VARIABLE API COME FROMhuma.WriteErr(api, ctx, http.StatusInternalServerError,
"Some friendly message", fmt.Errorf("error detail"),
)
return
}
// Otherwise, just continue as normal.next(ctx)
})
The text was updated successfully, but these errors were encountered:
@NeroBlackstone you can pass it into the middleware creation function. This creates a closure where you have access to the API. For example, this prints the API title in a middleware:
funcMyMiddleware(api huma.API) func(ctx huma.Context, nextfunc(huma.Context)) {
returnfunc(ctx huma.Context, nextfunc(huma.Context)) {
fmt.Println("Hello from middleware for "+api.OpenAPI().Info.Title)
next(ctx)
}
}
In huma middleware docs.
I don't know where dose the variable
api
come from?The text was updated successfully, but these errors were encountered: