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:
@@ -262,7 +262,7 @@ func (h *AuthHandler) Register(c *echo.Context) error {
|
||||
}
|
||||
c.SetCookie(cookie)
|
||||
|
||||
_, refreshToken, err := h.CreateRefreshToken(uuid.UUID(user.ID.Bytes))
|
||||
_, refreshToken, err := h.CreateRefreshToken(user.ID.Bytes)
|
||||
if err != nil {
|
||||
if c.Request().Header.Get("HX-Request") == "true" {
|
||||
return c.HTML(http.StatusInternalServerError, `<div class="text-red-500">Failed to generate refresh token</div>`)
|
||||
@@ -408,7 +408,7 @@ func (h *AuthHandler) Login(c *echo.Context) error {
|
||||
}
|
||||
c.SetCookie(cookie)
|
||||
|
||||
_, refreshToken, err := h.CreateRefreshToken(uuid.UUID(user.ID.Bytes))
|
||||
_, refreshToken, err := h.CreateRefreshToken(user.ID.Bytes)
|
||||
if err != nil {
|
||||
if c.Request().Header.Get("HX-Request") == "true" {
|
||||
return c.HTML(http.StatusInternalServerError, `<div class="text-red-500">Failed to generate refresh token</div>`)
|
||||
@@ -496,7 +496,7 @@ func (h *AuthHandler) UpdateProfile(c *echo.Context) error {
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"})
|
||||
}
|
||||
targetUserUUID = pgtype.UUID{Bytes: [16]byte(parsedUUID), Valid: true}
|
||||
targetUserUUID = pgtype.UUID{Bytes: parsedUUID, Valid: true}
|
||||
} else {
|
||||
// Self-edit mode
|
||||
targetUserUUID = currentUser.ID
|
||||
@@ -760,7 +760,7 @@ func (h *AuthHandler) UpdatePassword(c *echo.Context) error {
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"})
|
||||
}
|
||||
targetUserUUID = pgtype.UUID{Bytes: [16]byte(parsedUUID), Valid: true}
|
||||
targetUserUUID = pgtype.UUID{Bytes: parsedUUID, Valid: true}
|
||||
} else {
|
||||
// Self-change mode
|
||||
targetUserUUID = currentUser.ID
|
||||
@@ -840,7 +840,7 @@ func (h *AuthHandler) DeleteUser(c *echo.Context) error {
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"})
|
||||
}
|
||||
targetUserUUID = pgtype.UUID{Bytes: [16]byte(parsedUUID), Valid: true}
|
||||
targetUserUUID = pgtype.UUID{Bytes: parsedUUID, Valid: true}
|
||||
} else {
|
||||
// Self-deletion mode
|
||||
targetUserUUID = currentUser.ID
|
||||
|
||||
Reference in New Issue
Block a user