MCPcopy
hub / github.com/knadh/koanf / Load

Method Load

koanf.go:93–123  ·  view source on GitHub ↗

Load takes a Provider that either provides a parsed config map[string]any in which case pa (Parser) can be nil, or raw bytes to be parsed, where a Parser can be provided to parse. Additionally, options can be passed which modify the load behavior, such as passing a custom merge function.

(p Provider, pa Parser, opts ...Option)

Source from the content-addressed store, hash-verified

91// can be provided to parse. Additionally, options can be passed which modify the
92// load behavior, such as passing a custom merge function.
93func (ko *Koanf) Load(p Provider, pa Parser, opts ...Option) error {
94 var (
95 mp map[string]any
96 err error
97 )
98
99 if p == nil {
100 return fmt.Errorf("load received a nil provider")
101 }
102
103 // No Parser is given. Call the Provider's Read() method to get
104 // the config map.
105 if pa == nil {
106 mp, err = p.Read()
107 if err != nil {
108 return err
109 }
110 } else {
111 // There's a Parser. Get raw bytes from the Provider to parse.
112 b, err := p.ReadBytes()
113 if err != nil {
114 return err
115 }
116 mp, err = pa.Unmarshal(b)
117 if err != nil {
118 return err
119 }
120 }
121
122 return ko.merge(mp, newOptions(opts))
123}
124
125// Keys returns the slice of all flattened keys in the loaded configuration
126// sorted alphabetically.

Callers 15

TestCliFlagFunction · 0.80
TestCliFlagFunction · 0.80
TestNatsFunction · 0.80
TestLoadFunction · 0.80
TestIssue90Function · 0.80
TestIssue100Function · 0.80
TestFSProviderFunction · 0.80
initFunction · 0.80
BenchmarkLoadFileFunction · 0.80
TestLoadMergeYamlJsonFunction · 0.80
TestLoadMergeJsonYamlFunction · 0.80

Calls 5

mergeMethod · 0.95
newOptionsFunction · 0.85
ReadMethod · 0.65
ReadBytesMethod · 0.65
UnmarshalMethod · 0.65

Tested by 15

TestCliFlagFunction · 0.64
TestCliFlagFunction · 0.64
TestNatsFunction · 0.64
TestLoadFunction · 0.64
TestIssue90Function · 0.64
TestIssue100Function · 0.64
TestFSProviderFunction · 0.64
initFunction · 0.64
BenchmarkLoadFileFunction · 0.64
TestLoadMergeYamlJsonFunction · 0.64
TestLoadMergeJsonYamlFunction · 0.64