Skip to content

Commit

Permalink
fix: targeting key serialization fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Feb 13, 2024
1 parent cf305c9 commit e86e78e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions demo/GoDemoApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ func main() {

attributes := make(map[string]interface{})
targetingKey := uuid.New().String()
attributes["targeting_key"] = targetingKey

fmt.Println(" Random UUID -> " + targetingKey)

of := openfeature.NewEvaluationContext("", attributes)
of := openfeature.NewEvaluationContext(targetingKey, attributes)

colorValue, _ := client.StringValue(context.Background(), "hawkflag.color", "defaultValue", of)
messageValue, _ := client.StringValue(context.Background(), "hawkflag.message", "defaultValue", of)
Expand Down
11 changes: 10 additions & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (e FlagProvider) resolveFlag(ctx context.Context, flag string, defaultValue
requestFlagName := fmt.Sprintf("flags/%s", flagName)
resp, err := e.ResolveClient.sendResolveRequest(ctx,
resolveRequest{ClientSecret: e.Config.APIKey,
Flags: []string{requestFlagName}, Apply: true, EvaluationContext: evalCtx,
Flags: []string{requestFlagName}, Apply: true, EvaluationContext: processTargetingKey(evalCtx),
Sdk: sdk{Id: SDK_ID, Version: SDK_VERSION}})

if err != nil {
Expand All @@ -96,6 +96,15 @@ func (e FlagProvider) resolveFlag(ctx context.Context, flag string, defaultValue
return processResolvedFlag(resolvedFlag, defaultValue, expectedKind, propertyPath)
}

func processTargetingKey(evalCtx openfeature.FlattenedContext) openfeature.FlattenedContext {
newEvalContext := openfeature.FlattenedContext{}
newEvalContext = evalCtx
if targetingKey, exists := evalCtx["targetingKey"]; exists {
newEvalContext["targeting_key"] = targetingKey
}
return newEvalContext
}

func (e FlagProvider) Hooks() []openfeature.Hook {
return []openfeature.Hook{}
}

0 comments on commit e86e78e

Please sign in to comment.