forked from segmentio/go-athena
-
Notifications
You must be signed in to change notification settings - Fork 3
/
context.go
72 lines (53 loc) · 1.88 KB
/
context.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package athena
import "context"
const contextPrefix string = "go-athena"
/*
* Result Mode
*/
const resultModeContextKey string = "result_mode_key"
// ResultModeContextKey context key of setting result mode
var ResultModeContextKey string = contextPrefix + resultModeContextKey
// SetAPIMode set APIMode to ResultMode from context
func SetAPIMode(ctx context.Context) context.Context {
return context.WithValue(ctx, ResultModeContextKey, ResultModeAPI)
}
// SetDLMode set DownloadMode to ResultMode from context
func SetDLMode(ctx context.Context) context.Context {
return context.WithValue(ctx, ResultModeContextKey, ResultModeDL)
}
// SetGzipDLMode set CTASMode to ResultMode from context
func SetGzipDLMode(ctx context.Context) context.Context {
return context.WithValue(ctx, ResultModeContextKey, ResultModeGzipDL)
}
func getResultMode(ctx context.Context) (ResultMode, bool) {
val, ok := ctx.Value(ResultModeContextKey).(ResultMode)
return val, ok
}
/*
* timeout
*/
const timeoutContextKey string = "timeout_key"
// TimeoutContextKey context key of setting timeout
var TimeoutContextKey string = contextPrefix + timeoutContextKey
// SetTimeout set timeout from context
func SetTimeout(ctx context.Context, timeout uint) context.Context {
return context.WithValue(ctx, TimeoutContextKey, timeout)
}
func getTimeout(ctx context.Context) (uint, bool) {
val, ok := ctx.Value(TimeoutContextKey).(uint)
return val, ok
}
/*
* catalog
*/
const catalogContextKey string = "catalog_key"
// CatalogContextKey context key of setting catalog
var CatalogContextKey string = contextPrefix + catalogContextKey
// SetCatalog set catalog from context
func SetCatalog(ctx context.Context, catalog string) context.Context {
return context.WithValue(ctx, CatalogContextKey, catalog)
}
func getCatalog(ctx context.Context) (string, bool) {
val, ok := ctx.Value(CatalogContextKey).(string)
return val, ok
}