go: Modernize codebase with go fix
diff --git a/lib/go/test/tests/gotag_test.go b/lib/go/test/tests/gotag_test.go
index b7ad17b..f65362f 100644
--- a/lib/go/test/tests/gotag_test.go
+++ b/lib/go/test/tests/gotag_test.go
@@ -27,8 +27,7 @@
)
func TestDefaultTag(t *testing.T) {
- s := gotagtest.Tagged{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[gotagtest.Tagged]()
field, ok := st.FieldByName("StringThing")
if !ok || field.Tag.Get("json") != "string_thing" {
t.Error("Unexpected default tag value")
@@ -36,8 +35,7 @@
}
func TestCustomTag(t *testing.T) {
- s := gotagtest.Tagged{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[gotagtest.Tagged]()
field, ok := st.FieldByName("IntThing")
if !ok {
t.Error("Missing field IntThing")
@@ -53,8 +51,7 @@
}
func TestOptionalTag(t *testing.T) {
- s := gotagtest.Tagged{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[gotagtest.Tagged]()
field, ok := st.FieldByName("OptionalIntThing")
if !ok || field.Tag.Get("json") != "optional_int_thing,omitempty" {
t.Error("Unexpected default tag value for optional field")
@@ -62,8 +59,7 @@
}
func TestOptionalTagWithDefaultValue(t *testing.T) {
- s := gotagtest.Tagged{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[gotagtest.Tagged]()
field, ok := st.FieldByName("OptionalBoolThing")
if !ok || field.Tag.Get("json") != "optional_bool_thing" {
t.Error("Unexpected default tag value for optional field that has a default value")
diff --git a/lib/go/test/tests/ignoreinitialisms_test.go b/lib/go/test/tests/ignoreinitialisms_test.go
index c7012dd..5eacc2c 100644
--- a/lib/go/test/tests/ignoreinitialisms_test.go
+++ b/lib/go/test/tests/ignoreinitialisms_test.go
@@ -27,8 +27,7 @@
)
func TestIgnoreInitialismsFlagIsHonoured(t *testing.T) {
- s := ignoreinitialismstest.IgnoreInitialismsTest{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[ignoreinitialismstest.IgnoreInitialismsTest]()
_, ok := st.FieldByName("Id")
if !ok {
t.Error("Id attribute is missing!")
diff --git a/lib/go/test/tests/initialisms_test.go b/lib/go/test/tests/initialisms_test.go
index e6b4f63..fcf7a59 100644
--- a/lib/go/test/tests/initialisms_test.go
+++ b/lib/go/test/tests/initialisms_test.go
@@ -27,8 +27,7 @@
)
func TestThatCommonInitialismsAreFixed(t *testing.T) {
- s := initialismstest.InitialismsTest{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[initialismstest.InitialismsTest]()
_, ok := st.FieldByName("UserID")
if !ok {
t.Error("UserID attribute is missing!")
diff --git a/lib/go/test/tests/names_test.go b/lib/go/test/tests/names_test.go
index 5094bcb..ebf3559 100644
--- a/lib/go/test/tests/names_test.go
+++ b/lib/go/test/tests/names_test.go
@@ -27,8 +27,7 @@
)
func TestThatAttributeNameSubstituionDoesNotOccur(t *testing.T) {
- s := namestest.NamesTest{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[namestest.NamesTest]()
_, ok := st.FieldByName("Type")
if !ok {
t.Error("Type attribute is missing!")
diff --git a/lib/go/test/tests/processor_middleware_test.go b/lib/go/test/tests/processor_middleware_test.go
index aedd93f..c53aaeb 100644
--- a/lib/go/test/tests/processor_middleware_test.go
+++ b/lib/go/test/tests/processor_middleware_test.go
@@ -92,11 +92,9 @@
server.Stop()
})
var wg sync.WaitGroup
- wg.Add(1)
- go func() {
- defer wg.Done()
+ wg.Go(func() {
server.Serve()
- }()
+ })
time.Sleep(10 * time.Millisecond)
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index 29ccd53..0f0044a 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -150,7 +150,7 @@
}
mapout := make(map[int32]int32)
- for i := int32(0); i < 5; i++ {
+ for i := range int32(5) {
mapout[i] = i - 10
}
if r, err := client.TestMap(defaultCtx, mapout); !reflect.DeepEqual(r, mapout) || err != nil {
diff --git a/lib/go/test/tests/validate_test.go b/lib/go/test/tests/validate_test.go
index 52e059a..57c12f0 100644
--- a/lib/go/test/tests/validate_test.go
+++ b/lib/go/test/tests/validate_test.go
@@ -482,7 +482,7 @@
if err != nil {
t.Error(err)
}
- jsonMap := make(map[string]interface{})
+ jsonMap := make(map[string]any)
if err = json.Unmarshal(b, &jsonMap); err != nil {
t.Error(err)
}
diff --git a/lib/go/thrift/configuration.go b/lib/go/thrift/configuration.go
index a9565d3..9ae6418 100644
--- a/lib/go/thrift/configuration.go
+++ b/lib/go/thrift/configuration.go
@@ -306,7 +306,7 @@
//
// NOTE: nil cfg is not propagated. If you want to propagate a TConfiguration
// with everything being default value, use &TConfiguration{} explicitly instead.
-func PropagateTConfiguration(impl interface{}, cfg *TConfiguration) {
+func PropagateTConfiguration(impl any, cfg *TConfiguration) {
if cfg == nil || cfg.noPropagation {
return
}
diff --git a/lib/go/thrift/header_transport.go b/lib/go/thrift/header_transport.go
index 06f71b3..2eb5d15 100644
--- a/lib/go/thrift/header_transport.go
+++ b/lib/go/thrift/header_transport.go
@@ -28,6 +28,7 @@
"errors"
"fmt"
"io"
+ "slices"
)
// Size in bytes for 32-bit ints.
@@ -787,10 +788,8 @@
// addWriteTransformsDedupe adds id to writeTransforms only if it's not already
// there.
func (t *THeaderTransport) addWriteTransformsDedupe(id THeaderTransformID) {
- for _, existingID := range t.writeTransforms {
- if existingID == id {
- return
- }
+ if slices.Contains(t.writeTransforms, id) {
+ return
}
t.writeTransforms = append(t.writeTransforms, id)
}
diff --git a/lib/go/thrift/json_protocol_test.go b/lib/go/thrift/json_protocol_test.go
index 1680532..f5eea0b 100644
--- a/lib/go/thrift/json_protocol_test.go
+++ b/lib/go/thrift/json_protocol_test.go
@@ -479,7 +479,7 @@
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
- str1 := new([]interface{})
+ str1 := new([]any)
err := json.Unmarshal([]byte(str), str1)
if err != nil {
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
@@ -533,7 +533,7 @@
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
- str1 := new([]interface{})
+ str1 := new([]any)
err := json.Unmarshal([]byte(str), str1)
if err != nil {
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
diff --git a/lib/go/thrift/multiplexed_protocol.go b/lib/go/thrift/multiplexed_protocol.go
index cacbf6b..db549e3 100644
--- a/lib/go/thrift/multiplexed_protocol.go
+++ b/lib/go/thrift/multiplexed_protocol.go
@@ -22,6 +22,7 @@
import (
"context"
"fmt"
+ "maps"
"strings"
)
@@ -136,9 +137,7 @@
}
}
if t.DefaultProcessor != nil {
- for method, processorFunc := range t.DefaultProcessor.ProcessorMap() {
- processorFuncMap[method] = processorFunc
- }
+ maps.Copy(processorFuncMap, t.DefaultProcessor.ProcessorMap())
}
return processorFuncMap
}
@@ -220,7 +219,7 @@
return actualProcessor.Process(ctx, smb, out)
}
-//Protocol that use stored message for ReadMessageBegin
+// Protocol that use stored message for ReadMessageBegin
type storedMessageProtocol struct {
TProtocol
name string
diff --git a/lib/go/thrift/serializer_test.go b/lib/go/thrift/serializer_test.go
index 19879c5..feead61 100644
--- a/lib/go/thrift/serializer_test.go
+++ b/lib/go/thrift/serializer_test.go
@@ -247,9 +247,7 @@
s := NewTSerializerPool(NewTSerializer)
d := NewTDeserializerPool(NewTDeserializer)
f := func(i int64) bool {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ wg.Go(func() {
t.Run(
fmt.Sprintf("#%d-%d", counter.Add(1), i),
func(t *testing.T) {
@@ -273,7 +271,7 @@
}
},
)
- }()
+ })
return true
}
quick.Check(f, nil)
diff --git a/lib/go/thrift/simple_json_protocol_test.go b/lib/go/thrift/simple_json_protocol_test.go
index 002a231..1865098 100644
--- a/lib/go/thrift/simple_json_protocol_test.go
+++ b/lib/go/thrift/simple_json_protocol_test.go
@@ -547,7 +547,7 @@
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
- str1 := new([]interface{})
+ str1 := new([]any)
err := json.Unmarshal([]byte(str), str1)
if err != nil {
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
@@ -601,7 +601,7 @@
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
- str1 := new([]interface{})
+ str1 := new([]any)
err := json.Unmarshal([]byte(str), str1)
if err != nil {
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
diff --git a/lib/go/thrift/socket_aix_syscall.go b/lib/go/thrift/socket_aix_syscall.go
index 2253f75..643181b 100644
--- a/lib/go/thrift/socket_aix_syscall.go
+++ b/lib/go/thrift/socket_aix_syscall.go
@@ -1,5 +1,4 @@
//go:build aix
-// +build aix
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/lib/go/thrift/socket_non_aix_syscall.go b/lib/go/thrift/socket_non_aix_syscall.go
index 523f356..45e38a6 100644
--- a/lib/go/thrift/socket_non_aix_syscall.go
+++ b/lib/go/thrift/socket_non_aix_syscall.go
@@ -1,5 +1,4 @@
//go:build !aix && !windows && !wasm
-// +build !aix,!windows,!wasm
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/lib/go/thrift/socket_non_unix_conn.go b/lib/go/thrift/socket_non_unix_conn.go
index 75ed91d..644bd8c 100644
--- a/lib/go/thrift/socket_non_unix_conn.go
+++ b/lib/go/thrift/socket_non_unix_conn.go
@@ -1,5 +1,4 @@
//go:build windows || wasm
-// +build windows wasm
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/lib/go/thrift/socket_unix_conn.go b/lib/go/thrift/socket_unix_conn.go
index c06e0e1..c762125 100644
--- a/lib/go/thrift/socket_unix_conn.go
+++ b/lib/go/thrift/socket_unix_conn.go
@@ -1,5 +1,4 @@
//go:build !windows && !wasm
-// +build !windows,!wasm
/*
* Licensed to the Apache Software Foundation (ASF) under one