-
Notifications
You must be signed in to change notification settings - Fork 87
/
noop.go
33 lines (26 loc) · 895 Bytes
/
noop.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
package provider
import (
"context"
)
// A NoopProvider is a provider that always returns a noop providable regardless of the key
type NoopProvider[Value Providable] struct {
providable Value
}
// Get implements Provider
func (p *NoopProvider[Value]) Get(ctx context.Context, key string) (v Value, err error) {
return p.providable, nil
}
// Has implements Provider
func (p *NoopProvider[Value]) Has(ctx context.Context, key string) bool {
isInstalled, err := p.providable.IsInstalled(ctx)
return isInstalled && err == nil
}
// Keys implements Provider
func (p *NoopProvider[Value]) Keys(context.Context) []string {
return []string{"noop"}
}
func NewNoopProvider[Value Providable](providable Value) Provider[Value] {
return &NoopProvider[Value]{providable: providable}
}
// compile-time check that we implement the interface
var _ Provider[Providable] = &NoopProvider[Providable]{}