Skip to content

Conversation

kieranbarty
Copy link
Contributor

To retrieve metadata from incoming requests further in our handlers, we need to be able to set and retrieve it on the handler itself. This introduces an optional field called metadata, and a new method named GetMetadata().

Fixes #67

RELEASE NOTES: Allows retrieval of metadata from client requests throughout the handler lifecycle.

@kieranbarty kieranbarty requested a review from a team as a code owner July 28, 2025 09:13
Copy link

github-actions bot commented Jul 28, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@kieranbarty
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@hyprh hyprh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks for your contribution

@kieranbarty
Copy link
Contributor Author

@hyprh looks like the PR is failing on the go-apidiff check - is there anything I need to change in the PR?

@hyprh hyprh merged commit 2d97fbd into trpc-group:main Jul 28, 2025
4 of 6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2025
@@ -72,6 +72,9 @@ type TaskHandler interface {

// GetContextID returns the context ID of the current message, if any.
GetContextID() string

// GetMetadata returns the metadata of the current task.
GetMetadata() (map[string]interface{}, error)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adopting a uniform style and replace interface{} with any? Since you had used metadata map[string]any below.

Copy link
Contributor

@hyprh hyprh Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I did not noticed this comment and merged it , I will fix it.

// GetMetadata returns the metadata of the current request.
func (h *memoryTaskHandler) GetMetadata() (map[string]interface{}, error) {
if h.metadata == nil {
return nil, fmt.Errorf("metadata is nil")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.New("metadata is nil") might be better

// GetMetadata returns the metadata of the current request.
func (h *taskHandler) GetMetadata() (map[string]interface{}, error) {
if h.metadata == nil {
return nil, fmt.Errorf("metadata is nil")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GetMetadata() method to TaskHandler interface to allow for propagating metadata to processors
3 participants