-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstancer.go
More file actions
32 lines (24 loc) · 744 Bytes
/
instancer.go
File metadata and controls
32 lines (24 loc) · 744 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
package authorizer
import (
"context"
"fmt"
. "github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/errors"
)
type ContextKey string
const (
INSTANCE_ID = ContextKey("multiinstance.id")
)
type Instancer interface {
GetInstanceId(ctx context.Context) (string, error)
WithInstanceId(ctx context.Context, instanceId string) context.Context
}
type SimpleInstancer struct{}
func (s *SimpleInstancer) GetInstanceId(ctx context.Context) (string, error) {
if v := ctx.Value(INSTANCE_ID); v != nil {
return fmt.Sprintf("%s", v), nil
}
return "", ErrMissingInstanceId
}
func (s *SimpleInstancer) WithInstanceId(ctx context.Context, instanceId string) context.Context {
return context.WithValue(ctx, INSTANCE_ID, instanceId)
}