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
+9 -6
View File
@@ -160,12 +160,12 @@ func (h *CollectionHandler) GetCollections(c *echo.Context) error {
continue
}
response = append(response, CollectionResponse{
ID: uuid.UUID(col.ID.Bytes),
ID: col.ID.Bytes,
Name: col.Name,
Description: textToString(col.Description),
Color: textToString(col.Color),
Icon: textToString(col.Icon),
AutoAssignRules: json.RawMessage(col.AutoAssignRules),
AutoAssignRules: col.AutoAssignRules,
CreatedAt: col.CreatedAt.Time.String(),
})
}
@@ -214,7 +214,10 @@ func (h *CollectionHandler) GetCollection(c *echo.Context) error {
var viewSettings map[string]interface{}
if len(collection.ViewSettings) > 0 {
json.Unmarshal(collection.ViewSettings, &viewSettings)
err := json.Unmarshal(collection.ViewSettings, &viewSettings)
if err != nil {
return err
}
}
return c.JSON(http.StatusOK, map[string]interface{}{
@@ -460,8 +463,8 @@ func (h *CollectionHandler) GetDeviceMappings(c *echo.Context) error {
response := make([]MappingResponse, 0, len(mappings))
for _, m := range mappings {
response = append(response, MappingResponse{
ID: uuid.UUID(m.ID.Bytes),
CollectionID: uuid.UUID(m.CollectionID.Bytes),
ID: m.ID.Bytes,
CollectionID: m.CollectionID.Bytes,
CollectionName: m.CollectionName,
DeviceShelfName: textToString(m.DeviceShelfName),
SyncDirection: textToString(m.SyncDirection),
@@ -586,7 +589,7 @@ func (h *CollectionHandler) GetBookCollections(c *echo.Context) error {
response := make([]CollectionResponse, 0, len(collections))
for _, col := range collections {
response = append(response, CollectionResponse{
ID: uuid.UUID(col.ID.Bytes),
ID: col.ID.Bytes,
Name: col.Name,
Description: textToString(col.Description),
Color: textToString(col.Color),