|
|
@ -28,12 +28,15 @@ type StorageSettings struct { |
|
|
|
func parseSettings(data []byte) Settings { |
|
|
|
settings := Settings{} |
|
|
|
|
|
|
|
json.Unmarshal(data, &settings) |
|
|
|
err := json.Unmarshal(data, &settings) |
|
|
|
if err != nil { |
|
|
|
return Settings{} |
|
|
|
} |
|
|
|
|
|
|
|
return settings |
|
|
|
} |
|
|
|
|
|
|
|
func LoadSettings(fileSystem afero.Fs) Settings { |
|
|
|
func LoadSettings(fileSystem afero.Fs) (Settings, error) { |
|
|
|
workingDirectory, _ := os.Getwd() |
|
|
|
path := filepath.Join(workingDirectory, "settings.json") |
|
|
|
|
|
|
@ -41,7 +44,7 @@ func LoadSettings(fileSystem afero.Fs) Settings { |
|
|
|
data, err := afero.ReadFile(fileSystem, path) |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
return parseSettings(data) |
|
|
|
return parseSettings(data), nil |
|
|
|
} |
|
|
|
|
|
|
|
// If file does not exist, create default settings
|
|
|
@ -55,7 +58,14 @@ func LoadSettings(fileSystem afero.Fs) Settings { |
|
|
|
} |
|
|
|
|
|
|
|
serializedSettings, err := json.MarshalIndent(defaultSettings, "", "\t") |
|
|
|
afero.WriteFile(fileSystem, path, serializedSettings, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
return Settings{}, err |
|
|
|
} |
|
|
|
|
|
|
|
err = afero.WriteFile(fileSystem, path, serializedSettings, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
return Settings{}, err |
|
|
|
} |
|
|
|
|
|
|
|
return defaultSettings |
|
|
|
return defaultSettings, nil |
|
|
|
} |