Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding context to Validator Middleware's ErrFunc and LogFunc functions #472

Closed
nsp opened this issue Jan 6, 2022 · 2 comments · Fixed by #953
Closed

Consider adding context to Validator Middleware's ErrFunc and LogFunc functions #472

nsp opened this issue Jan 6, 2022 · 2 comments · Fixed by #953

Comments

@nsp
Copy link

nsp commented Jan 6, 2022

This would be a breaking change, but for us, a good thing if these openapi3filter/middleware.go's types were instead

// ErrFunc handles errors that may occur during validation.
type ErrFunc func(ctx context.Context, w http.ResponseWriter, status int, code ErrCode, err error)

// LogFunc handles log messages that may occur during validation.
type LogFunc func(ctx context.Context, message string, err error)

And invoked by the middleware with r.Context(). This way, the logging and error handling functions can access important info from the request context, like tracingIDs, requestIDs, deadline information, etc.

It might not be a breaking change if additional handler functions are added (ErrWithContextFunc and LogWithContextFunc?) for additional complexity.

If one of these approaches is acceptable, I can contribute a MR.

@fenollp
Copy link
Collaborator

fenollp commented Feb 23, 2022

Please go ahead with the first proposition (the breaking change)

@crissi98
Copy link
Contributor

crissi98 commented Jun 1, 2024

Hi @fenollp,

I wanted to use the LogFunc as described in this issue, so i went ahead with a first proposition, but without breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants