Skip to content

v0.3.0

Choose a tag to compare

@mpyw mpyw released this 12 Dec 06:18
· 39 commits to main since this release
375ee78

Installation

go get github.com/mpyw/feature@v0.3.0

What's Changed

  • Add Inspection pattern for ergonomic value retrieval by @mpyw in #2

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

Full Changelog: v0.2.0...v0.3.0