Skip to content

Commit 6617008

Browse files
committed
THRIFT-5969: Enforce gofmt -s in CI
Also fix all `gofmt -s` issues.
1 parent 1668e19 commit 6617008

11 files changed

Lines changed: 59 additions & 44 deletions

File tree

.github/workflows/sca.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ jobs:
185185
-i lib/c_glib/test/gen-cpp \
186186
--error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib
187187
188+
lib-go:
189+
needs: compiler
190+
runs-on: ubuntu-24.04
191+
strategy:
192+
matrix:
193+
go:
194+
- '1.26'
195+
fail-fast: false
196+
steps:
197+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
198+
with:
199+
persist-credentials: false
200+
201+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
202+
with:
203+
go-version: ${{ matrix.go }}
204+
205+
- name: Run gofmt
206+
# Args:
207+
# -s: Simplify code
208+
# -d: Display changes, and exit non-zero when changes present
209+
# -e: Report all errors instead of only the first 10
210+
run: gofmt -s -d -e $(git ls-files | grep "\.go$")
211+
188212
lib-python:
189213
needs: compiler
190214
runs-on: ubuntu-24.04

lib/go/test/fuzz/fuzz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
"fmt"
2828
"strconv"
2929

30+
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/fuzztest"
3031
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared"
3132
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/tutorial"
32-
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/fuzztest"
3333
"github.com/apache/thrift/lib/go/thrift"
3434
)
3535

lib/go/test/fuzz/fuzz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build gofuzz
12
// +build gofuzz
23

