commit aae82d7d807a3f77f74c1b4f002e3945c90b2962 Author: naudachu Date: Sat May 11 09:37:32 2024 +0000 Upload files to "/" diff --git a/rctx.go b/rctx.go new file mode 100644 index 0000000..400ce75 --- /dev/null +++ b/rctx.go @@ -0,0 +1,42 @@ +package rctx + +import ( + "context" + + "github.com/google/uuid" +) + +// ContextString +// Assign context implementation was stolen +// here: https://medium.com/@funfoolsuzi/logging-with-request-id-in-go-microservice-21485c6730da +type ContextString string + +const ( + ContextRequestIDKey ContextString = "requestID" +) + +// AssignRequestID +// +// Assigns request id to the context.Context variable +func AssignRequestID(ctx context.Context) context.Context { + + reqID := uuid.New() + + return context.WithValue(ctx, ContextRequestIDKey, reqID.String()) + +} + +// GetRequestID +// +// Gets request id from the context.Context variable +func GetRequestID(ctx context.Context) string { + + reqID := ctx.Value(ContextRequestIDKey) + + if ret, ok := reqID.(string); ok { + return ret + } + + return "" + +}