Add Inspection pattern for ergonomic value retrieval#2
Merged
Conversation
This commit introduces a new Inspection pattern that separates context
value retrieval from display logic, providing a more ergonomic API.
## Breaking Changes
- Remove DebugValue/DebugString methods (replaced by Inspection.String())
## New Features
### Inspection[V] struct
- Captures Key, Value, and Ok (whether set) in one call
- Provides helper methods without requiring context:
- Get() / TryGet() / GetOrDefault() / MustGet()
- IsSet() / IsNotSet()
- Implements fmt.Stringer: "key-name: value" or "key-name: <not set>"
- Implements fmt.GoStringer with package qualification
### BoolInspection struct
- Specialized wrapper for boolean feature flags
- Provides Enabled() / Disabled() / ExplicitlyDisabled()
- Embeds Inspection[bool] for full functionality
### Key[V] interface additions
- Inspect(ctx) Inspection[V] - retrieves value with metadata
- fmt.GoStringer - returns "feature.Key[T]{name: \"...\"}"
### BoolKey interface additions
- InspectBool(ctx) BoolInspection
## Internal Changes
- Refactor existing Key methods to use Inspection internally
- Split inspection-related code into inspection.go
- Split inspection tests into inspection_test.go
- Achieve 100% test coverage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 2 +1
Lines 81 113 +32
=========================================
+ Hits 81 113 +32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new Inspection pattern that separates context value retrieval from display logic, providing a more ergonomic and flexible API for working with feature flag values.
Key Changes
New
Inspection[V]struct: Captures the key, value, and whether it was set in a single call toInspect(ctx). All helper methods (Get,TryGet,GetOrDefault,MustGet,IsSet,IsNotSet) are now available on the inspection result without needing to pass context again.New
BoolInspectionstruct: A specialized wrapper for boolean feature flags withEnabled(),Disabled(), andExplicitlyDisabled()convenience methods.fmt.Stringerandfmt.GoStringersupport: BothKeyandInspectiontypes now implement these interfaces with package-qualified output for better debugging.Breaking change: Removed
DebugValue/DebugStringmethods (replaced byInspection.String()).Example Usage
File Changes
feature.goInspect()method toKey[V],InspectBool()toBoolKey,fmt.GoStringerinterface, refactored existing methods to use Inspection internallyinspection.goInspection[V]andBoolInspectionstructs with all helper methodsfeature_test.goDebugValuetestsinspection_test.goTest Plan
InspectionandBoolInspectiontypesgolangci-lintpasses with no issuesgo vetpasses🤖 Generated with Claude Code