Last active
December 22, 2021 14:41
-
-
Save Jimeux/28e15bbfbd7f62b3b1b68d087986a9f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type HandlerFunc func(ctx context.Context, req *events.APIGatewayWebsocketProxyRequest) (Response, error) | |
// Middleware executed initialization logic common to all WS handlers. | |
func Middleware(logger *Logger, next HandlerFunc) HandlerFunc { | |
return func(ctx context.Context, req *events.APIGatewayWebsocketProxyRequest) (Response, error) { | |
// set common context values for logging | |
ctx = context.WithValue(ctx, KeyConnectionID, req.RequestContext.ConnectionID) | |
ctx = context.WithValue(ctx, KeyRequestID, req.RequestContext.RequestID) | |
// flush buffered logs on exit | |
defer logger.Sync() | |
logger.Info(ctx, "request to "+req.RequestContext.RouteKey) | |
return next(ctx, req) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment