We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
ContextOperator.Inject
BUG: default ContextOperator use database (TxBeginner) for extracting and injecting ( Inject/Extract) transaction (Tx) to context.Context:
ContextOperator
TxBeginner
Inject
Extract
Tx
context.Context
// ContextOperator inject and extract Tx from context.Context. type ContextOperator[B any 👈🏻 , T Tx] struct { beginner *B } // NewContextOperator returns new ContextOperator. func NewContextOperator[B any, T Tx](b *B) *ContextOperator[B, T] { return &ContextOperator[B, T]{ beginner: b, } } // Inject returns new context.Context contains Tx as value. func (p *ContextOperator[B, T]) Inject(ctx context.Context, tx T) context.Context { return context.WithValue(ctx, p.beginner, tx) 👈🏻 } // Extract returns Tx extracted from context.Context. func (p *ContextOperator[B, T]) Extract(ctx context.Context) (T, bool) { c, ok := ctx.Value(p.beginner).(T) 👈🏻 return c, ok }
if type B is not comparable, context.Context produce the panic: " key is not comparable"
B
To avoid the produce, need to change type B to comparable:
comparable
// ContextOperator inject and extract Tx from context.Context. type ContextOperator[B comparable, T Tx] struct { beginner B } // NewContextOperator returns new ContextOperator. func NewContextOperator[B comparable, T Tx](b B) *ContextOperator[B, T] { return &ContextOperator[B, T]{ beginner: b, } }
ENCHANCEMENT: default ContextOperator use *B type in the constructor. It's a bit unhandy.
*B
// NewContextOperator returns new ContextOperator. func NewContextOperator[B any, T Tx](b *B 👈🏻) *ContextOperator[B, T] { return &ContextOperator[B, T]{ beginner: b, } }
the pointer may be removed.
The text was updated successfully, but these errors were encountered:
[#88] fix default ContextOperator: change B to comparable
ce6b817
50b9ec4
48a2436
4465a69
key
Merge pull request #89 from kozmod/bugfix/88_context_operator_B_compa…
f0263dc
…rable [#88] fix default `ContextOperator`: change `B` to comparable
kozmod
Successfully merging a pull request may close this issue.
Description
BUG:
default
ContextOperator
use database (TxBeginner
) for extracting and injecting (Inject
/Extract
) transaction (Tx
) tocontext.Context
:if type
B
is not comparable,context.Context
produce the panic: " key is not comparable"To avoid the produce, need to change type
B
tocomparable
:ENCHANCEMENT:
default
ContextOperator
use*B
type in the constructor. It's a bit unhandy.the pointer may be removed.
The text was updated successfully, but these errors were encountered: