feat(api): add Delete and Sub methods, update CI workflows

- Add Delete(key) to remove keys from all config layers
- Add Sub(key) to get a scoped ConfigManager for nested sections
- Update CodeQL workflow actions to v4/v5/v3
- Update govulncheck workflow checkout to v4
- Remove boilerplate comments from CodeQL workflow
- Add comprehensive tests for both new methods
- Update README with Sub() usage example and API docs
This commit is contained in:
2026-03-07 11:03:48 +00:00
parent 8b154b58ba
commit c8cbb72ed7
7 changed files with 235 additions and 22 deletions

View File

@@ -28,6 +28,19 @@ func (c *ConfigManager) Set(key string, value any) {
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
}
// Delete removes a key from all configuration layers (overrides, file,
// defaults) and rebuilds the combined configuration. Environment variables
// are not affected since they are loaded from the process environment.
func (c *ConfigManager) Delete(key string) {
c.mutex.Lock()
lower := strings.ToLower(key)
delete(c.overrideConfig, lower)
delete(c.fileConfig, lower)
delete(c.defaultConfig, lower)
delete(c.combinedConfig, lower)
c.mutex.Unlock()
}
func (c *ConfigManager) SetDefault(key string, value any) {
c.mutex.Lock()
defer c.mutex.Unlock()