From f0b5a4f9a8d9f531ad35165f1c79d94471998f4f Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sat, 2 May 2026 18:58:13 +0200 Subject: [PATCH] chore: go fixes --- api/playback/allanime_client.go | 7 ------- api/playback/handler.go | 5 ++--- api/playback/provider_extractor.go | 2 +- api/playback/service_resolution.go | 6 ++---- integrations/jikan/client.go | 5 +---- integrations/jikan/types.go | 10 +++++----- internal/worker/relations.go | 10 ++-------- templates/renderer.go | 15 ++++++--------- 8 files changed, 19 insertions(+), 41 deletions(-) diff --git a/api/playback/allanime_client.go b/api/playback/allanime_client.go index abba7a9..8eee274 100644 --- a/api/playback/allanime_client.go +++ b/api/playback/allanime_client.go @@ -304,13 +304,6 @@ func getMapKeys(m map[string]any) []string { return keys } -func min(a, b int) int { - if a < b { - return a - } - return b -} - func (c *allAnimeClient) extractSourceURLsFromData(ctx context.Context, data map[string]any) []StreamSource { episodeData, ok := data["episode"].(map[string]any) if !ok { diff --git a/api/playback/handler.go b/api/playback/handler.go index f2b96e4..908f340 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "maps" "net/http" "sort" "strconv" @@ -214,9 +215,7 @@ func (h *Handler) HandleProxy(w http.ResponseWriter, r *http.Request) { return } - for k, v := range headers { - w.Header()[k] = v - } + maps.Copy(w.Header(), headers) w.WriteHeader(statusCode) if bodyReader != nil { diff --git a/api/playback/provider_extractor.go b/api/playback/provider_extractor.go index f0221cf..79ac2da 100644 --- a/api/playback/provider_extractor.go +++ b/api/playback/provider_extractor.go @@ -31,7 +31,7 @@ func (e *providerExtractor) ExtractVideoLinks(ctx context.Context, providerPath var resp *http.Response var err error - for attempt := 0; attempt < 3; attempt++ { + for attempt := range 3 { if attempt > 0 { select { case <-ctx.Done(): diff --git a/api/playback/service_resolution.go b/api/playback/service_resolution.go index 77c77d5..bba1a59 100644 --- a/api/playback/service_resolution.go +++ b/api/playback/service_resolution.go @@ -48,12 +48,10 @@ func (s *Service) searchShowResultsByMode(ctx context.Context, query string, mod var wg sync.WaitGroup for _, mode := range modeCandidates { modeValue := mode - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { results, err := s.allAnimeClient.Search(ctx, query, modeValue) searchCh <- searchModeResult{Mode: modeValue, Results: results, Err: err} - }() + }) } wg.Wait() diff --git a/integrations/jikan/client.go b/integrations/jikan/client.go index dfd8c3f..bcfda02 100644 --- a/integrations/jikan/client.go +++ b/integrations/jikan/client.go @@ -316,10 +316,7 @@ func (c *Client) fetchWithRetry(ctx context.Context, urlStr string, out any) err if retryable && attempt < maxRetries-1 { resp.Body.Close() - delay := retryDelay(attempt) - if retryAfter > delay { - delay = retryAfter - } + delay := max(retryAfter, retryDelay(attempt)) if retryErr := waitForRetry(ctx, delay); retryErr != nil { return retryErr diff --git a/integrations/jikan/types.go b/integrations/jikan/types.go index 9249fc1..e205b10 100644 --- a/integrations/jikan/types.go +++ b/integrations/jikan/types.go @@ -100,16 +100,16 @@ func (a Anime) ShortDuration() string { return "" } // Duration format: "23 min per ep" or "1 hr 30 min" - var num string + var num strings.Builder for _, c := range a.Duration { if c >= '0' && c <= '9' { - num += string(c) - } else if c == ' ' && num != "" { + num.WriteString(string(c)) + } else if c == ' ' && num.String() != "" { break } } - if num != "" { - return num + "m" + if num.String() != "" { + return num.String() + "m" } return a.Duration } diff --git a/internal/worker/relations.go b/internal/worker/relations.go index df096d9..db44887 100644 --- a/internal/worker/relations.go +++ b/internal/worker/relations.go @@ -65,10 +65,7 @@ func retryBackoff(attempts int64) string { delay := time.Minute if attempts > 1 { - shift := attempts - 1 - if shift > 6 { - shift = 6 - } + shift := min(attempts-1, 6) delay = time.Minute * time.Duration(1<