-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
persister.go
38 lines (32 loc) · 1.03 KB
/
persister.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package operator // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
import (
"context"
"fmt"
)
// Persister is an interface used to persist data
type Persister interface {
Get(context.Context, string) ([]byte, error)
Set(context.Context, string, []byte) error
Delete(context.Context, string) error
}
type scopedPersister struct {
Persister
scope string
}
func NewScopedPersister(s string, p Persister) Persister {
return &scopedPersister{
Persister: p,
scope: s,
}
}
func (p scopedPersister) Get(ctx context.Context, key string) ([]byte, error) {
return p.Persister.Get(ctx, fmt.Sprintf("%s.%s", p.scope, key))
}
func (p scopedPersister) Set(ctx context.Context, key string, value []byte) error {
return p.Persister.Set(ctx, fmt.Sprintf("%s.%s", p.scope, key), value)
}
func (p scopedPersister) Delete(ctx context.Context, key string) error {
return p.Persister.Delete(ctx, fmt.Sprintf("%s.%s", p.scope, key))
}