feat(getters): add GetFloat64 and GetInt64, fix docs

- Add GetFloat64 and GetInt64 methods to ConfigManager and package-level API
- Fix README precedence: actual order is Set > env > file > default
  (was incorrectly documented as file > env > default)
- Fix GetStringMap return type in API table: map[string]any, not map[string]string
- Bump Go to 1.26.1
- Add tests for all new getters (coverage 94.7% → 95.2%)
This commit is contained in:
2026-03-06 10:32:42 +00:00
parent 60253426ae
commit dd7e2e3ecb
5 changed files with 162 additions and 6 deletions

View File

@@ -146,6 +146,64 @@ func (c *ConfigManager) GetStringSlice(key string) []string {
}
}
func (c *ConfigManager) GetFloat64(key string) float64 {
c.mutex.RLock()
defer c.mutex.RUnlock()
v, ok := c.resolve(key)
if !ok {
return 0
}
switch val := v.Value.(type) {
case float64:
return val
case float32:
return float64(val)
case int:
return float64(val)
case int64:
return float64(val)
case string:
f, err := strconv.ParseFloat(val, 64)
if err != nil {
return 0
}
return f
case nil:
return 0
default:
return 0
}
}
func (c *ConfigManager) GetInt64(key string) int64 {
c.mutex.RLock()
defer c.mutex.RUnlock()
v, ok := c.resolve(key)
if !ok {
return 0
}
switch val := v.Value.(type) {
case int64:
return val
case int:
return int64(val)
case string:
i, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return 0
}
return i
case float32:
return int64(val)
case float64:
return int64(val)
case nil:
return 0
default:
return 0
}
}
func (c *ConfigManager) GetInt(key string) int {
c.mutex.RLock()
defer c.mutex.RUnlock()