Skip to content

Using a type for keys - #13

Merged
serroba merged 1 commit into
mainfrom
dev
Jan 2, 2026
Merged

Using a type for keys#13
serroba merged 1 commit into
mainfrom
dev

Conversation

@serroba

@serroba serroba commented Jan 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 2, 2026 07:33
@serroba
serroba merged commit 4dc59d5 into main Jan 2, 2026
6 checks passed
@codecov

codecov Bot commented Jan 2, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #13   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          176       176           
=========================================
  Hits           176       176           

☔ 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.

@serroba
serroba deleted the dev branch January 2, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new FlagKey type (a string alias) to provide stronger type safety for flag keys throughout the codebase. The change replaces raw string usage with the typed FlagKey across the domain model, service layer, repository interface, and handler layer.

Key changes:

  • Introduced type FlagKey string in the flags package to create a distinct type for flag keys
  • Updated all struct fields, method signatures, and conversions to use FlagKey instead of raw strings
  • Added comprehensive validation tags to request/response models for API constraints

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/flags/types.go Defines the new FlagKey type and updates Flag and EvalResult structs to use it
internal/flags/service.go Updates the Evaluate method signature to accept FlagKey parameter
internal/flags/repository.go Updates the Repository interface Get method to accept FlagKey parameter
internal/flags/memory.go Updates the in-memory repository implementation to use map[FlagKey]Flag and converts method signatures
internal/handler/models.go Updates response models to use FlagKey type and adds validation tags for enum values and constraints
internal/handler/handler.go Updates the FlagService interface and adds type conversion when calling service methods
internal/handler/mapper.go Adds explicit conversion from string to FlagKey when mapping request bodies
internal/handler/handler_test.go Updates test expectations and mock setup to use FlagKey type
internal/handler/mapper_test.go Updates test assertions to expect FlagKey type
internal/handler/mock_service_test.go Updates generated mock to match new interface signature
internal/flags/service_test.go Updates test assertions to expect FlagKey type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Evaluate(gomock.Any(), "my-flag", gomock.Any()).
Evaluate(gomock.Any(), flags.FlagKey("my-flag"), gomock.Any()).
Return(flags.EvalResult{
FlagKey: "my-flag",

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FlagKey field should use the flags.FlagKey type for consistency. Change this to FlagKey: flags.FlagKey("my-flag") to match the new type system.

Suggested change
FlagKey: "my-flag",
FlagKey: flags.FlagKey("my-flag"),

Copilot uses AI. Check for mistakes.
Evaluate(gomock.Any(), "premium-feature", gomock.Any()).
Evaluate(gomock.Any(), flags.FlagKey("premium-feature"), gomock.Any()).
Return(flags.EvalResult{
FlagKey: "premium-feature",

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FlagKey field should use the flags.FlagKey type for consistency. Change this to FlagKey: flags.FlagKey("premium-feature") to match the new type system.

Suggested change
FlagKey: "premium-feature",
FlagKey: flags.FlagKey("premium-feature"),

Copilot uses AI. Check for mistakes.
Evaluate(gomock.Any(), "disabled-flag", gomock.Any()).
Evaluate(gomock.Any(), flags.FlagKey("disabled-flag"), gomock.Any()).
Return(flags.EvalResult{
FlagKey: "disabled-flag",

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FlagKey field should use the flags.FlagKey type for consistency. Change this to FlagKey: flags.FlagKey("disabled-flag") to match the new type system.

Suggested change
FlagKey: "disabled-flag",
FlagKey: flags.FlagKey("disabled-flag"),

Copilot uses AI. Check for mistakes.
@@ -69,7 +69,7 @@ func TestService_Evaluate_ReturnsDefault(t *testing.T) {
result, err := svc.Evaluate(ctx, "my-flag", flags.EvalContext{})

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Evaluate method now expects a flags.FlagKey type, not a string. Change this to svc.Evaluate(ctx, flags.FlagKey("my-flag"), flags.EvalContext{}) for type consistency.

Copilot uses AI. Check for mistakes.
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