-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathload.go
More file actions
31 lines (25 loc) · 891 Bytes
/
load.go
File metadata and controls
31 lines (25 loc) · 891 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
package uconfig
import (
"github.com/omeid/uconfig/plugins"
"github.com/omeid/uconfig/plugins/defaults"
"github.com/omeid/uconfig/plugins/env"
"github.com/omeid/uconfig/plugins/file"
)
// UnmarshalOptions represents a set of file paths and the appropriate unmarshaller function.
type UnmarshalOptions = file.UnmarshalOptions
// Load creates a uconfig manager with defaults,environment variables,
// and optionally file loaders based on the provided PluginProvider.
func Load[C any](files PluginProvider, userPlugins ...plugins.Plugin) Config[C] {
ps := make([]plugins.Plugin, 0, 2+len(userPlugins))
// first defaults
ps = append(ps, defaults.New())
// then files
if files != nil {
ps = append(ps, files.Plugins()...)
}
// then any user plugins, often just _secret_.
ps = append(ps, userPlugins...)
// followed by envs
ps = append(ps, env.New())
return New[C](ps...)
}