[#266] Fix namespace config initialization #274

Merged
alexvanin merged 1 commit from dkirillov/frostfs-s3-gw:bugfix/266-fix_handling_missing_file into master 2023-12-04 09:40:49 +00:00

View file

@ -482,7 +482,7 @@ func fetchNamespacesConfig(l *zap.Logger, v *viper.Viper) NamespacesConfig {
nsConfig, err := readNamespacesConfig(v.GetString(cfgNamespacesConfig))
if err != nil {
l.Warn(logs.FailedToParseNamespacesConfig)
l.Warn(logs.FailedToParseNamespacesConfig, zap.Error(err))
}
defaultNamespacesNames := fetchDefaultNamespaces(l, v)
@ -516,18 +516,21 @@ func fetchNamespacesConfig(l *zap.Logger, v *viper.Viper) NamespacesConfig {
}
func readNamespacesConfig(filepath string) (NamespacesConfig, error) {
nsConfig := NamespacesConfig{
Namespaces: make(Namespaces),
}
if filepath == "" {
return NamespacesConfig{}, nil
return nsConfig, nil
}
data, err := os.ReadFile(filepath)
if err != nil {
return NamespacesConfig{}, fmt.Errorf("failed to read namespace config '%s': %w", filepath, err)
return nsConfig, fmt.Errorf("failed to read namespace config '%s': %w", filepath, err)
}
var nsConfig NamespacesConfig
if err = json.Unmarshal(data, &nsConfig); err != nil {
return NamespacesConfig{}, fmt.Errorf("failed to parse namespace config: %w", err)
return nsConfig, fmt.Errorf("failed to parse namespace config: %w", err)
}
return nsConfig, nil