Revert "migration: go 1.21"

This reverts commit 33d41338ef.
This commit is contained in:
wwqgtxx
2023-09-21 08:25:26 +08:00
parent 0d7a57fa9d
commit 62266010ac
11 changed files with 63 additions and 20 deletions

View File

@ -3,6 +3,8 @@ package updater
import (
"fmt"
"io"
"golang.org/x/exp/constraints"
)
// LimitReachedError records the limit and the operation that caused it.
@ -33,7 +35,7 @@ func (lr *limitedReader) Read(p []byte) (n int, err error) {
}
}
p = p[:min(lr.n, int64(len(p)))]
p = p[:Min(lr.n, int64(len(p)))]
n, err = lr.r.Read(p)
lr.n -= int64(n)
@ -54,3 +56,12 @@ func LimitReader(r io.Reader, n int64) (limited io.Reader, err error) {
n: n,
}, nil
}
// Min returns the smaller of x or y.
func Min[T constraints.Integer | ~string](x, y T) (res T) {
if x < y {
return x
}
return y
}