Skip to content

Instantly share code, notes, and snippets.

@Jimeux
Last active December 22, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimeux/28e15bbfbd7f62b3b1b68d087986a9f5 to your computer and use it in GitHub Desktop.
Save Jimeux/28e15bbfbd7f62b3b1b68d087986a9f5 to your computer and use it in GitHub Desktop.
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