refactor: use slices.Backward to simplify the code

Signed-off-by: chuanshanjida <chuanshanjida@outlook.com>
This commit is contained in:
chuanshanjida
2026-04-12 16:01:45 +08:00
parent 708f8d6b06
commit 0679fc13c5
3 changed files with 9 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import (
"math"
"net/http"
"regexp"
"slices"
"strconv"
"strings"
"unicode"
@@ -256,8 +257,8 @@ func (hrs *HTTPReadSeeker) reader() (_ io.Reader, retErr error) {
encoding := strings.FieldsFunc(resp.Header.Get("Content-Encoding"), func(r rune) bool {
return unicode.IsSpace(r) || r == ','
})
for i := len(encoding) - 1; i >= 0; i-- {
algorithm := strings.ToLower(encoding[i])
for _, v := range slices.Backward(encoding) {
algorithm := strings.ToLower(v)
switch algorithm {
case "zstd":
r, err := zstd.NewReader(body)