blob: 8bb02b2f57571483f5aa2dc0ff8ac8ac3dbb4812 (
plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package common
import (
"context"
"database/sql"
)
type Key uint8
const (
keyDB Key = 0
keyDebug Key = 1
keyAuthor Key = 2
KeyCopaingState Key = 3
)
func SetDB(ctx context.Context, db *sql.DB) context.Context {
return context.WithValue(ctx, keyDB, db)
}
func GetDB(ctx context.Context) *sql.DB {
raw := ctx.Value(keyDB)
if raw == nil {
return nil
}
return raw.(*sql.DB)
}
func SetDebug(ctx context.Context, b bool) context.Context {
return context.WithValue(ctx, keyDebug, b)
}
func IsDebug(ctx context.Context) bool {
raw := ctx.Value(keyDebug)
if raw == nil {
return false
}
return raw.(bool)
}
func SetAuthor(ctx context.Context, s string) context.Context {
return context.WithValue(ctx, keyAuthor, s)
}
func GetAuthor(ctx context.Context) string {
raw := ctx.Value(keyAuthor)
if raw == nil {
return ""
}
return raw.(string)
}
|