From 0a76dc83ddeb9f129b62c4c31de6ffec6ddb448b Mon Sep 17 00:00:00 2001 From: VnPower Date: Mon, 14 Aug 2023 19:41:26 +0700 Subject: [PATCH] Optimize: bump to Go 1.21 and clean some code --- go.mod | 2 +- handler/artwork.go | 2 +- handler/helpers.go | 8 -------- handler/misc.go | 2 +- handler/top.go | 2 +- handler/user.go | 2 +- 6 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 handler/helpers.go diff --git a/go.mod b/go.mod index 7aeea23..a031805 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module pixivfe -go 1.20 +go 1.21 require ( github.com/goccy/go-json v0.10.2 diff --git a/handler/artwork.go b/handler/artwork.go index e8cf3f1..194b8de 100644 --- a/handler/artwork.go +++ b/handler/artwork.go @@ -81,7 +81,7 @@ func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) { sort.Sort(sort.Reverse(sort.IntSlice(ids))) idsString := "" - count := Min(len(ids), 30) + count := min(len(ids), 30) for i := 0; i < count; i++ { idsString += fmt.Sprintf("&ids[]=%d", ids[i]) diff --git a/handler/helpers.go b/handler/helpers.go deleted file mode 100644 index f60d80f..0000000 --- a/handler/helpers.go +++ /dev/null @@ -1,8 +0,0 @@ -package handler - -func Min(x, y int) int { - if x < y { - return x - } - return y -} diff --git a/handler/misc.go b/handler/misc.go index 38a7215..e8bc424 100644 --- a/handler/misc.go +++ b/handler/misc.go @@ -98,7 +98,7 @@ func (p *PixivClient) GetDiscoveryArtwork(mode string, count int) ([]models.Illu var artworks []models.IllustShort for count > 0 { - itemsForRequest := Min(100, count) + itemsForRequest := min(100, count) count -= itemsForRequest diff --git a/handler/top.go b/handler/top.go index 2be594b..43a657b 100644 --- a/handler/top.go +++ b/handler/top.go @@ -85,7 +85,7 @@ func (p *PixivClient) GetLandingPage(mode string) (models.LandingArtworks, error for i := 0; i < len(pages.RecommendedByTags); i++ { temp := pages.RecommendedByTags[i] - temp.Artworks = artworks.Artworks[count : count+Min(len(temp.Ids), 18)] + temp.Artworks = artworks.Artworks[count : count+min(len(temp.Ids), 18)] context.RecommendByTags = append(context.RecommendByTags, temp.LandingRecommendByTags) count += len(temp.Ids) diff --git a/handler/user.go b/handler/user.go index 90e2fbb..e17a15f 100644 --- a/handler/user.go +++ b/handler/user.go @@ -67,7 +67,7 @@ func (p *PixivClient) GetUserArtworksID(id string, category string, page int) (s } start := (page - 1) * int(worksPerPage) - end := int(math.Min(float64(page)*worksPerPage, worksNumber)) // no overflow + end := int(min(float64(page)*worksPerPage, worksNumber)) // no overflow for _, k := range ids[start:end] { idsString += fmt.Sprintf("&ids[]=%d", k)