mirror of
https://github.com/taigrr/jety.git
synced 2026-04-16 18:35:13 -07:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
5643d4d262
|
|||
|
ee74c94359
|
|||
|
e84645ccfa
|
|||
|
b2e7785e00
|
|||
|
ef3350d66d
|
@@ -1,6 +1,6 @@
|
|||||||
# JETY
|
# 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.
|
This is a package for collapsing multiple configuration stores (env+json, env+yaml, env+toml) and writing them back to a centralized config.
|
||||||
|
|
||||||
|
|||||||
4
jety.go
4
jety.go
@@ -175,11 +175,15 @@ func (c *ConfigManager) ReadInConfig() error {
|
|||||||
conf[lower] = ConfigMap{Key: k, Value: v}
|
conf[lower] = ConfigMap{Key: k, Value: v}
|
||||||
}
|
}
|
||||||
c.mapConfig = conf
|
c.mapConfig = conf
|
||||||
|
c.collapse()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFile(filename string, fileType configType) (map[string]any, error) {
|
func readFile(filename string, fileType configType) (map[string]any, error) {
|
||||||
fileData := make(map[string]any)
|
fileData := make(map[string]any)
|
||||||
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
|
return nil, ErrConfigFileNotFound
|
||||||
|
}
|
||||||
switch fileType {
|
switch fileType {
|
||||||
case ConfigTypeTOML:
|
case ConfigTypeTOML:
|
||||||
_, err := toml.DecodeFile(filename, &fileData)
|
_, err := toml.DecodeFile(filename, &fileData)
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ func (c *ConfigManager) SetDefault(key string, value any) {
|
|||||||
lower := strings.ToLower(key)
|
lower := strings.ToLower(key)
|
||||||
c.defaultConfig[lower] = ConfigMap{Key: key, Value: value}
|
c.defaultConfig[lower] = ConfigMap{Key: key, Value: value}
|
||||||
if _, ok := c.mapConfig[lower]; !ok {
|
if _, ok := c.mapConfig[lower]; !ok {
|
||||||
if envVal, ok := c.envConfig[lower]; !ok {
|
if envVal, ok := c.envConfig[lower]; ok {
|
||||||
c.mapConfig[lower] = envVal
|
c.mapConfig[lower] = envVal
|
||||||
c.combinedConfig[lower] = envVal
|
c.combinedConfig[lower] = envVal
|
||||||
|
} else {
|
||||||
|
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c.combinedConfig[lower] = c.mapConfig[lower]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user