Skip to content

Commit ee0cb7b

Browse files
authored
Merge pull request #165 from Flagsmith/feat/undeprecate-getidentityflags-getenvironmentflags
feat: Un-deprecate GetEnvironmentFlags and GetIdentityFlags, improve docs
2 parents cb87239 + b07bbad commit ee0cb7b

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ EVALUATION_CONTEXT_SCHEMA_URL ?= https://raw.githubusercontent.com/Flagsmith/fla
55

66
.PHONY: generate-evaluation-context
77
generate-evaluation-context:
8-
npx quicktype ${EVALUATION_CONTEXT_SCHEMA_URL} \
8+
curl ${EVALUATION_CONTEXT_SCHEMA_URL} | npx quicktype \
99
--src-lang schema \
1010
--lang go \
1111
--package flagsmith \
1212
--omit-empty \
1313
--just-types-and-package \
14-
> evaluationcontext.go
14+
--top-level EvaluationContext \
15+
-o evaluationcontext.go

client.go

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,13 @@ func NewClient(apiKey string, options ...Option) *Client {
171171
return c
172172
}
173173

174-
// Returns `Flags` struct holding all the flags for the current environment.
174+
// GetFlags evaluates the feature flags within an EvaluationContext.
175175
//
176-
// Provide `EvaluationContext` to evaluate flags for a specific environment or identity.
176+
// When flag evaluation fails, the value of each Flag is determined by the default flag handler
177+
// from WithDefaultHandler, if one was provided.
177178
//
178-
// If local evaluation is enabled this function will not call the Flagsmith API
179-
// directly, but instead read the asynchronously updated local environment or
180-
// use the default flag handler in case it has not yet been updated.
181-
//
182-
// Notes:
183-
//
184-
// * `EvaluationContext.Environment` is ignored in local evaluation mode.
185-
//
186-
// * `EvaluationContext.Feature` is not yet supported.
179+
// Flags are evaluated remotely by the Flagsmith API by default.
180+
// To evaluate flags locally, instantiate a client using WithLocalEvaluation.
187181
func (c *Client) GetFlags(ctx context.Context, ec *EvaluationContext) (f Flags, err error) {
188182
if ec != nil {
189183
ctx = WithEvaluationContext(ctx, *ec)
@@ -194,13 +188,8 @@ func (c *Client) GetFlags(ctx context.Context, ec *EvaluationContext) (f Flags,
194188
return c.GetEnvironmentFlags(ctx)
195189
}
196190

197-
// Returns `Flags` struct holding all the flags for the current environment.
198-
//
199-
// If local evaluation is enabled this function will not call the Flagsmith API
200-
// directly, but instead read the asynchronously updated local environment or
201-
// use the default flag handler in case it has not yet been updated.
202-
//
203-
// Deprecated: Use `GetFlags` instead.
191+
// GetEnvironmentFlags calls GetFlags using the current environment as the EvaluationContext.
192+
// Equivalent to GetFlags(ctx, nil).
204193
func (c *Client) GetEnvironmentFlags(ctx context.Context) (f Flags, err error) {
205194
if c.config.localEvaluation || c.config.offlineMode {
206195
if f, err = c.getEnvironmentFlagsFromEnvironment(); err == nil {
@@ -219,18 +208,7 @@ func (c *Client) GetEnvironmentFlags(ctx context.Context) (f Flags, err error) {
219208
return Flags{}, &FlagsmithClientError{msg: fmt.Sprintf("Failed to fetch flags with error: %s", err)}
220209
}
221210

222-
// Returns `Flags` struct holding all the flags for the current environment for
223-
// a given identity.
224-
//
225-
// If local evaluation is disabled it will also upsert all traits to the
226-
// Flagsmith API for future evaluations. Providing a trait with a value of nil
227-
// will remove the trait from the identity if it exists.
228-
//
229-
// If local evaluation is enabled this function will not call the Flagsmith API
230-
// directly, but instead read the asynchronously updated local environment or
231-
// use the default flag handler in case it has not yet been updated.
232-
//
233-
// Deprecated: Use `GetFlags` providing `EvaluationContext.Identity` instead.
211+
// GetIdentityFlags calls GetFlags using this identifier and traits as the EvaluationContext.
234212
func (c *Client) GetIdentityFlags(ctx context.Context, identifier string, traits []*Trait) (f Flags, err error) {
235213
if c.config.localEvaluation || c.config.offlineMode {
236214
if f, err = c.getIdentityFlagsFromEnvironment(identifier, traits); err == nil {

evaluationcontext.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
package flagsmith
22

3+
// EvaluationContext represents a context in which feature flags can be evaluated.
4+
// Flagsmith flags are always evaluated in an EnvironmentEvaluationContext, with an optional IdentityEvaluationContext.
35
type EvaluationContext struct {
46
Environment *EnvironmentEvaluationContext `json:"environment,omitempty"`
5-
Feature *FeatureEvaluationContext `json:"feature,omitempty"`
67
Identity *IdentityEvaluationContext `json:"identity,omitempty"`
8+
Feature *FeatureEvaluationContext `json:"feature,omitempty"`
79
}
810

11+
// EnvironmentEvaluationContext represents a Flagsmith environment used in an EvaluationContext.
12+
// It is ignored if the evaluating Client was created using WithLocalEvaluation.
913
type EnvironmentEvaluationContext struct {
14+
// APIKey is an identifier for this environment. It is also known as the environment ID or client-side SDK key.
1015
APIKey string `json:"api_key"`
1116
}
1217

13-
type FeatureEvaluationContext struct {
14-
Name string `json:"name"`
15-
}
16-
18+
// IdentityEvaluationContext represents a Flagsmith identity within a Flagsmith environment, used in an EvaluationContext.
19+
// Traits are application-defined key-value pairs which can be used as part of the flag evaluation context.
20+
// Flagsmith will not persist Transient identities when flags are remotely evaluated.
1721
type IdentityEvaluationContext struct {
1822
Identifier *string `json:"identifier,omitempty"`
1923
Traits map[string]*TraitEvaluationContext `json:"traits,omitempty"`
2024
Transient *bool `json:"transient,omitempty"`
2125
}
2226

27+
// TraitEvaluationContext represents a single trait value used within an IdentityEvaluationContext.
28+
// A Transient trait will not be persisted.
2329
type TraitEvaluationContext struct {
2430
Transient *bool `json:"transient,omitempty"`
2531
Value interface{} `json:"value"`
2632
}
33+
34+
// FeatureEvaluationContext is not yet implemented.
35+
type FeatureEvaluationContext struct {
36+
Name string `json:"name"`
37+
}

0 commit comments

Comments
 (0)