Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/go/test/fuzz/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 1 addition & 0 deletions lib/go/test/fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gofuzz
// +build gofuzz

/*
Expand Down
4 changes: 2 additions & 2 deletions lib/go/test/tests/optional_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/go/thrift/compact_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions lib/go/thrift/framed_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
22 changes: 8 additions & 14 deletions lib/go/thrift/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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-- {
Expand All @@ -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.
Expand Down
17 changes: 8 additions & 9 deletions lib/go/thrift/server_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/


package thrift

import (
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions lib/go/thrift/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion lib/go/thrift/socket_unix_conn_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
//go:build !windows

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down
14 changes: 7 additions & 7 deletions lib/go/thrift/ssl_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading