kpumuk opened a new pull request, #3493:
URL: https://github.com/apache/thrift/pull/3493
<!-- Explain the changes in the pull request below: -->
> [!NOTE]
> This is a follow-up to THRIFT-5969, where @fishy mentioned that if I
attempt to make Go compiler to produce `gofmt`-compatible code, they will help
me review it :-)
The change actually makes Thrift compiler for Go to generate clean
`gofmt`-compatible code. There were a few low hanging fruits, such as spaces
around curly braces, but the most challenging part is newlines between blocks
of generated code: instead of simply printing new lines after it, we need to
track what was generated before and insert new lines before the block so we
don't produce excessive new line characters. Another tricky area is aligning
struct fields, which was done by finding the lengths before rendering the
struct.
Additionally, imports have been sorted to separate standard library from
thrift, which is compatible with more strict formatters.
The output was tested on all thrift files found in the repository.
## Comparison
### Imports
Creates 3 distinct groups: stdlib, thrift library, local code.
```diff
"fmt"
"iter"
"log/slog"
+ "regexp"
+ "strings"
"time"
+
thrift "github.com/apache/thrift/lib/go/thrift"
- "strings"
- "regexp"
- "github.com/apache/thrift/tutorial/go/gen-go/shared"
+ "github.com/apache/thrift/tutorial/go/gen-go/shared"
)
```
### Struct fields
```diff
// Attributes:
-// - Success
-// - Ouch
-//
+// - Success
+// - Ouch
type CalculatorCalculateResult struct {
- Success *int32 `thrift:"success,0" db:"success"
json:"success,omitempty"`
- Ouch *InvalidOperation `thrift:"ouch,1" db:"ouch" json:"ouch,omitempty"`
+ Success *int32 `thrift:"success,0" db:"success"
json:"success,omitempty"`
+ Ouch *InvalidOperation `thrift:"ouch,1" db:"ouch"
json:"ouch,omitempty"`
}
```
### Enums
```diff
func OperationFromString(s string) (Operation, error) {
switch s {
- case "ADD": return Operation_ADD, nil
- case "SUBTRACT": return Operation_SUBTRACT, nil
- case "MULTIPLY": return Operation_MULTIPLY, nil
- case "DIVIDE": return Operation_DIVIDE, nil
+ case "ADD":
+ return Operation_ADD, nil
+ case "SUBTRACT":
+ return Operation_SUBTRACT, nil
+ case "MULTIPLY":
+ return Operation_MULTIPLY, nil
+ case "DIVIDE":
+ return Operation_DIVIDE, nil
}
return Operation(0), fmt.Errorf("not a valid Operation string")
}
```
## Full Diff
<details><summary>Click to expand</summary>
```diff
diff --color -ru go-compiler/before/shared/GoUnusedProtection__.go
go-compiler/after/shared/GoUnusedProtection__.go
--- go-compiler/before/shared/GoUnusedProtection__.go 2026-05-18
15:02:36
+++ go-compiler/after/shared/GoUnusedProtection__.go 2026-05-18 15:02:36
@@ -2,5 +2,4 @@
package shared
-var GoUnusedProtection__ int;
-
+var GoUnusedProtection__ int
diff --color -ru go-compiler/before/shared/shared-consts.go
go-compiler/after/shared/shared-consts.go
--- go-compiler/before/shared/shared-consts.go 2026-05-18 15:02:36
+++ go-compiler/after/shared/shared-consts.go 2026-05-18 15:02:36
@@ -9,10 +9,11 @@
"fmt"
"iter"
"log/slog"
+ "regexp"
+ "strings"
"time"
+
thrift "github.com/apache/thrift/lib/go/thrift"
- "strings"
- "regexp"
)
// (needed to ensure safety because of naive import list construction.)
@@ -24,11 +25,10 @@
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
+
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
-
func init() {
}
-
diff --color -ru go-compiler/before/shared/shared.go
go-compiler/after/shared/shared.go
--- go-compiler/before/shared/shared.go 2026-05-18 15:02:36
+++ go-compiler/after/shared/shared.go 2026-05-18 15:02:36
@@ -9,10 +9,11 @@
"fmt"
"iter"
"log/slog"
+ "regexp"
+ "strings"
"time"
+
thrift "github.com/apache/thrift/lib/go/thrift"
- "strings"
- "regexp"
)
// (needed to ensure safety because of naive import list construction.)
@@ -24,16 +25,16 @@
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
+
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
// Attributes:
-// - Key
-// - Value
-//
+// - Key
+// - Value
type SharedStruct struct {
- Key int32 `thrift:"key,1" db:"key" json:"key"`
+ Key int32 `thrift:"key,1" db:"key" json:"key"`
Value string `thrift:"value,2" db:"value" json:"value"`
}
@@ -41,14 +42,10 @@
return &SharedStruct{}
}
-
-
func (p *SharedStruct) GetKey() int32 {
return p.Key
}
-
-
func (p *SharedStruct) GetValue() string {
return p.Value
}
@@ -57,8 +54,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -126,8 +121,12 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
- if err := p.writeField2(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField2(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -170,8 +169,12 @@
} else if p == nil || other == nil {
return false
}
- if p.Key != other.Key { return false }
- if p.Value != other.Value { return false }
+ if p.Key != other.Key {
+ return false
+ }
+ if p.Value != other.Value {
+ return false
+ }
return true
}
@@ -187,7 +190,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*shared.SharedStruct",
+ Type: "*shared.SharedStruct",
Value: p,
}
return slog.AnyValue(v)
@@ -201,13 +204,12 @@
type SharedService interface {
// Parameters:
- // - Key
- //
+ // - Key
GetStruct(ctx context.Context, key int32) (_r *SharedStruct, _err error)
}
type SharedServiceClient struct {
- c thrift.TClient
+ c thrift.TClient
meta thrift.ResponseMeta
}
@@ -242,8 +244,7 @@
}
// Parameters:
-// - Key
-//
+// - Key
func (p *SharedServiceClient) GetStruct(ctx context.Context, key int32) (_r
*SharedStruct, _err error) {
var _args0 SharedServiceGetStructArgs
_args0.Key = key
@@ -262,7 +263,7 @@
type SharedServiceProcessor struct {
processorMap map[string]thrift.TProcessorFunction
- handler SharedService
+ handler SharedService
}
func (p *SharedServiceProcessor) AddToProcessorMap(key string, processor
thrift.TProcessorFunction) {
@@ -280,20 +281,22 @@
func NewSharedServiceProcessor(handler SharedService)
*SharedServiceProcessor {
- self4 := &SharedServiceProcessor{handler:handler,
processorMap:make(map[string]thrift.TProcessorFunction)}
- self4.processorMap["getStruct"] =
&sharedServiceProcessorGetStruct{handler:handler}
+ self4 := &SharedServiceProcessor{handler: handler, processorMap:
make(map[string]thrift.TProcessorFunction)}
+ self4.processorMap["getStruct"] =
&sharedServiceProcessorGetStruct{handler: handler}
return self4
}
func (p *SharedServiceProcessor) Process(ctx context.Context, iprot, oprot
thrift.TProtocol) (success bool, err thrift.TException) {
name, _, seqId, err2 := iprot.ReadMessageBegin(ctx)
- if err2 != nil { return false, thrift.WrapTException(err2) }
+ if err2 != nil {
+ return false, thrift.WrapTException(err2)
+ }
if processor, ok := p.GetProcessorFunction(name); ok {
return processor.Process(ctx, seqId, iprot, oprot)
}
iprot.Skip(ctx, thrift.STRUCT)
iprot.ReadMessageEnd(ctx)
- x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown
function " + name)
+ x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown
function "+name)
oprot.WriteMessageBegin(ctx, name, thrift.EXCEPTION, seqId)
x5.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
@@ -363,7 +366,7 @@
}
}
}
- _exc7 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR,
"Internal error processing getStruct: " + err2.Error())
+ _exc7 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR,
"Internal error processing getStruct: "+err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "getStruct",
thrift.EXCEPTION, seqId); err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
@@ -408,12 +411,10 @@
return true, err
}
-
// HELPER FUNCTIONS AND STRUCTURES
// Attributes:
-// - Key
-//
+// - Key
type SharedServiceGetStructArgs struct {
Key int32 `thrift:"key,1" db:"key" json:"key"`
}
@@ -422,8 +423,6 @@
return &SharedServiceGetStructArgs{}
}
-
-
func (p *SharedServiceGetStructArgs) GetKey() int32 {
return p.Key
}
@@ -432,8 +431,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -482,7 +479,9 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -518,7 +517,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*shared.SharedServiceGetStructArgs",
+ Type: "*shared.SharedServiceGetStructArgs",
Value: p,
}
return slog.AnyValue(v)
@@ -527,8 +526,7 @@
var _ slog.LogValuer = (*SharedServiceGetStructArgs)(nil)
// Attributes:
-// - Success
-//
+// - Success
type SharedServiceGetStructResult struct {
Success *SharedStruct `thrift:"success,0" db:"success"
json:"success,omitempty"`
}
@@ -554,8 +552,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -603,7 +599,9 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField0(ctx, oprot); err != nil { return err }
+ if err := p.writeField0(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -641,12 +639,10 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*shared.SharedServiceGetStructResult",
+ Type: "*shared.SharedServiceGetStructResult",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*SharedServiceGetStructResult)(nil)
-
-
diff --color -ru
go-compiler/before/shared/shared_service-remote/shared_service-remote.go
go-compiler/after/shared/shared_service-remote/shared_service-remote.go
--- go-compiler/before/shared/shared_service-remote/shared_service-remote.go
2026-05-18 15:02:36
+++ go-compiler/after/shared/shared_service-remote/shared_service-remote.go
2026-05-18 15:02:36
@@ -12,7 +12,9 @@
"os"
"strconv"
"strings"
+
thrift "github.com/apache/thrift/lib/go/thrift"
+
"github.com/apache/thrift/tutorial/go/gen-go/shared"
)
@@ -65,7 +67,7 @@
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H
\"Key: Value\")")
flag.Parse()
-
+
if len(urlString) > 0 {
var err error
parsedUrl, err = url.Parse(urlString)
@@ -82,7 +84,7 @@
flag.Usage()
}
}
-
+
cmd := flag.Arg(0)
var err error
var cfg *thrift.TConfiguration = nil
@@ -139,10 +141,10 @@
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":",
port, " ", err)
os.Exit(1)
}
-
+
switch cmd {
case "getStruct":
- if flag.NArg() - 1 != 1 {
+ if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "GetStruct requires 1 args")
flag.Usage()
}
diff --color -ru go-compiler/before/tutorial/GoUnusedProtection__.go
go-compiler/after/tutorial/GoUnusedProtection__.go
--- go-compiler/before/tutorial/GoUnusedProtection__.go 2026-05-18
15:02:36
+++ go-compiler/after/tutorial/GoUnusedProtection__.go 2026-05-18
15:02:36
@@ -2,5 +2,4 @@
package tutorial
-var GoUnusedProtection__ int;
-
+var GoUnusedProtection__ int
diff --color -ru
go-compiler/before/tutorial/calculator-remote/calculator-remote.go
go-compiler/after/tutorial/calculator-remote/calculator-remote.go
--- go-compiler/before/tutorial/calculator-remote/calculator-remote.go
2026-05-18 15:02:36
+++ go-compiler/after/tutorial/calculator-remote/calculator-remote.go
2026-05-18 15:02:36
@@ -12,7 +12,9 @@
"os"
"strconv"
"strings"
+
thrift "github.com/apache/thrift/lib/go/thrift"
+
"github.com/apache/thrift/tutorial/go/gen-go/shared"
"github.com/apache/thrift/tutorial/go/gen-go/tutorial"
)
@@ -71,7 +73,7 @@
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H
\"Key: Value\")")
flag.Parse()
-
+
if len(urlString) > 0 {
var err error
parsedUrl, err = url.Parse(urlString)
@@ -88,7 +90,7 @@
flag.Usage()
}
}
-
+
cmd := flag.Arg(0)
var err error
var cfg *thrift.TConfiguration = nil
@@ -145,10 +147,10 @@
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":",
port, " ", err)
os.Exit(1)
}
-
+
switch cmd {
case "ping":
- if flag.NArg() - 1 != 0 {
+ if flag.NArg()-1 != 0 {
fmt.Fprintln(os.Stderr, "Ping requires 0 args")
flag.Usage()
}
@@ -156,7 +158,7 @@
fmt.Print("\n")
break
case "add":
- if flag.NArg() - 1 != 2 {
+ if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "Add requires 2 args")
flag.Usage()
}
@@ -178,7 +180,7 @@
fmt.Print("\n")
break
case "calculate":
- if flag.NArg() - 1 != 2 {
+ if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "Calculate requires 2 args")
flag.Usage()
}
@@ -210,7 +212,7 @@
fmt.Print("\n")
break
case "zip":
- if flag.NArg() - 1 != 0 {
+ if flag.NArg()-1 != 0 {
fmt.Fprintln(os.Stderr, "Zip requires 0 args")
flag.Usage()
}
@@ -218,7 +220,7 @@
fmt.Print("\n")
break
case "getStruct":
- if flag.NArg() - 1 != 1 {
+ if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "GetStruct requires 1 args")
flag.Usage()
}
diff --color -ru go-compiler/before/tutorial/tutorial-consts.go
go-compiler/after/tutorial/tutorial-consts.go
--- go-compiler/before/tutorial/tutorial-consts.go 2026-05-18 15:02:36
+++ go-compiler/after/tutorial/tutorial-consts.go 2026-05-18 15:02:36
@@ -9,12 +9,13 @@
"fmt"
"iter"
"log/slog"
+ "regexp"
+ "strings"
"time"
+
thrift "github.com/apache/thrift/lib/go/thrift"
- "strings"
- "regexp"
- "github.com/apache/thrift/tutorial/go/gen-go/shared"
+ "github.com/apache/thrift/tutorial/go/gen-go/shared"
)
// (needed to ensure safety because of naive import list construction.)
@@ -26,19 +27,19 @@
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
+
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
-
var _ = shared.GoUnusedProtection__
+
const INT32CONSTANT = 9853
+
var MAPCONSTANT map[string]string
func init() {
-MAPCONSTANT = map[string]string{
- "goodnight": "moon",
- "hello": "world",
+ MAPCONSTANT = map[string]string{
+ "goodnight": "moon",
+ "hello": "world",
+ }
}
-
-}
-
diff --color -ru go-compiler/before/tutorial/tutorial.go
go-compiler/after/tutorial/tutorial.go
--- go-compiler/before/tutorial/tutorial.go 2026-05-18 15:02:36
+++ go-compiler/after/tutorial/tutorial.go 2026-05-18 15:02:36
@@ -10,12 +10,13 @@
"fmt"
"iter"
"log/slog"
+ "regexp"
+ "strings"
"time"
+
thrift "github.com/apache/thrift/lib/go/thrift"
- "strings"
- "regexp"
- "github.com/apache/thrift/tutorial/go/gen-go/shared"
+ "github.com/apache/thrift/tutorial/go/gen-go/shared"
)
// (needed to ensure safety because of naive import list construction.)
@@ -27,20 +28,21 @@
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
+
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
-
var _ = shared.GoUnusedProtection__
-//You can define enums, which are just 32 bit integers. Values are optional
-//and start at 1 if not supplied, C style again.
+
+// You can define enums, which are just 32 bit integers. Values are optional
+// and start at 1 if not supplied, C style again.
type Operation int64
const (
- Operation_ADD Operation = 1
+ Operation_ADD Operation = 1
Operation_SUBTRACT Operation = 2
Operation_MULTIPLY Operation = 3
- Operation_DIVIDE Operation = 4
+ Operation_DIVIDE Operation = 4
)
var knownOperationValues = []Operation{
@@ -59,28 +61,34 @@
}
}
}
-
func (p Operation) String() string {
switch p {
- case Operation_ADD: return "ADD"
- case Operation_SUBTRACT: return "SUBTRACT"
- case Operation_MULTIPLY: return "MULTIPLY"
- case Operation_DIVIDE: return "DIVIDE"
+ case Operation_ADD:
+ return "ADD"
+ case Operation_SUBTRACT:
+ return "SUBTRACT"
+ case Operation_MULTIPLY:
+ return "MULTIPLY"
+ case Operation_DIVIDE:
+ return "DIVIDE"
}
return "<UNSET>"
}
func OperationFromString(s string) (Operation, error) {
switch s {
- case "ADD": return Operation_ADD, nil
- case "SUBTRACT": return Operation_SUBTRACT, nil
- case "MULTIPLY": return Operation_MULTIPLY, nil
- case "DIVIDE": return Operation_DIVIDE, nil
+ case "ADD":
+ return Operation_ADD, nil
+ case "SUBTRACT":
+ return Operation_SUBTRACT, nil
+ case "MULTIPLY":
+ return Operation_MULTIPLY, nil
+ case "DIVIDE":
+ return Operation_DIVIDE, nil
}
return Operation(0), fmt.Errorf("not a valid Operation string")
}
-
func OperationPtr(v Operation) *Operation { return &v }
func (p Operation) MarshalText() ([]byte, error) {
@@ -112,8 +120,8 @@
return int64(*p), nil
}
-//Thrift lets you do typedefs to get pretty names for your types. Standard
-//C style here.
+// Thrift lets you do typedefs to get pretty names for your types. Standard
+// C style here.
type MyInteger int32
func MyIntegerPtr(v MyInteger) *MyInteger { return &v }
@@ -121,42 +129,35 @@
// Structs are the basic complex data structures. They are comprised of
fields
// which each have an integer identifier, a type, a symbolic name, and an
// optional default value.
-//
+//
// Fields can be declared "optional", which ensures they will not be
included
// in the serialized output if they aren't set. Note that this requires
some
// manual management in some languages.
-//
+//
// Attributes:
-// - Num1
-// - Num2
-// - Op
-// - Comment
-//
+// - Num1
+// - Num2
+// - Op
+// - Comment
type Work struct {
- Num1 int32 `thrift:"num1,1" db:"num1" json:"num1"`
- Num2 int32 `thrift:"num2,2" db:"num2" json:"num2"`
- Op Operation `thrift:"op,3" db:"op" json:"op"`
- Comment *string `thrift:"comment,4" db:"comment"
json:"comment,omitempty"`
+ Num1 int32 `thrift:"num1,1" db:"num1" json:"num1"`
+ Num2 int32 `thrift:"num2,2" db:"num2" json:"num2"`
+ Op Operation `thrift:"op,3" db:"op" json:"op"`
+ Comment *string `thrift:"comment,4" db:"comment"
json:"comment,omitempty"`
}
func NewWork() *Work {
return &Work{}
}
-
-
func (p *Work) GetNum1() int32 {
return p.Num1
}
-
-
func (p *Work) GetNum2() int32 {
return p.Num2
}
-
-
func (p *Work) GetOp() Operation {
return p.Op
}
@@ -178,8 +179,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -286,10 +285,18 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
- if err := p.writeField2(ctx, oprot); err != nil { return err }
- if err := p.writeField3(ctx, oprot); err != nil { return err }
- if err := p.writeField4(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField2(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField3(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField4(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -360,14 +367,22 @@
} else if p == nil || other == nil {
return false
}
- if p.Num1 != other.Num1 { return false }
- if p.Num2 != other.Num2 { return false }
- if p.Op != other.Op { return false }
+ if p.Num1 != other.Num1 {
+ return false
+ }
+ if p.Num2 != other.Num2 {
+ return false
+ }
+ if p.Op != other.Op {
+ return false
+ }
if p.Comment != other.Comment {
if p.Comment == nil || other.Comment == nil {
return false
}
- if (*p.Comment) != (*other.Comment) { return false }
+ if *p.Comment != *other.Comment {
+ return false
+ }
}
return true
}
@@ -384,7 +399,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.Work",
+ Type: "*tutorial.Work",
Value: p,
}
return slog.AnyValue(v)
@@ -397,28 +412,23 @@
}
// Structs can also be exceptions, if they are nasty.
-//
+//
// Attributes:
-// - WhatOp
-// - Why
-//
+// - WhatOp
+// - Why
type InvalidOperation struct {
- WhatOp int32 `thrift:"whatOp,1" db:"whatOp" json:"whatOp"`
- Why string `thrift:"why,2" db:"why" json:"why"`
+ WhatOp int32 `thrift:"whatOp,1" db:"whatOp" json:"whatOp"`
+ Why string `thrift:"why,2" db:"why" json:"why"`
}
func NewInvalidOperation() *InvalidOperation {
return &InvalidOperation{}
}
-
-
func (p *InvalidOperation) GetWhatOp() int32 {
return p.WhatOp
}
-
-
func (p *InvalidOperation) GetWhy() string {
return p.Why
}
@@ -427,8 +437,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -496,8 +504,12 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
- if err := p.writeField2(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField2(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -540,8 +552,12 @@
} else if p == nil || other == nil {
return false
}
- if p.WhatOp != other.WhatOp { return false }
- if p.Why != other.Why { return false }
+ if p.WhatOp != other.WhatOp {
+ return false
+ }
+ if p.Why != other.Why {
+ return false
+ }
return true
}
@@ -567,7 +583,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.InvalidOperation",
+ Type: "*tutorial.InvalidOperation",
Value: p,
}
return slog.AnyValue(v)
@@ -581,8 +597,8 @@
type Calculator interface {
shared.SharedService
- //Ahh, now onto the cool part, defining a service. Services just need a
name
- //and can optionally inherit from another service using the extends
keyword.
+ // Ahh, now onto the cool part, defining a service. Services just need
a name
+ // and can optionally inherit from another service using the extends
keyword.
// A method definition looks like C code. It has a return type,
arguments,
// and optionally a list of exceptions that it may throw. Note that
argument
@@ -590,14 +606,12 @@
// field lists in struct or exception definitions.
Ping(ctx context.Context) (_err error)
// Parameters:
- // - Num1
- // - Num2
- //
+ // - Num1
+ // - Num2
Add(ctx context.Context, num1 int32, num2 int32) (_r int32, _err error)
// Parameters:
- // - Logid
- // - W
- //
+ // - Logid
+ // - W
Calculate(ctx context.Context, logid int32, w *Work) (_r int32, _err
error)
// This method has a oneway modifier. That means the client only makes
// a request and does not listen for any response at all. Oneway methods
@@ -605,14 +619,15 @@
Zip(ctx context.Context) (_err error)
}
-//Ahh, now onto the cool part, defining a service. Services just need a name
-//and can optionally inherit from another service using the extends keyword.
+// Ahh, now onto the cool part, defining a service. Services just need a
name
+// and can optionally inherit from another service using the extends
keyword.
type CalculatorClient struct {
*shared.SharedServiceClient
}
func NewCalculatorClientFactory(t thrift.TTransport, f
thrift.TProtocolFactory) *CalculatorClient {
- return &CalculatorClient{SharedServiceClient:
shared.NewSharedServiceClientFactory(t, f)}}
+ return &CalculatorClient{SharedServiceClient:
shared.NewSharedServiceClientFactory(t, f)}
+}
func NewCalculatorClientProtocol(t thrift.TTransport, iprot
thrift.TProtocol, oprot thrift.TProtocol) *CalculatorClient {
return &CalculatorClient{SharedServiceClient:
shared.NewSharedServiceClientProtocol(t, iprot, oprot)}
@@ -641,9 +656,8 @@
}
// Parameters:
-// - Num1
-// - Num2
-//
+// - Num1
+// - Num2
func (p *CalculatorClient) Add(ctx context.Context, num1 int32, num2 int32)
(_r int32, _err error) {
var _args3 CalculatorAddArgs
_args3.Num1 = num1
@@ -659,9 +673,8 @@
}
// Parameters:
-// - Logid
-// - W
-//
+// - Logid
+// - W
func (p *CalculatorClient) Calculate(ctx context.Context, logid int32, w
*Work) (_r int32, _err error) {
var _args6 CalculatorCalculateArgs
_args6.Logid = logid
@@ -674,7 +687,7 @@
return
}
switch {
- case _result8.Ouch!= nil:
+ case _result8.Ouch != nil:
return _r, _result8.Ouch
}
@@ -699,10 +712,10 @@
func NewCalculatorProcessor(handler Calculator) *CalculatorProcessor {
self10 :=
&CalculatorProcessor{shared.NewSharedServiceProcessor(handler)}
- self10.AddToProcessorMap("ping",
&calculatorProcessorPing{handler:handler})
- self10.AddToProcessorMap("add",
&calculatorProcessorAdd{handler:handler})
- self10.AddToProcessorMap("calculate",
&calculatorProcessorCalculate{handler:handler})
- self10.AddToProcessorMap("zip",
&calculatorProcessorZip{handler:handler})
+ self10.AddToProcessorMap("ping", &calculatorProcessorPing{handler:
handler})
+ self10.AddToProcessorMap("add", &calculatorProcessorAdd{handler:
handler})
+ self10.AddToProcessorMap("calculate",
&calculatorProcessorCalculate{handler: handler})
+ self10.AddToProcessorMap("zip", &calculatorProcessorZip{handler:
handler})
return self10
}
@@ -768,7 +781,7 @@
}
}
}
- _exc12 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing ping: " + err2.Error())
+ _exc12 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing ping: "+err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "ping",
thrift.EXCEPTION, seqId); err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
@@ -873,7 +886,7 @@
}
}
}
- _exc14 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing add: " + err2.Error())
+ _exc14 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing add: "+err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "add",
thrift.EXCEPTION, seqId); err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
@@ -984,7 +997,7 @@
}
}
}
- _exc16 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing calculate: " + err2.Error())
+ _exc16 :=
thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error
processing calculate: "+err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "calculate",
thrift.EXCEPTION, seqId); err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
@@ -1053,7 +1066,6 @@
return true, err
}
-
// HELPER FUNCTIONS AND STRUCTURES
type CalculatorPingArgs struct {
@@ -1067,8 +1079,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1117,7 +1127,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorPingArgs",
+ Type: "*tutorial.CalculatorPingArgs",
Value: p,
}
return slog.AnyValue(v)
@@ -1136,8 +1146,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1186,7 +1194,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorPingResult",
+ Type: "*tutorial.CalculatorPingResult",
Value: p,
}
return slog.AnyValue(v)
@@ -1195,9 +1203,8 @@
var _ slog.LogValuer = (*CalculatorPingResult)(nil)
// Attributes:
-// - Num1
-// - Num2
-//
+// - Num1
+// - Num2
type CalculatorAddArgs struct {
Num1 int32 `thrift:"num1,1" db:"num1" json:"num1"`
Num2 int32 `thrift:"num2,2" db:"num2" json:"num2"`
@@ -1207,14 +1214,10 @@
return &CalculatorAddArgs{}
}
-
-
func (p *CalculatorAddArgs) GetNum1() int32 {
return p.Num1
}
-
-
func (p *CalculatorAddArgs) GetNum2() int32 {
return p.Num2
}
@@ -1223,8 +1226,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1292,8 +1293,12 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
- if err := p.writeField2(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField2(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -1342,7 +1347,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorAddArgs",
+ Type: "*tutorial.CalculatorAddArgs",
Value: p,
}
return slog.AnyValue(v)
@@ -1351,8 +1356,7 @@
var _ slog.LogValuer = (*CalculatorAddArgs)(nil)
// Attributes:
-// - Success
-//
+// - Success
type CalculatorAddResult struct {
Success *int32 `thrift:"success,0" db:"success"
json:"success,omitempty"`
}
@@ -1378,8 +1382,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1428,7 +1430,9 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField0(ctx, oprot); err != nil { return err }
+ if err := p.writeField0(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -1466,7 +1470,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorAddResult",
+ Type: "*tutorial.CalculatorAddResult",
Value: p,
}
return slog.AnyValue(v)
@@ -1475,20 +1479,17 @@
var _ slog.LogValuer = (*CalculatorAddResult)(nil)
// Attributes:
-// - Logid
-// - W
-//
+// - Logid
+// - W
type CalculatorCalculateArgs struct {
Logid int32 `thrift:"logid,1" db:"logid" json:"logid"`
- W *Work `thrift:"w,2" db:"w" json:"w"`
+ W *Work `thrift:"w,2" db:"w" json:"w"`
}
func NewCalculatorCalculateArgs() *CalculatorCalculateArgs {
return &CalculatorCalculateArgs{}
}
-
-
func (p *CalculatorCalculateArgs) GetLogid() int32 {
return p.Logid
}
@@ -1510,8 +1511,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1578,8 +1577,12 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField1(ctx, oprot); err != nil { return err }
- if err := p.writeField2(ctx, oprot); err != nil { return err }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField2(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -1628,7 +1631,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorCalculateArgs",
+ Type: "*tutorial.CalculatorCalculateArgs",
Value: p,
}
return slog.AnyValue(v)
@@ -1637,12 +1640,11 @@
var _ slog.LogValuer = (*CalculatorCalculateArgs)(nil)
// Attributes:
-// - Success
-// - Ouch
-//
+// - Success
+// - Ouch
type CalculatorCalculateResult struct {
- Success *int32 `thrift:"success,0" db:"success"
json:"success,omitempty"`
- Ouch *InvalidOperation `thrift:"ouch,1" db:"ouch" json:"ouch,omitempty"`
+ Success *int32 `thrift:"success,0" db:"success"
json:"success,omitempty"`
+ Ouch *InvalidOperation `thrift:"ouch,1" db:"ouch"
json:"ouch,omitempty"`
}
func NewCalculatorCalculateResult() *CalculatorCalculateResult {
@@ -1679,8 +1681,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1747,8 +1747,12 @@
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if p != nil {
- if err := p.writeField0(ctx, oprot); err != nil { return err }
- if err := p.writeField1(ctx, oprot); err != nil { return err }
+ if err := p.writeField0(ctx, oprot); err != nil {
+ return err
+ }
+ if err := p.writeField1(ctx, oprot); err != nil {
+ return err
+ }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
@@ -1801,7 +1805,7 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorCalculateResult",
+ Type: "*tutorial.CalculatorCalculateResult",
Value: p,
}
return slog.AnyValue(v)
@@ -1820,8 +1824,6 @@
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p),
err)
}
-
-
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
@@ -1870,12 +1872,10 @@
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
- Type: "*tutorial.CalculatorZipArgs",
+ Type: "*tutorial.CalculatorZipArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorZipArgs)(nil)
-
-
```
</details>
<!-- We recommend you review the checklist/tips before submitting a pull
request. -->
- [x] Did you create an [Apache
Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?
[THRIFT-6011](https://issues.apache.org/jira/browse/THRIFT-6011)
- [x] If a ticket exists: Does your pull request title follow the pattern
"THRIFT-NNNN: describe my issue"?
- [x] Did you squash your changes to a single commit? (not required, but
preferred)
- [x] Did you do your best to avoid breaking changes? If one was needed,
did you label the Jira ticket with "Breaking-Change"?
- [ ] If your change does not involve any code, include `[skip ci]` anywhere
in the commit message to free up build resources.
<!--
The Contributing Guide at:
https://github.com/apache/thrift/blob/master/CONTRIBUTING.md
has more details and tips for committing properly.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]