misc: Upgrade Go to v1.21

Upgrade to 1.21 as 1.20 is now unmaintained.

Most changes are related to the new `slices` package from standard
library, which can replace some existing custom functions.
This commit is contained in:
Michael Manganiello
2024-03-05 09:49:10 -03:00
parent ea1b2f3284
commit 801967a530
19 changed files with 47 additions and 104 deletions
+5 -17
View File
@@ -1,6 +1,8 @@
package util
import (
"slices"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
)
@@ -69,15 +71,15 @@ func SelectTrackRange(tracks []*TrackListModel, idx int) {
tracks[idx].Selected = true
return
}
from := minInt(idx, lastSelected)
to := maxInt(idx, lastSelected)
from := min(idx, lastSelected)
to := max(idx, lastSelected)
for i := from; i <= to; i++ {
tracks[i].Selected = true
}
}
func FindTrackByID(tracks []*TrackListModel, id string) (*mediaprovider.Track, int) {
idx := sharedutil.Find(tracks, func(tr *TrackListModel) bool {
idx := slices.IndexFunc(tracks, func(tr *TrackListModel) bool {
return tr.Track.ID == id
})
if idx >= 0 {
@@ -85,17 +87,3 @@ func FindTrackByID(tracks []*TrackListModel, id string) (*mediaprovider.Track, i
}
return nil, -1
}
func minInt(a, b int) int {
if a < b {
return a
}
return b
}
func maxInt(a, b int) int {
if a > b {
return a
}
return b
}