Skip to content

Make EvaluationContext optional when evaluating flags #465

Description

@gabegorelick

Requirements

EvaluationContexts can be defined globally, on the client, on the Go context, or at the point of flag evaluation. Currently, the flag evaluation functions in the Go SDK require an EvaluationContext, even if there is already one defined at a higher level.

// Attach an EvaluationContext globally
openfeature.SetEvaluationContext(openfeature.NewEvaluationContext(
    "",
    map[string]interface{}{
        "myGlobalKey":  "myGlobalValue",
    },
))

// Attach an EvaluationContext to the client
client := openfeature.NewClient("my-app")
client.SetEvaluationContext(openfeature.NewEvaluationContext(
    "", 
    map[string]interface{}{
        "myGlobalKey":  "myGlobalValue",
    },
))

// Attach an EvaluationContext to the Go context
ctx := openfeature.WithTransactionContext(context.TODO(), openfeature.EvaluationContext{})

// You still need to pass an evaluation context here, even though we already attached
// evaluation contexts globally, on the client, and on the Go context.
client.Boolean(ctx, "boolFlag", false, openfeature.EvaluationContext{})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions