-
Notifications
You must be signed in to change notification settings - Fork 47
/
metering.go
47 lines (36 loc) · 902 Bytes
/
metering.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
package reqctx
import (
"context"
"google.golang.org/grpc/metadata"
)
var backFillerKey = "livebackfiller"
func WithBackfillerRequest(ctx context.Context) context.Context {
return metadata.AppendToOutgoingContext(ctx, backFillerKey, "true")
}
func HasBackfillerRequest(ctx context.Context) bool {
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
return false
}
_, ok = md[backFillerKey]
return ok
}
func IsBackfillerRequest(ctx context.Context) bool {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return false
}
_, ok = md[backFillerKey]
return ok
}
type outputModuleKeyType int
func WithOutputModuleHash(ctx context.Context, hash string) context.Context {
return context.WithValue(ctx, outputModuleHashKey, hash)
}
func OutputModuleHash(ctx context.Context) string {
hash, ok := ctx.Value(outputModuleHashKey).(string)
if !ok {
return ""
}
return hash
}