From 47821829af91aea278808fdae2c5de143640890e Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Thu, 2 Nov 2023 22:35:05 -0700 Subject: [PATCH] clarify readme, extract setters --- README.md | 16 +--------------- env.go | 14 -------------- setters.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 setters.go diff --git a/README.md b/README.md index ca45045..d15aef7 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,4 @@ This is a package for collapsing multiple configuration stores (env+json, env+ya It should behave similarly to the AutomaticEnv functionality of viper, but without some of the extra heft of the depedendencies it carries. - -.AutomaticEnv -.ConfigFileUsed -.GetDuration -.GetString -.GetStringMap -.GetStringSlice -.ReadInConfig -.SetConfigFile -.SetConfigName -.SetConfigType -.SetDefault -.Set("privkey", string -viper.ConfigFileNotFoundError); ok { -.WriteConfig +The inital purpose of this repo is to support the configuration requirements of [grlx](http://github.com/gogrlx/grlx), but development may continue to expand until more viper use cases and functionality are covered. diff --git a/env.go b/env.go index dd740b0..79e9f00 100644 --- a/env.go +++ b/env.go @@ -273,20 +273,6 @@ func (c *ConfigManager) SetEnvPrefix(prefix string) { c.envPrefix = prefix } -func (c *ConfigManager) Set(key string, value any) { - c.mutex.Lock() - defer c.mutex.Unlock() - lower := strings.ToLower(key) - c.mapConfig[lower] = ConfigMap{Key: key, Value: value} -} - -func (c *ConfigManager) SetDefault(key string, value any) { - c.mutex.Lock() - defer c.mutex.Unlock() - lower := strings.ToLower(key) - c.defaultConfig[lower] = ConfigMap{Key: key, Value: value} -} - func (c *ConfigManager) GetIntSlice(key string) []int { c.mutex.RLock() defer c.mutex.RUnlock() diff --git a/setters.go b/setters.go new file mode 100644 index 0000000..4133e95 --- /dev/null +++ b/setters.go @@ -0,0 +1,33 @@ +package config + +import ( + "strings" +) + +func (c *ConfigManager) SetBool(key string, value bool) { + c.mutex.Lock() + defer c.mutex.Unlock() + lower := strings.ToLower(key) + c.mapConfig[lower] = ConfigMap{Key: key, Value: value} +} + +func (c *ConfigManager) SetString(key string, value string) { + c.mutex.Lock() + defer c.mutex.Unlock() + lower := strings.ToLower(key) + c.mapConfig[lower] = ConfigMap{Key: key, Value: value} +} + +func (c *ConfigManager) Set(key string, value any) { + c.mutex.Lock() + defer c.mutex.Unlock() + lower := strings.ToLower(key) + c.mapConfig[lower] = ConfigMap{Key: key, Value: value} +} + +func (c *ConfigManager) SetDefault(key string, value any) { + c.mutex.Lock() + defer c.mutex.Unlock() + lower := strings.ToLower(key) + c.defaultConfig[lower] = ConfigMap{Key: key, Value: value} +}