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
{{ message }}
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
From Slack:
Thoughts on using a page out of Java's book with the class StringBuilder (and maybe method chaining) to consistently and maintainably implement request handling on the backend?
Example:
funchandler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
handlerChain:=new(HandlerChain)
.append(validateRequestMyHandler) // Check parameters
.append(authentiate) // (optional) Store user info in ctx
.append(processRequestMyHandlerPart1)
.append(processRequestMyHandlerPart2) // There could be multiple steps to processing a request
.append(processRequestMyHandlerPart3)
returnhandlerChain.handle(ctx, req)
}
Every handler only invokes the next one if there is no error, otherwise it returns the error response.
This way we can return an error using shared code without adding unrelated logic to the handlers.
Please discuss! 🙂
The text was updated successfully, but these errors were encountered:
I think this might help reduce duplicate code or errors when doing generic stuff such as acquiring user info (aka authentication/authorization) or API version validation, since it would contain it in a single function call respectively.
it is a valid reason, but the common approach for this kind of work is middleware.
your suggestion is like middleware but middleware is before the handler not inside the handler.
Yes, that was the idea, but I am not sure if this is supported by AWS SAM.
I don't know, but If was sam not supporting middleware we can create a structure like a method Channing/middleware in the main function, out side handler for auth or ...
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
help wantedExtra attention is neededquestionFurther information is requested
From Slack:
Thoughts on using a page out of Java's book with the class
StringBuilder
(and maybe method chaining) to consistently and maintainably implement request handling on the backend?Example:
Every handler only invokes the next one if there is no error, otherwise it returns the error response.
This way we can return an error using shared code without adding unrelated logic to the handlers.
Please discuss! 🙂
The text was updated successfully, but these errors were encountered: