Repository navigation
v0.3.0
Installation
go get github.com/mpyw/feature@v0.3.0What's Changed
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
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.goAdded Inspect()method toKey[V],InspectBool()toBoolKey,fmt.GoStringerinterface, refactored existing methods to use Inspection internallyinspection.goNew file containing Inspection[V]andBoolInspectionstructs with all helper methodsfeature_test.goUpdated tests, removed obsolete DebugValuetestsinspection_test.goNew comprehensive tests for Inspection functionality
Full Changelog: v0.2.0...v0.3.0