Merge pull request #1961 from versity/ben/modernize

chore: run go modernize tool
This commit is contained in:
Ben McClelland
2026-03-10 16:17:52 -07:00
committed by GitHub
29 changed files with 67 additions and 88 deletions
+2 -2
View File
@@ -327,8 +327,8 @@ func ParseCORSHeaders(headers string) ([]CORSHeader, error) {
return result, nil
}
headersSplitted := strings.Split(headers, ",")
for _, h := range headersSplitted {
headersSplitted := strings.SplitSeq(headers, ",")
for h := range headersSplitted {
corsHeader := CORSHeader(strings.TrimSpace(h))
if corsHeader == "" || !corsHeader.IsValid() {
debuglogger.Logf("invalid access control header: %s", h)
+2 -2
View File
@@ -416,7 +416,7 @@ func (ipa *IpaIAMService) newRequest(method string, args []string, dict map[stri
return "", fmt.Errorf("ipa request invalid: %w", err)
}
request := map[string]interface{}{
request := map[string]any{
"id": id,
"method": json.RawMessage(jmethod),
"params": []json.RawMessage{json.RawMessage(jargs), json.RawMessage(jdict)},
@@ -448,7 +448,7 @@ func pkcs7Unpad(b []byte, blocksize int) ([]byte, error) {
if n == 0 || n > len(b) {
return nil, errors.New("invalid padding on input")
}
for i := 0; i < n; i++ {
for i := range n {
if b[len(b)-n+i] != c {
return nil, errors.New("invalid padding on input")
}
+10 -10
View File
@@ -31,14 +31,14 @@ func getHost(r *http.Request) string {
//
// Copied from the Go 1.8 standard library (net/url)
func stripPort(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
before, _, ok := strings.Cut(hostport, ":")
if !ok {
return hostport
}
if i := strings.IndexByte(hostport, ']'); i != -1 {
return strings.TrimPrefix(hostport[:i], "[")
if before, _, ok := strings.Cut(hostport, "]"); ok {
return strings.TrimPrefix(before, "[")
}
return hostport[:colon]
return before
}
// Port returns the port part of u.Host, without the leading colon.
@@ -46,17 +46,17 @@ func stripPort(hostport string) string {
//
// Copied from the Go 1.8 standard library (net/url)
func portOnly(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
_, after, ok := strings.Cut(hostport, ":")
if !ok {
return ""
}
if i := strings.Index(hostport, "]:"); i != -1 {
return hostport[i+len("]:"):]
if _, after, ok := strings.Cut(hostport, "]:"); ok {
return after
}
if strings.Contains(hostport, "]") {
return ""
}
return hostport[colon+len(":"):]
return after
}
// Returns true if the specified URI is using the standard port
+1 -1
View File
@@ -122,7 +122,7 @@ func TestStripExcessHeaders(t *testing.T) {
"12 3 1abc123",
}
for i := 0; i < len(vals); i++ {
for i := range vals {
r := StripExcessSpaces(vals[i])
if e, a := expected[i], r; e != a {
t.Errorf("%d, expect %v, got %v", i, e, a)
+1 -1
View File
@@ -457,7 +457,7 @@ func (s *httpSigner) buildCanonicalHeaders(host string, rule v4Internal.Rule, he
var canonicalHeaders strings.Builder
n := len(headers)
const colon = ':'
for i := 0; i < n; i++ {
for i := range n {
if headers[i] == hostHeader {
canonicalHeaders.WriteString(hostHeader)
canonicalHeaders.WriteRune(colon)
+2 -2
View File
@@ -100,7 +100,7 @@ func TestPresignRequest(t *testing.T) {
t.Errorf("expect %v, got %v", e, a)
}
for _, h := range strings.Split(expectedHeaders, ";") {
for h := range strings.SplitSeq(expectedHeaders, ";") {
v := headers.Get(h)
if len(v) == 0 {
t.Errorf("expect %v, to be present in header map", h)
@@ -153,7 +153,7 @@ func TestPresignBodyWithArrayRequest(t *testing.T) {
t.Errorf("expect %v, got %v", e, a)
}
for _, h := range strings.Split(expectedHeaders, ";") {
for h := range strings.SplitSeq(expectedHeaders, ";") {
v := headers.Get(h)
if len(v) == 0 {
t.Errorf("expect %v, to be present in header map", h)
-1
View File
@@ -13,7 +13,6 @@
// under the License.
//go:build !linux
// +build !linux
package posix
+2 -6
View File
@@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"io/fs"
"slices"
"strings"
"syscall"
@@ -300,12 +301,7 @@ func Walk(ctx context.Context, fileSystem fs.FS, prefix, delimiter, marker strin
}
func contains(a string, strs []string) bool {
for _, s := range strs {
if s == a {
return true
}
}
return false
return slices.Contains(strs, a)
}
type WalkVersioningResults struct {
+2 -4
View File
@@ -374,14 +374,12 @@ func TestWalkStop(t *testing.T) {
var err error
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
_, err = backend.Walk(ctx, s, "", "/", "", 1000,
func(path string, d fs.DirEntry) (s3response.Object, error) {
return s3response.Object{}, nil
}, []string{})
}()
})
select {
case <-time.After(1 * time.Second):
+4 -4
View File
@@ -583,11 +583,11 @@ func parseCreateBucketPayload(input string) ([]byte, error) {
}
for _, part := range inputParts {
part = strings.TrimSpace(part)
if strings.HasPrefix(part, "LocationConstraint=") {
locConstraint := strings.TrimPrefix(part, "LocationConstraint=")
if after, ok := strings.CutPrefix(part, "LocationConstraint="); ok {
locConstraint := after
config.LocationConstraint = &locConstraint
} else if strings.HasPrefix(part, "Tags=") {
tags, err := parseTagging(strings.TrimPrefix(part, "Tags="))
} else if after, ok := strings.CutPrefix(part, "Tags="); ok {
tags, err := parseTagging(after)
if err != nil {
return nil, err
}
+2 -4
View File
@@ -68,8 +68,7 @@ func initPosix(ctx context.Context) {
log.Fatalf("init posix: %v", err)
}
wg.Add(1)
go func() {
wg.Go(func() {
err = runGateway(ctx, be)
if err != nil && err != context.Canceled {
log.Fatalf("run gateway: %v", err)
@@ -79,8 +78,7 @@ func initPosix(ctx context.Context) {
if err != nil {
log.Fatalf("remove temp directory: %v", err)
}
wg.Done()
}()
})
// wait for server to start
time.Sleep(1 * time.Second)
+4 -4
View File
@@ -88,9 +88,9 @@ func NewManager(ctx context.Context, conf Config) (Manager, error) {
// setup statsd endpoints
if len(conf.StatsdServers) > 0 {
statsdServers := strings.Split(conf.StatsdServers, ",")
statsdServers := strings.SplitSeq(conf.StatsdServers, ",")
for _, server := range statsdServers {
for server := range statsdServers {
statsd, err := newStatsd(server, conf.ServiceName)
if err != nil {
return nil, err
@@ -101,9 +101,9 @@ func NewManager(ctx context.Context, conf Config) (Manager, error) {
// setup dogstatsd endpoints
if len(conf.DogStatsdServers) > 0 {
dogStatsdServers := strings.Split(conf.DogStatsdServers, ",")
dogStatsdServers := strings.SplitSeq(conf.DogStatsdServers, ",")
for _, server := range dogStatsdServers {
for server := range dogStatsdServers {
dogStatsd, err := newDogStatsd(server, conf.ServiceName)
if err != nil {
return nil, err
+1 -1
View File
@@ -349,7 +349,7 @@ func ensureExposeMetaHeaders(ctx *fiber.Ctx) {
lowerExisting := map[string]struct{}{}
if existing != "" {
for _, part := range strings.Split(existing, ",") {
for part := range strings.SplitSeq(existing, ",") {
p := strings.ToLower(strings.TrimSpace(part))
if p != "" {
lowerExisting[p] = struct{}{}
+1 -1
View File
@@ -29,7 +29,7 @@ func ensureExposeETag(ctx *fiber.Ctx) {
}
lowerExisting := map[string]struct{}{}
for _, part := range strings.Split(existing, ",") {
for part := range strings.SplitSeq(existing, ",") {
p := strings.ToLower(strings.TrimSpace(part))
if p != "" {
lowerExisting[p] = struct{}{}
+6 -6
View File
@@ -401,8 +401,8 @@ func ParseObjectAttributes(ctx *fiber.Ctx) (map[s3response.ObjectAttributes]stru
if len(value) == 0 {
break
}
oattrs := strings.Split(string(value), ",")
for _, a := range oattrs {
oattrs := strings.SplitSeq(string(value), ",")
for a := range oattrs {
attr := s3response.ObjectAttributes(a)
if !attr.IsValid() {
debuglogger.Logf("invalid object attribute: %v\n", attr)
@@ -500,16 +500,16 @@ type ChecksumValues map[types.ChecksumAlgorithm]string
// e.g.
// "x-amz-checksum-crc64nvme, x-amz-checksum-sha1"
func (cv ChecksumValues) Headers() string {
result := ""
var result strings.Builder
isFirst := false
for key := range cv {
if !isFirst {
result += ", "
result.WriteString(", ")
}
result += fmt.Sprintf("x-amz-checksum-%v", strings.ToLower(string(key)))
result.WriteString(fmt.Sprintf("x-amz-checksum-%v", strings.ToLower(string(key))))
}
return result
return result.String()
}
// ParseCalculatedChecksumHeaders parses and validates x-amz-checksum-x header keys
+1 -1
View File
@@ -992,7 +992,7 @@ func TestParseTagging(t *testing.T) {
},
}
for i := 0; i < lgth; i++ {
for range lgth {
res.TagSet.Tags = append(res.TagSet.Tags, s3response.Tag{
Key: genRandStr(10),
Value: genRandStr(20),
+1 -1
View File
@@ -940,7 +940,7 @@ func GetAPIErrorResponse(err APIError, resource, requestID, hostID string) []byt
}
// Encodes the response headers into XML format.
func encodeResponse(response interface{}) []byte {
func encodeResponse(response any) []byte {
var bytesBuffer bytes.Buffer
bytesBuffer.WriteString(xml.Header)
e := xml.NewEncoder(&bytesBuffer)
-1
View File
@@ -13,7 +13,6 @@
// under the License.
//go:build amd64 || arm64 || ppc64le || riscv64
// +build amd64 arm64 ppc64le riscv64
package s3select
+2 -2
View File
@@ -344,8 +344,8 @@ func headerCompare(expectedHeaders map[string]string, actualHeaders map[string][
}
// regex match
if strings.HasPrefix(want, "re:") {
pat := strings.TrimPrefix(want, "re:")
if after, ok := strings.CutPrefix(want, "re:"); ok {
pat := after
re, err := regexp.Compile(pat)
if err != nil {
return fmt.Errorf("bad regex for header %q: %w", k, err)
+3 -4
View File
@@ -23,6 +23,7 @@ import (
"fmt"
"io"
"net/http"
"slices"
"strings"
"sync"
@@ -1898,10 +1899,8 @@ func CompleteMultipartUpload_racey_success(s *S3Conf) error {
mu.RLock()
defer mu.RUnlock()
for _, s := range sums {
if csum == s {
return nil
}
if slices.Contains(sums, csum) {
return nil
}
return fmt.Errorf("expected the object checksum to be one of %v, instead got %v",
sums, csum)
+4 -6
View File
@@ -45,7 +45,7 @@ func TestUpload(s *S3Conf, files int, objSize int64, bucket, prefix string) erro
runF("performance test: upload objects")
for i := 0; i < files; i++ {
for i := range files {
sg.Add(1)
go func(i int) {
var r io.Reader = NewDataReader(int(objSize), int(s.PartSize))
@@ -87,7 +87,7 @@ func TestDownload(s *S3Conf, files int, objSize int64, bucket, prefix string) er
runF("performance test: download objects")
for i := 0; i < files; i++ {
for i := range files {
sg.Add(1)
go func(i int) {
nw := NewNullWriter()
@@ -131,16 +131,14 @@ func TestReqPerSec(s *S3Conf, totalReqs int, bucket string) error {
runF("performance test: measuring request per second")
for i := 0; i < s.Concurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for i := 0; i < totalReqs/s.Concurrency; i++ {
_, err := client.HeadBucket(context.Background(), &s3.HeadBucketInput{Bucket: &bucket})
if err != nil && resErr != nil {
resErr = err
}
}
}()
})
}
wg.Wait()
+2 -4
View File
@@ -87,13 +87,11 @@ func (ct *TestState) process() {
if err := ct.sem.Acquire(ct.ctx, 1); err != nil {
continue
}
ct.wg.Add(1)
go func() {
ct.wg.Go(func() {
// Run test and release semaphore once done
fn(ct.conf)
ct.sem.Release(1)
ct.wg.Done()
}()
})
}
}
}
+3 -3
View File
@@ -32,17 +32,17 @@ var (
FailCount atomic.Uint32
)
func runF(format string, a ...interface{}) {
func runF(format string, a ...any) {
RunCount.Add(1)
fmt.Printf(colorCyan+"RUN "+colorReset+format+"\n", a...)
}
func failF(format string, a ...interface{}) {
func failF(format string, a ...any) {
FailCount.Add(1)
fmt.Printf(colorRed+"FAIL "+colorReset+format+"\n", a...)
}
func passF(format string, a ...interface{}) {
func passF(format string, a ...any) {
PassCount.Add(1)
fmt.Printf(colorGreen+"PASS "+colorReset+format+"\n", a...)
}
+3 -4
View File
@@ -1886,7 +1886,6 @@ func cleanupLockedObjects(client *s3.Client, bucket string, objs []objToDelete)
sem := semaphore.NewWeighted(maxDelObjWorkers)
for _, obj := range objs {
obj := obj // capture loop variable
// Acquire worker slot before processing an object
if err := sem.Acquire(ctx, 1); err != nil {
@@ -2417,12 +2416,12 @@ func extractSignature(req *http.Request) ([]byte, error) {
authHdr := req.Header.Get("Authorization")
i := strings.Index(authHdr, key)
if i == -1 {
_, after, ok := strings.Cut(authHdr, key)
if !ok {
return nil, errors.New("signature not found")
}
sig := authHdr[i+len(key):]
sig := after
return hex.DecodeString(sig)
}
+1 -6
View File
@@ -22,12 +22,7 @@ func (c *PayloadChunked) getChunkedPayloadContentLength(additionalChunkHeaderSiz
var sizeIdx int64
var contentLength int64
for sizeIdx = 0; sizeIdx < payloadSize; sizeIdx += c.chunkSize {
var endIdx int64
if sizeIdx+c.chunkSize < payloadSize {
endIdx = sizeIdx + c.chunkSize
} else {
endIdx = payloadSize
}
endIdx := min(sizeIdx+c.chunkSize, payloadSize)
hexSize := fmt.Sprintf("%x", endIdx-sizeIdx)
contentLength += int64(len(hexSize)) + additionalChunkHeaderSize + (endIdx - sizeIdx) + 2
}
@@ -56,8 +56,8 @@ func NewPutBucketCORSCommand(command *S3Command, ruleStrings []string) (*S3Comma
func assembleCORSRule(ruleString string) (*CORSRule, error) {
corsRule := &CORSRule{}
ruleComponents := strings.Split(ruleString, ";")
for _, component := range ruleComponents {
ruleComponents := strings.SplitSeq(ruleString, ";")
for component := range ruleComponents {
componentSegments := strings.Split(component, "=")
switch componentSegments[0] {
case AllowedMethods:
+2 -2
View File
@@ -77,8 +77,8 @@ func (r *restParams) String() string {
func (r *restParams) Set(value string) error {
*r = make(map[string]string)
pairs := strings.Split(value, *paramSeparator)
for _, pair := range pairs {
pairs := strings.SplitSeq(value, *paramSeparator)
for pair := range pairs {
kv := strings.SplitN(pair, ":", 2)
if len(kv) != 2 {
return fmt.Errorf("invalid key-value pair: %s", pair)
+2 -2
View File
@@ -8,7 +8,7 @@ import (
var Debug *bool
var LogFile *string
func PrintDebug(format string, args ...interface{}) {
func PrintDebug(format string, args ...any) {
if *Debug {
if *LogFile != "" {
logFile, err := os.OpenFile(*LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
@@ -22,7 +22,7 @@ func PrintDebug(format string, args ...interface{}) {
}
}
func LogFatal(format string, args ...interface{}) {
func LogFatal(format string, args ...any) {
PrintDebug(format, args...)
os.Exit(1)
}
+1 -1
View File
@@ -138,7 +138,7 @@ func (s *Server) handleIndexHTML(c *fiber.Ctx) error {
adminGateways = s.config.Gateways
}
configJSON, err := json.Marshal(map[string]interface{}{
configJSON, err := json.Marshal(map[string]any{
"gateways": s.config.Gateways,
"adminGateways": adminGateways,
"defaultRegion": s.config.Region,