MCPcopy
hub / github.com/spf13/viper / SetDefault

Method SetDefault

viper.go:1482–1493  ·  view source on GitHub ↗
(key string, value any)

Source from the content-addressed store, hash-verified

1480func SetDefault(key string, value any) { v.SetDefault(key, value) }
1481
1482func (v *Viper) SetDefault(key string, value any) {
1483 // If alias passed in, then set the proper default
1484 key = v.realKey(strings.ToLower(key))
1485 value = toCaseInsensitiveValue(value)
1486
1487 path := strings.Split(key, v.keyDelim)
1488 lastKey := strings.ToLower(path[len(path)-1])
1489 deepestMap := deepSearch(v.defaults, path[0:len(path)-1])
1490
1491 // set innermost value
1492 deepestMap[lastKey] = value
1493}
1494
1495// Set sets the value for the key in the override register.
1496// Set is case-insensitive for a key.

Callers 15

TestDefaultFunction · 0.80
TestDefaultPostFunction · 0.80
TestUnmarshalFunction · 0.80
TestBindPFlagsIntSliceFunction · 0.80
TestBindPFlagStringToIntFunction · 0.80
TestIsSetFunction · 0.80
TestDirsSearchFunction · 0.80

Calls 3

realKeyMethod · 0.95
toCaseInsensitiveValueFunction · 0.85
deepSearchFunction · 0.85

Tested by 15

TestDefaultFunction · 0.64
TestDefaultPostFunction · 0.64
TestUnmarshalFunction · 0.64
TestBindPFlagsIntSliceFunction · 0.64
TestBindPFlagStringToIntFunction · 0.64
TestIsSetFunction · 0.64
TestDirsSearchFunction · 0.64