2 Commits

Author SHA1 Message Date
9c5923bd4e fix mutex 2023-11-03 03:42:21 -07:00
5643d4d262 send back custom error 2023-11-03 03:18:37 -07:00

View File

@@ -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,13 +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)