forked from nil-go/konf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
46 lines (38 loc) · 1.34 KB
/
provider.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
// Copyright (c) 2024 The konf authors
// Use of this source code is governed by a MIT license found in the LICENSE file.
package konf
import (
"context"
"strings"
)
// Loader is the interface that wraps the Load method.
//
// Load loads the latest configuration and returns it as a nested map[string]any.
// The keys should be nested like `{parent: {child: {key: 1}}}`.
type Loader interface {
Load() (map[string]any, error)
}
// Watcher is the interface that wraps the Watch method.
//
// Watch watches the configuration and triggers the register callback with the latest
// full configurations as a nested map[string]any when it changes.
// It blocks until ctx is done, or the watching returns an error.
type Watcher interface {
Watch(ctx context.Context, onChange func(map[string]any)) error
}
// Statuser is the interface that wraps the Status method.
//
// Status enables providers report the status of configuration loading/watching.
type Statuser interface {
Status(onStatus func(changed bool, err error))
}
// Exists tests if the given path exist in the configuration.
//
// It's used by the loader to check if the configuration has been set by other loaders.
func (c *Config) Exists(path []string) bool {
if c == nil || c.values.Load() == nil {
return false
}
c.nocopy.Check()
return c.sub(*c.values.Load(), strings.Join(path, c.delim())) != nil
}