forked from nil-go/konf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
31 lines (26 loc) · 1.09 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
// 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"
// 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 in the returned map should be case-insensitive to avoid random overriding.
// 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 onChange 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
}
// 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 {
return sub(c.values, path) != nil
}