-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctx.go
27 lines (22 loc) · 765 Bytes
/
ctx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2016 Tamás Gulácsi. All rights reserved.
// Use of this source code is governed by The MIT License
// found in the accompanying LICENSE file.
package ora
import "context"
const (
stmtCfgKey = "stmtCfg"
)
// ctxStmtCfg returns the StmtCfg from the context, and
// whether it exist at all.
func ctxStmtCfg(ctx context.Context) (StmtCfg, bool) {
cfg, ok := ctx.Value(stmtCfgKey).(StmtCfg)
return cfg, ok
}
// WithStmtCfg returns a new context, with the given cfg that
// can be used to configure several parameters.
//
// WARNING: the StmtCfg must be derived from Cfg(), or NewStmtCfg(),
// as an empty StmtCfg is not usable!
func WithStmtCfg(ctx context.Context, cfg StmtCfg) context.Context {
return context.WithValue(ctx, stmtCfgKey, cfg)
}