Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Generics for v2 release of go-sdk #158

Open
skyerus opened this issue Feb 13, 2023 · 1 comment
Open

[FEATURE] Generics for v2 release of go-sdk #158

skyerus opened this issue Feb 13, 2023 · 1 comment
Labels
contribfest A good issue for Contribfest KubeCon EU '24 enhancement New feature or request Needs Triage

Comments

@skyerus
Copy link
Contributor

skyerus commented Feb 13, 2023

Requirements

Now the go-sdk has been upgraded to go 1.18 it can make use of generics.

The obvious candidates where leveraging generics would reduce bloat:

  • Evaluation types are effectively the same structure with different Value types
  • Resolution types, as above, are effectively the same structure with different Value types

Pros:

  • Less types to maintain
  • Less duplicated code
  • Less type inference
  • Less chance of accidental inconsistent behaviour across types

Cons:

  • Breaking change
  • Breaks contract between providers and sdk

Perhaps this undertaking isn't worth the effort but it's at least worth raising.

@paddycarver
Copy link
Contributor

I just tinkered with this for something similar. A constraint to be aware of: methods cannot accept type parameters.

So you can't turn

thisWillBeABool, err := client.BoolValue(ctx, "my-flag", true, myContext)

into

thisWillBeABool, err := client.Value(ctx, "my-flag", true, myContext)

You have to turn it into this:

thisWillBeABool, err := openfeature.Evaluate(ctx, client, "my-flag", true, myContext)

where the client gets passed to a package-level function (which can have type parameters). The function looks something like this:

Evaluate[T any](ctx context.Context, client *Client, flag string, defaultValue T, evalCtx EvaluationContext, options ...Option) (T, error)

This also would mean that client.ObjectValue would be able to accept a user-defined default type and could always return that type, without the need for any interfaces or runtime-checking of the type by the caller.

@toddbaert toddbaert added the contribfest A good issue for Contribfest KubeCon EU '24 label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribfest A good issue for Contribfest KubeCon EU '24 enhancement New feature or request Needs Triage
Projects
None yet
Development

No branches or pull requests

3 participants