refactor: remove unnecessary type conversions and handle ignored errors across codebase

Remove redundant type conversions that Go 1.26 makes unnecessary or that
were already no-ops:

- uuid.UUID(x.Bytes) → x.Bytes (uuid.UUID is [16]byte, same as pgtype UUID Bytes)
- pgtype.UUID{Bytes: [16]byte(u), Valid: true} → pgtype.UUID{Bytes: u, Valid: true}
- (*time.Time)(&x.Time) → &x.Time
- json.RawMessage(x) → x where x is already []byte
- []byte(stringVal) → stringVal where []byte is expected
- int()/int64()/byte() casts on values already of the target type
- Decompressor(fn) → fn (type is identical)

Handle previously ignored error returns:

- collections.go: check json.Unmarshal error in GetCollection
- conversion_service.go: check fileSize.Scan() error
- app_test.go: check app.Shutdown() error in benchmark
This commit is contained in:
2026-04-21 21:15:59 -04:00
parent ad27902790
commit e389df92c3
23 changed files with 85 additions and 75 deletions
+5 -1
View File
@@ -12,6 +12,7 @@ import (
"time"
"bookhoard/internal/database"
"github.com/jackc/pgx/v5/pgtype"
)
@@ -81,7 +82,10 @@ func (s *ConversionService) ConvertEPUBToKEPUB(ctx context.Context, mediaItemID
}
var fileSize pgtype.Int8
fileSize.Scan(int64(fileinfo.Size()))
err = fileSize.Scan(fileinfo.Size())
if err != nil {
return nil, err
}
_, err = s.db.CreateMediaItemFormat(ctx, database.CreateMediaItemFormatParams{
MediaItemID: mediaItemID,
+2 -2
View File
@@ -154,7 +154,7 @@ func (s *DashboardService) GetDashboardSections(
}
results = append(results, DashboardSection{
CollectionID: uuid.UUID(coll.ID.Bytes),
CollectionID: coll.ID.Bytes,
CollectionName: coll.Name,
Items: items,
QueryType: coll.QueryType.String,
@@ -182,7 +182,7 @@ func (s *DashboardService) GetDashboardSections(
}
results = append(results, DashboardSection{
CollectionID: uuid.UUID(coll.ID.Bytes),
CollectionID: coll.ID.Bytes,
CollectionName: coll.Name,
Items: items,
QueryType: coll.QueryType.String,
+1 -1
View File
@@ -1536,7 +1536,7 @@ func (s *MediaScanner) extractEPUBCover(epubPath string) (string, error) {
opfStartAttr += len("full-path=")
quote := content[opfStart+opfStartAttr]
opfStartQuote := opfStart + opfStartAttr + 1
opfEndQuote := bytes.Index(content[opfStartQuote:], []byte{byte(quote)})
opfEndQuote := bytes.Index(content[opfStartQuote:], []byte{quote})
if opfEndQuote == -1 {
continue
}
+1 -1
View File
@@ -383,7 +383,7 @@ func (s *ReaderService) UpdateSettings(
// Update in database
_, err = s.db.UpsertReaderSettings(ctx, database.UpsertReaderSettingsParams{
UserID: pgtype.UUID{Bytes: userID, Valid: true},
SettingValue: []byte(settingsJSON),
SettingValue: settingsJSON,
})
return err