diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
| commit | 44a426c883a2c448d40a19903c822d03e5cf70af (patch) | |
| tree | dbb1fe11db1993c2cac7daf1c9930e37f44b38d1 /internal/config/config.go | |
| parent | cfddc5696f4956081630e3d394ef3d8c652af02e (diff) | |
chore: complete code quality audit fixesv1.2.6
- Fixed failing test in config_test.go (hardcoded date)
- Addressed unchecked error returns from Close() operations
- Refactored large functions to follow SRP (run.go and main.go)
- Added documentation to exported identifiers
- Fixed linting errors (error message capitalization, errcheck)
- Bumped version to v1.2.6
Diffstat (limited to 'internal/config/config.go')
| -rw-r--r-- | internal/config/config.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 8b101be..73dae9f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,7 +11,8 @@ import ( "codeberg.org/snonux/gos/internal/colour" ) -// The config file containing all the secrets and credentials plus maybe more. +// Config holds the application configuration loaded from the JSON config file. +// It contains secrets, credentials, and various settings for the application. type Config struct { LastRunEpoch int64 `json:"LastRunEpoch,omitempty"` MastodonURL string @@ -48,7 +49,12 @@ func New(configPath string, composeEntry bool) (Config, error) { if err != nil { return conf, fmt.Errorf("failed to open file: %w", err) } - defer file.Close() + defer func() { + if err := file.Close(); err != nil { + // Log the error but don't fail the operation since we've already written the data + colour.Errorln("Error closing file:", err) + } + }() bytes, err := io.ReadAll(file) if err != nil { @@ -77,7 +83,12 @@ func (s Config) WriteToDisk(configPath string) error { if err != nil { return fmt.Errorf("failed to create file: %w", err) } - defer file.Close() + defer func() { + if err := file.Close(); err != nil { + // Log the error but don't fail the operation since we've already written the data + colour.Errorln("Error closing file:", err) + } + }() if _, err := file.Write(bytes); err != nil { return fmt.Errorf("failed to write to file: %w", err) |