34
/*

lib/go/test/tests/optional_fields_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestListNotEmpty(t *testing.T) {
182182
}
183183
}
184184

185-
//Make sure that optional fields are not being serialized
185+
// Make sure that optional fields are not being serialized
186186
func TestNoOptionalUnsetFieldsOnWire(t *testing.T) {
187187
mockCtrl := gomock.NewController(t)
188188
defer mockCtrl.Finish()
@@ -210,7 +210,7 @@ func TestNoSetToDefaultFieldsOnWire(t *testing.T) {
210210
ao.Write(context.Background(), proto)
211211
}
212212

213-
//Make sure that only one field is being serialized when set to non-default
213+
// Make sure that only one field is being serialized when set to non-default
214214
func TestOneISetFieldOnWire(t *testing.T) {
215215
mockCtrl := gomock.NewController(t)
216216
defer mockCtrl.Finish()

lib/go/thrift/compact_protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ const maxVarint64Bytes = 10
775775
func (p *TCompactProtocol) readVarint64() (int64, error) {
776776
shift := uint(0)
777777
result := int64(0)
778-
for rsize := 0; rsize < maxVarint64Bytes; rsize++ {
778+
for range maxVarint64Bytes {
779779
b, err := p.readByteDirect()
780780
if err != nil {
781781
return 0, err

lib/go/thrift/framed_transport.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory {
6161

6262
// Deprecated: Use NewTFramedTransportFactoryConf instead.
6363
func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory {
64-
safeMax := maxLength
65-
if safeMax > math.MaxInt32 {
66-
safeMax = math.MaxInt32
67-
}
64+
safeMax := min(maxLength, math.MaxInt32)
6865

6966
return NewTFramedTransportFactoryConf(factory, &TConfiguration{
7067
MaxFrameSize: int32(safeMax),

lib/go/thrift/middleware.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ type ProcessorMiddleware func(name string, next TProcessorFunction) TProcessorFu
3535
//
3636
// Middlewares will be called in the order that they are defined:
3737
//
38-
// 1. Middlewares[0]
39-
// 2. Middlewares[1]
40-
// ...
41-
// N. Middlewares[n]
38+
// Middlewares[0] -> Middlewares[1] -> ... -> Middlewares[n]
4239
func WrapProcessor(processor TProcessor, middlewares ...ProcessorMiddleware) TProcessor {
4340
for name, processorFunc := range processor.ProcessorMap() {
4441
wrapped := processorFunc
@@ -98,10 +95,7 @@ var (
9895
//
9996
// Middlewares will be called in the order that they are defined:
10097
//
101-
// 1. Middlewares[0]
102-
// 2. Middlewares[1]
103-
// ...
104-
// N. Middlewares[n]
98+
// Middlewares[0] -> Middlewares[1] -> ... -> Middlewares[n]
10599
func WrapClient(client TClient, middlewares ...ClientMiddleware) TClient {
106100
// Add middlewares in reverse so the first in the list is the outermost.
107101
for i := len(middlewares) - 1; i >= 0; i-- {
@@ -117,12 +111,12 @@ func WrapClient(client TClient, middlewares ...ClientMiddleware) TClient {
117111
// By default if a client call gets an exception defined in the thrift IDL, for
118112
// example:
119113
//
120-
// service MyService {
121-
// FooResponse foo(1: FooRequest request) throws (
122-
// 1: Exception1 error1,
123-
// 2: Exception2 error2,
124-
// )
125-
// }
114+
// service MyService {
115+
// FooResponse foo(1: FooRequest request) throws (
116+
// 1: Exception1 error1,
117+
// 2: Exception2 error2,
118+
// )
119+
// }
126120
//
127121
// Exception1 or Exception2 will not be in the err return of TClient.Call,
128122
// but in the result TStruct instead, and there's no easy access to them.

lib/go/thrift/server_socket.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
2120
package thrift
2221

2322
import (
@@ -28,9 +27,9 @@ import (
2827

2928
type TServerSocket struct {
3029
// TServerSocketListenerFactory abstracts how listeners are created.
31-
listenerFactory func(net.Addr) (net.Listener, error)
32-
addr net.Addr
33-
clientTimeout time.Duration
30+
listenerFactory func(net.Addr) (net.Listener, error)
31+
addr net.Addr
32+
clientTimeout time.Duration
3433

3534
// Protects the listener and interrupted fields to make them thread safe.
3635
mu sync.RWMutex
@@ -66,9 +65,9 @@ func NewTServerSocketFromAddrTimeout(addr net.Addr, clientTimeout time.Duration)
6665
// Allows full customization (TLS, mocks, unix sockets, windows named pipes, etc.)
6766
func NewTServerSocketFromFactoryTimeout(listenerFactory func(addr net.Addr) (listener net.Listener, err error), addr net.Addr, clientTimeout time.Duration) *TServerSocket {
6867
return &TServerSocket{
69-
listenerFactory: listenerFactory,
70-
addr: addr,
71-
clientTimeout: clientTimeout,
68+
listenerFactory: listenerFactory,
69+
addr: addr,
70+
clientTimeout: clientTimeout,
7271
}
7372
}
7473

@@ -77,7 +76,7 @@ func (p *TServerSocket) try_listen(raise bool) error {
7776
defer p.mu.Unlock()
7877

7978
if p.listener != nil {
80-
if (raise) {
79+
if raise {
8180
return NewTTransportException(ALREADY_OPEN, "Server socket already open")
8281
}
8382
return nil
@@ -145,7 +144,7 @@ func (p *TServerSocket) Addr() net.Addr {
145144
func (p *TServerSocket) try_close(interrupt bool) error {
146145
p.mu.Lock()
147146
defer p.mu.Unlock()
148-
if (interrupt){
147+
if interrupt {
149148
p.interrupted = true
150149
}
151150

lib/go/thrift/socket.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ func NewTSocket(hostPort string) (*TSocket, error) {
5555
//
5656
// Example:
5757
//
58-
// trans := thrift.NewTSocketConf("localhost:9090", &TConfiguration{
59-
// ConnectTimeout: time.Second, // Use 0 for no timeout
60-
// SocketTimeout: time.Second, // Use 0 for no timeout
61-
// })
58+
// trans := thrift.NewTSocketConf("localhost:9090", &TConfiguration{
59+
// ConnectTimeout: time.Second, // Use 0 for no timeout
60+
// SocketTimeout: time.Second, // Use 0 for no timeout
61+
// })
6262
func NewTSocketConf(hostPort string, conf *TConfiguration) *TSocket {
6363
return NewTSocketFromAddrConf(tcpAddr(hostPort), conf)
6464
}
@@ -197,7 +197,7 @@ func (p *TSocket) Close() error {
197197
return p.conn.Close()
198198
}
199199

200-
//Returns the remote address of the socket.
200+
// Returns the remote address of the socket.
201201
func (p *TSocket) Addr() net.Addr {
202202
return p.addr
203203
}

lib/go/thrift/socket_unix_conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
/*
44
* Licensed to the Apache Software Foundation (ASF) under one

0 commit comments

Comments
 (0)