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:
@@ -362,7 +362,7 @@ func (h *ReaderHandler) UpdateReadingSpeed(c *echo.Context) error {
|
||||
// Update reading speed using service
|
||||
err = h.readerService.CalculateReadingSpeed(
|
||||
c.Request().Context(),
|
||||
uuid.UUID(user.ID.Bytes),
|
||||
user.ID.Bytes,
|
||||
parsedUUID,
|
||||
req.PagesRead,
|
||||
req.TimeSpentMinutes,
|
||||
@@ -477,7 +477,7 @@ func (h *ReaderHandler) GetSettings(c *echo.Context) error {
|
||||
user := c.Get("user").(database.Users)
|
||||
|
||||
// Use reader service to get settings
|
||||
settings, err := h.readerService.GetSettings(c.Request().Context(), uuid.UUID(user.ID.Bytes))
|
||||
settings, err := h.readerService.GetSettings(c.Request().Context(), user.ID.Bytes)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to fetch settings"})
|
||||
}
|
||||
@@ -510,13 +510,13 @@ func (h *ReaderHandler) UpdateSettings(c *echo.Context) error {
|
||||
}
|
||||
|
||||
// Use reader service to update settings
|
||||
err := h.readerService.UpdateSettings(c.Request().Context(), uuid.UUID(user.ID.Bytes), settings)
|
||||
err := h.readerService.UpdateSettings(c.Request().Context(), user.ID.Bytes, settings)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to update settings"})
|
||||
}
|
||||
|
||||
// Return updated settings
|
||||
updatedSettings, _ := h.readerService.GetSettings(c.Request().Context(), uuid.UUID(user.ID.Bytes))
|
||||
updatedSettings, _ := h.readerService.GetSettings(c.Request().Context(), user.ID.Bytes)
|
||||
return c.JSON(http.StatusOK, updatedSettings)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user