-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go1.8beta1
What operating system and processor architecture are you using (go env
)?
linux/amd64
What did you do?
See https://groups.google.com/forum/#!topic/golang-nuts/20NtIGTgBeg
What did you expect to see?
A nice, clean API just as before, and not using context.Context for transferring options.
What did you see instead?
ReadOnlyContext and IsolationContext to passes isolation level and readonly flag in the Context.
I'd modify BeginContext as
func (db *DB) BeginContext(ctx context.Context, options... TxOption) (*Tx, error)
type TxOption func(*txOption)
type txOption struct {
IsReadOnly bool
IsolationLevel
}
func WithIsolationLevel(level IsolationLevel) TxOption { return func(o *txOption) { o.IsolationLevel = level } }
func WithReadOnly(readOnly bool) TxOption { return func(o *txOption) { o.IsReadOnly = readOnly } }
This does not block anybody to use the Context as bag-of-values, but at least does not encourage that.
dominikh, ash2k, yanpozka and cocojas