-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontext.go
40 lines (31 loc) · 904 Bytes
/
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
package dstore
import (
"context"
"github.com/streamingfast/logging"
"go.uber.org/zap"
)
type fileKey string
type storeKey string
func withLogger(ctx context.Context, logger *zap.Logger, tracer logging.Tracer) context.Context {
ctx = context.WithValue(ctx, "logger", logger)
ctx = context.WithValue(ctx, "tracer", tracer)
return ctx
}
func withStoreType(ctx context.Context, storeType string) context.Context {
return context.WithValue(ctx, storeKey("store"), storeType)
}
func StoreTypeFromContext(ctx context.Context) string {
if v := ctx.Value(storeKey("store")); v != nil {
return v.(string)
}
return ""
}
func withFileName(ctx context.Context, filename string) context.Context {
return context.WithValue(ctx, fileKey("file"), filename)
}
func FileNameFromContext(ctx context.Context) string {
if v := ctx.Value(fileKey("file")); v != nil {
return v.(string)
}
return ""
}