Skip to content

Conversation

@mpyw
Copy link
Owner

@mpyw mpyw commented Dec 12, 2025

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 to Inspect(ctx). All helper methods (Get, TryGet, GetOrDefault, MustGet, IsSet, IsNotSet) are now available on the inspection result without needing to pass context again.

  • New BoolInspection struct: A specialized wrapper for boolean feature flags with Enabled(), Disabled(), and ExplicitlyDisabled() convenience methods.

  • fmt.Stringer and fmt.GoStringer support: Both Key and Inspection types now implement these interfaces with package-qualified output for better debugging.

  • Breaking change: Removed DebugValue/DebugString methods (replaced by Inspection.String()).

Example Usage

var MaxRetries = feature.NewNamed[int]("max-retries")

// Inspect returns both the value and whether it was set
inspection := MaxRetries.Inspect(ctx)
fmt.Println(inspection)         // "max-retries: 5" or "max-retries: <not set>"
fmt.Println(inspection.IsSet()) // true or false

// All helper methods available without context
value := inspection.GetOrDefault(3)

File Changes

File Description
feature.go Added Inspect() method to Key[V], InspectBool() to BoolKey, fmt.GoStringer interface, refactored existing methods to use Inspection internally
inspection.go New file containing Inspection[V] and BoolInspection structs with all helper methods
feature_test.go Updated tests, removed obsolete DebugValue tests
inspection_test.go New comprehensive tests for Inspection functionality

Test Plan

  • All existing tests pass
  • New tests for Inspection and BoolInspection types
  • 100% code coverage maintained
  • golangci-lint passes with no issues
  • go vet passes

🤖 Generated with Claude Code

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 <[email protected]>
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f138f17) to head (1a74c26).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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.

@mpyw mpyw merged commit 375ee78 into main Dec 12, 2025
12 checks passed
@mpyw mpyw deleted the release-v0.3.0 branch December 13, 2025 14:42
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