mirror of
https://github.com/taigrr/jety.git
synced 2026-04-02 03:19:03 -07:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9c5923bd4e
|
|||
|
5643d4d262
|
|||
|
ee74c94359
|
|||
|
e84645ccfa
|
@@ -1,6 +1,6 @@
|
||||
# JETY
|
||||
|
||||
JSON, ENV, YAML, TOML
|
||||
JSON, ENV, TOML, YAML
|
||||
|
||||
This is a package for collapsing multiple configuration stores (env+json, env+yaml, env+toml) and writing them back to a centralized config.
|
||||
|
||||
|
||||
8
jety.go
8
jety.go
@@ -162,8 +162,6 @@ func (c *ConfigManager) SetEnvPrefix(prefix string) {
|
||||
}
|
||||
|
||||
func (c *ConfigManager) ReadInConfig() error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
// assume config = map[string]any
|
||||
confFileData, err := readFile(c.configFileUsed, c.configType)
|
||||
if err != nil {
|
||||
@@ -174,12 +172,18 @@ func (c *ConfigManager) ReadInConfig() error {
|
||||
lower := strings.ToLower(k)
|
||||
conf[lower] = ConfigMap{Key: k, Value: v}
|
||||
}
|
||||
c.mutex.Lock()
|
||||
c.mapConfig = conf
|
||||
c.mutex.Unlock()
|
||||
c.collapse()
|
||||
return nil
|
||||
}
|
||||
|
||||
func readFile(filename string, fileType configType) (map[string]any, error) {
|
||||
fileData := make(map[string]any)
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
return nil, ErrConfigFileNotFound
|
||||
}
|
||||
switch fileType {
|
||||
case ConfigTypeTOML:
|
||||
_, err := toml.DecodeFile(filename, &fileData)
|
||||
|
||||
@@ -40,5 +40,7 @@ func (c *ConfigManager) SetDefault(key string, value any) {
|
||||
} else {
|
||||
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
|
||||
}
|
||||
} else {
|
||||
c.combinedConfig[lower] = c.mapConfig[lower]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user