Skip to content
Snippets Groups Projects
Commit 211f3446 authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Added CurrentRequestID to api.Context for legacy handlers

parent 90ec162f
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,10 @@ import ( ...@@ -18,6 +18,10 @@ import (
"gitlab.com/uafrica/go-utils/service" "gitlab.com/uafrica/go-utils/service"
) )
//LEGACY: global variable is set only for backward compatibility
//When handlers are changed to accept context, they should get this from the context
var CurrentRequestID *string
//New creates the API with the specified routes keys on [path][method] //New creates the API with the specified routes keys on [path][method]
//value could be any of the handler function signatures supported by the api.Router //value could be any of the handler function signatures supported by the api.Router
//requestIDHeaderKey is defined in the response header to match the requestID from the request //requestIDHeaderKey is defined in the response header to match the requestID from the request
......
...@@ -113,6 +113,10 @@ func (api Api) Handler(baseCtx context.Context, apiGatewayProxyReq events.APIGat ...@@ -113,6 +113,10 @@ func (api Api) Handler(baseCtx context.Context, apiGatewayProxyReq events.APIGat
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
//LEGACY: delete this as soon as all handlers accepts context
//this does not support concurrent execution!
CurrentRequestID = &ctx.Request.RequestContext.RequestID
ctx.Debugf("HTTP %s %s ...\n", apiGatewayProxyReq.HTTPMethod, apiGatewayProxyReq.Resource) ctx.Debugf("HTTP %s %s ...\n", apiGatewayProxyReq.HTTPMethod, apiGatewayProxyReq.Resource)
ctx.WithFields(map[string]interface{}{ ctx.WithFields(map[string]interface{}{
"http_method": ctx.Request.HTTPMethod, "http_method": ctx.Request.HTTPMethod,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment