refactor(handlers): replace temporary variable pointer pattern with new() builtin
Simplify pointer creation across kobo, koreader, and queue handlers by replacing the two-step pattern (assign to local, then take address) with inline new() calls. This reduces verbosity without changing behavior: Before: remaining := int(a - b) pagesRemaining = &remaining After: pagesRemaining = new(int(a - b)) Covers page calculations, chapter/progress fields, UUID formatting, and timestamp string conversions.
This commit is contained in:
@@ -601,24 +601,19 @@ func (h *KOReaderHandler) GetMetadata(c *echo.Context) error {
|
||||
progressData.Epubcfi = &progress.Epubcfi.String
|
||||
}
|
||||
if progress.Chapter.Valid {
|
||||
ch := int(progress.Chapter.Int32)
|
||||
progressData.Chapter = &ch
|
||||
progressData.Chapter = new(int(progress.Chapter.Int32))
|
||||
}
|
||||
if progress.ChapterProgress.Valid {
|
||||
cp := progress.ChapterProgress.Float64
|
||||
progressData.ChapterProgress = &cp
|
||||
progressData.ChapterProgress = new(progress.ChapterProgress.Float64)
|
||||
}
|
||||
if progress.CharacterOffset.Valid {
|
||||
co := int64(progress.CharacterOffset.Int64)
|
||||
progressData.Character = &co
|
||||
progressData.Character = new(int64(progress.CharacterOffset.Int64))
|
||||
}
|
||||
if progress.CurrentPage.Valid {
|
||||
cp := int(progress.CurrentPage.Int32)
|
||||
progressData.Page = &cp
|
||||
progressData.Page = new(int(progress.CurrentPage.Int32))
|
||||
}
|
||||
if progress.TotalPages.Valid {
|
||||
tp := int(progress.TotalPages.Int32)
|
||||
progressData.TotalPages = &tp
|
||||
progressData.TotalPages = new(int(progress.TotalPages.Int32))
|
||||
}
|
||||
|
||||
annotations, err := h.db.GetAnnotationsForBook(c.Request().Context(), database.GetAnnotationsForBookParams{
|
||||
@@ -698,8 +693,7 @@ func (h *KOReaderHandler) GetLibrary(c *echo.Context) error {
|
||||
if err == nil {
|
||||
percentRead = progress.Percentage.Float64
|
||||
if progress.TotalPages.Valid && progress.CurrentPage.Valid {
|
||||
remaining := int(progress.TotalPages.Int32 - progress.CurrentPage.Int32)
|
||||
pagesRemaining = &remaining
|
||||
pagesRemaining = new(int(progress.TotalPages.Int32 - progress.CurrentPage.Int32))
|
||||
}
|
||||
if progress.LastReadAt.Valid {
|
||||
lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
|
||||
|
||||
Reference in New Issue
Block a user