Related to #413
|
// WithTransactionContext constructs a TransactionContext. |
|
// |
|
// ctx - the context to embed the EvaluationContext in |
|
// ec - the EvaluationContext to embed into the context |
|
func WithTransactionContext(ctx context.Context, ec EvaluationContext) context.Context { |
|
return context.WithValue(ctx, internal.TransactionContext, ec) |
|
} |
|
|
|
// MergeTransactionContext merges the provided EvaluationContext with the current TransactionContext (if it exists) |
|
// |
|
// ctx - the context to pull existing TransactionContext from |
|
// ec - the EvaluationContext to merge with the existing TransactionContext |
|
func MergeTransactionContext(ctx context.Context, ec EvaluationContext) context.Context { |
|
oldTc := TransactionContext(ctx) |
|
mergedTc := mergeContexts(ec, oldTc) |
|
return WithTransactionContext(ctx, mergedTc) |
|
} |
|
|
|
// TransactionContext extracts a EvaluationContext from the current |
|
// golang.org/x/net/context. if no EvaluationContext exist, it will construct |
|
// an empty EvaluationContext |
|
// |
|
// ctx - the context to pull EvaluationContext from |
|
func TransactionContext(ctx context.Context) EvaluationContext { |
|
ec, ok := ctx.Value(internal.TransactionContext).(EvaluationContext) |
|
|
|
if !ok { |
|
return EvaluationContext{} |
|
} |
|
|
|
return ec |
|
} |
My proposal is that we deprecate these functions and turn them into package-level variables that are assigned to the new functions.
See the OTel trace package for good names for these types of functions.
The convention here is TypeNameFromContext and ContextWithTypeName, where TypeName is the name of the type of identifier being stored/retrieved from the context.
Note that MergeTransactionContext will be handled in a separate issue, as it's a bit more involved.
Related to #413
go-sdk/openfeature/evaluation_context.go
Lines 60 to 91 in 4b3d6d9
My proposal is that we deprecate these functions and turn them into package-level variables that are assigned to the new functions.
ContextWithEvaluationContext.EvaluationContextFromContext.See the OTel trace package for good names for these types of functions.
The convention here is
TypeNameFromContextandContextWithTypeName, whereTypeNameis the name of the type of identifier being stored/retrieved from the context.Note that
MergeTransactionContextwill be handled in a separate issue, as it's a bit more involved.