Skip to content

Conversation

@kasidej
Copy link

@kasidej kasidej commented Jan 5, 2026

Description

Fix an inconsistency in the Context.Value method where it accepted keys of any type in its signature but internally restricted them to strings when pass to Context.Get.

Motivation

The Context.Value method had a signature accepting any for keys, but its implementation only worked with string keys due to a type assertion when pass to Context.Get. This was inconsistent with Context.Set which properly support any comparable key type. I using custom types as context keys (a common Go pattern to avoid key collisions) would find that Value didn't work while Set did.

Changes

  • modified Context.Value method in context.go
  • add a test using a custom struct type in context_test.go

Pull Request Checklist

Please ensure your pull request meets the following requirements:

  • Open your pull request against the master branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.
  • If the pull request introduces a new feature, the feature is documented in the docs/doc.md.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.99%. Comparing base (3dc1cd6) to head (b9d6964).
⚠️ Report is 230 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4492      +/-   ##
==========================================
- Coverage   99.21%   98.99%   -0.22%     
==========================================
  Files          42       44       +2     
  Lines        3182     2987     -195     
==========================================
- Hits         3157     2957     -200     
- Misses         17       21       +4     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.98% <100.00%> (?)
-tags go_json 98.92% <100.00%> (?)
-tags nomsgpack 98.98% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.24 98.99% <100.00%> (?)
go-1.25 98.99% <100.00%> (?)
macos-latest 98.99% <100.00%> (-0.22%) ⬇️
ubuntu-latest 98.99% <100.00%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Nurysso
Copy link
Contributor

Nurysso commented Jan 6, 2026

Looks good to me
@appleboy Can you please review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants