diff --git a/.github/workflows/sca.yml b/.github/workflows/sca.yml index 5c04b80f8c4..33d7e1624e0 100644 --- a/.github/workflows/sca.yml +++ b/.github/workflows/sca.yml @@ -185,6 +185,30 @@ jobs: -i lib/c_glib/test/gen-cpp \ --error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib + lib-go: + needs: compiler + runs-on: ubuntu-24.04 + strategy: + matrix: + go: + - '1.26' + fail-fast: false + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 + with: + go-version: ${{ matrix.go }} + + - name: Run gofmt + # Args: + # -s: Simplify code + # -d: Display changes, and exit non-zero when changes present + # -e: Report all errors instead of only the first 10 + run: gofmt -s -d -e $(git ls-files | grep "\.go$") + lib-python: needs: compiler runs-on: ubuntu-24.04 diff --git a/lib/go/test/fuzz/fuzz.go b/lib/go/test/fuzz/fuzz.go index bad6b41349b..7382836b103 100644 --- a/lib/go/test/fuzz/fuzz.go +++ b/lib/go/test/fuzz/fuzz.go @@ -27,9 +27,9 @@ import ( "fmt" "strconv" + "github.com/apache/thrift/lib/go/test/fuzz/gen-go/fuzztest" "github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared" "github.com/apache/thrift/lib/go/test/fuzz/gen-go/tutorial" - "github.com/apache/thrift/lib/go/test/fuzz/gen-go/fuzztest" "github.com/apache/thrift/lib/go/thrift" ) diff --git a/lib/go/test/fuzz/fuzz_test.go b/lib/go/test/fuzz/fuzz_test.go index 73eb0727156..8a656e79e50 100644 --- a/lib/go/test/fuzz/fuzz_test.go +++ b/lib/go/test/fuzz/fuzz_test.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz /* diff --git a/lib/go/test/tests/optional_fields_test.go b/lib/go/test/tests/optional_fields_test.go index 39fb1b5628f..0d8e7396b39 100644 --- a/lib/go/test/tests/optional_fields_test.go +++ b/lib/go/test/tests/optional_fields_test.go @@ -182,7 +182,7 @@ func TestListNotEmpty(t *testing.T) { } } -//Make sure that optional fields are not being serialized +// Make sure that optional fields are not being serialized func TestNoOptionalUnsetFieldsOnWire(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() @@ -210,7 +210,7 @@ func TestNoSetToDefaultFieldsOnWire(t *testing.T) { ao.Write(context.Background(), proto) } -//Make sure that only one field is being serialized when set to non-default +// Make sure that only one field is being serialized when set to non-default func TestOneISetFieldOnWire(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() diff --git a/lib/go/thrift/compact_protocol.go b/lib/go/thrift/compact_protocol.go index df01e337a46..b50c80e8f9c 100644 --- a/lib/go/thrift/compact_protocol.go +++ b/lib/go/thrift/compact_protocol.go @@ -775,7 +775,7 @@ const maxVarint64Bytes = 10 func (p *TCompactProtocol) readVarint64() (int64, error) { shift := uint(0) result := int64(0) - for rsize := 0; rsize < maxVarint64Bytes; rsize++ { + for range maxVarint64Bytes { b, err := p.readByteDirect() if err != nil { return 0, err diff --git a/lib/go/thrift/framed_transport.go b/lib/go/thrift/framed_transport.go index 276619221d8..f689ee76f5d 100644 --- a/lib/go/thrift/framed_transport.go +++ b/lib/go/thrift/framed_transport.go @@ -61,10 +61,7 @@ func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory { // Deprecated: Use NewTFramedTransportFactoryConf instead. func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory { - safeMax := maxLength - if safeMax > math.MaxInt32 { - safeMax = math.MaxInt32 - } + safeMax := min(maxLength, math.MaxInt32) return NewTFramedTransportFactoryConf(factory, &TConfiguration{ MaxFrameSize: int32(safeMax), diff --git a/lib/go/thrift/middleware.go b/lib/go/thrift/middleware.go index 85c7e06948d..af4a65affbd 100644 --- a/lib/go/thrift/middleware.go +++ b/lib/go/thrift/middleware.go @@ -35,10 +35,7 @@ type ProcessorMiddleware func(name string, next TProcessorFunction) TProcessorFu // // Middlewares will be called in the order that they are defined: // -// 1. Middlewares[0] -// 2. Middlewares[1] -// ... -// N. Middlewares[n] +// Middlewares[0] -> Middlewares[1] -> ... -> Middlewares[n] func WrapProcessor(processor TProcessor, middlewares ...ProcessorMiddleware) TProcessor { for name, processorFunc := range processor.ProcessorMap() { wrapped := processorFunc @@ -98,10 +95,7 @@ var ( // // Middlewares will be called in the order that they are defined: // -// 1. Middlewares[0] -// 2. Middlewares[1] -// ... -// N. Middlewares[n] +// Middlewares[0] -> Middlewares[1] -> ... -> Middlewares[n] func WrapClient(client TClient, middlewares ...ClientMiddleware) TClient { // Add middlewares in reverse so the first in the list is the outermost. for i := len(middlewares) - 1; i >= 0; i-- { @@ -117,12 +111,12 @@ func WrapClient(client TClient, middlewares ...ClientMiddleware) TClient { // By default if a client call gets an exception defined in the thrift IDL, for // example: // -// service MyService { -// FooResponse foo(1: FooRequest request) throws ( -// 1: Exception1 error1, -// 2: Exception2 error2, -// ) -// } +// service MyService { +// FooResponse foo(1: FooRequest request) throws ( +// 1: Exception1 error1, +// 2: Exception2 error2, +// ) +// } // // Exception1 or Exception2 will not be in the err return of TClient.Call, // but in the result TStruct instead, and there's no easy access to them. diff --git a/lib/go/thrift/server_socket.go b/lib/go/thrift/server_socket.go index 798b7a50070..4ad64637389 100644 --- a/lib/go/thrift/server_socket.go +++ b/lib/go/thrift/server_socket.go @@ -17,7 +17,6 @@ * under the License. */ - package thrift import ( @@ -28,9 +27,9 @@ import ( type TServerSocket struct { // TServerSocketListenerFactory abstracts how listeners are created. - listenerFactory func(net.Addr) (net.Listener, error) - addr net.Addr - clientTimeout time.Duration + listenerFactory func(net.Addr) (net.Listener, error) + addr net.Addr + clientTimeout time.Duration // Protects the listener and interrupted fields to make them thread safe. mu sync.RWMutex @@ -66,9 +65,9 @@ func NewTServerSocketFromAddrTimeout(addr net.Addr, clientTimeout time.Duration) // Allows full customization (TLS, mocks, unix sockets, windows named pipes, etc.) func NewTServerSocketFromFactoryTimeout(listenerFactory func(addr net.Addr) (listener net.Listener, err error), addr net.Addr, clientTimeout time.Duration) *TServerSocket { return &TServerSocket{ - listenerFactory: listenerFactory, - addr: addr, - clientTimeout: clientTimeout, + listenerFactory: listenerFactory, + addr: addr, + clientTimeout: clientTimeout, } } @@ -77,7 +76,7 @@ func (p *TServerSocket) try_listen(raise bool) error { defer p.mu.Unlock() if p.listener != nil { - if (raise) { + if raise { return NewTTransportException(ALREADY_OPEN, "Server socket already open") } return nil @@ -145,7 +144,7 @@ func (p *TServerSocket) Addr() net.Addr { func (p *TServerSocket) try_close(interrupt bool) error { p.mu.Lock() defer p.mu.Unlock() - if (interrupt){ + if interrupt { p.interrupted = true } diff --git a/lib/go/thrift/socket.go b/lib/go/thrift/socket.go index 2185fb18ca0..c91e11cfe28 100644 --- a/lib/go/thrift/socket.go +++ b/lib/go/thrift/socket.go @@ -55,10 +55,10 @@ func NewTSocket(hostPort string) (*TSocket, error) { // // Example: // -// trans := thrift.NewTSocketConf("localhost:9090", &TConfiguration{ -// ConnectTimeout: time.Second, // Use 0 for no timeout -// SocketTimeout: time.Second, // Use 0 for no timeout -// }) +// trans := thrift.NewTSocketConf("localhost:9090", &TConfiguration{ +// ConnectTimeout: time.Second, // Use 0 for no timeout +// SocketTimeout: time.Second, // Use 0 for no timeout +// }) func NewTSocketConf(hostPort string, conf *TConfiguration) *TSocket { return NewTSocketFromAddrConf(tcpAddr(hostPort), conf) } @@ -197,7 +197,7 @@ func (p *TSocket) Close() error { return p.conn.Close() } -//Returns the remote address of the socket. +// Returns the remote address of the socket. func (p *TSocket) Addr() net.Addr { return p.addr } diff --git a/lib/go/thrift/socket_unix_conn_test.go b/lib/go/thrift/socket_unix_conn_test.go index 1d4c806cf08..612d21325e9 100644 --- a/lib/go/thrift/socket_unix_conn_test.go +++ b/lib/go/thrift/socket_unix_conn_test.go @@ -1,4 +1,4 @@ -// +build !windows +//go:build !windows /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/lib/go/thrift/ssl_socket.go b/lib/go/thrift/ssl_socket.go index d7ba415ec87..b72609f121e 100644 --- a/lib/go/thrift/ssl_socket.go +++ b/lib/go/thrift/ssl_socket.go @@ -42,14 +42,14 @@ type TSSLSocket struct { // // Example: // -// trans := thrift.NewTSSLSocketConf("localhost:9090", &TConfiguration{ -// ConnectTimeout: time.Second, // Use 0 for no timeout -// SocketTimeout: time.Second, // Use 0 for no timeout +// trans := thrift.NewTSSLSocketConf("localhost:9090", &TConfiguration{ +// ConnectTimeout: time.Second, // Use 0 for no timeout +// SocketTimeout: time.Second, // Use 0 for no timeout // -// TLSConfig: &tls.Config{ -// // Fill in tls config here. -// } -// }) +// TLSConfig: &tls.Config{ +// // Fill in tls config here. +// } +// }) func NewTSSLSocketConf(hostPort string, conf *TConfiguration) *TSSLSocket { if cfg := conf.GetTLSConfig(); cfg != nil && cfg.MinVersion == 0 { cfg.MinVersion = tls.VersionTLS10