-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope.go
More file actions
34 lines (27 loc) · 986 Bytes
/
scope.go
File metadata and controls
34 lines (27 loc) · 986 Bytes
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
package weave
import "context"
type contextKey int
const (
tenantKey contextKey = iota
appKey
)
// TenantFromContext extracts the tenant identifier from the context.
// Returns an empty string if no tenant is set.
func TenantFromContext(ctx context.Context) string {
v, _ := ctx.Value(tenantKey).(string) //nolint:errcheck // zero value is fine
return v
}
// WithTenant returns a copy of ctx with the tenant identifier attached.
func WithTenant(ctx context.Context, tenant string) context.Context {
return context.WithValue(ctx, tenantKey, tenant)
}
// AppFromContext extracts the app identifier from the context.
// Returns an empty string if no app is set.
func AppFromContext(ctx context.Context) string {
v, _ := ctx.Value(appKey).(string) //nolint:errcheck // zero value is fine
return v
}
// WithApp returns a copy of ctx with the app identifier attached.
func WithApp(ctx context.Context, app string) context.Context {
return context.WithValue(ctx, appKey, app)
}