Skip to content
Open
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
7 changes: 6 additions & 1 deletion generator/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ func (g *GoGenerator) formatType(pkg string, thrift *parser.Thrift, typ *parser.
if pkg != g.pkg {
name = pkg + "." + name
}
return ptr + name
// for reference types like map or list we don't use pointers
if t.RefType() {
return name
} else {
return ptr + name
}
}
if e := thrift.Enums[typ.Name]; e != nil {
name := e.Name
Expand Down
5 changes: 5 additions & 0 deletions parser/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ func (t *Type) String() string {
}
return t.Name
}

// return true for reference types (map, list, set)
func (t *Type) RefType() bool {
return t.KeyType != nil || t.ValueType != nil
}
5 changes: 5 additions & 0 deletions testfiles/generator/rpc_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gentest

type RPCClient interface {
Call(method string, request interface{}, response interface{}) error
}
68 changes: 68 additions & 0 deletions testfiles/generator/typedefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,78 @@ var _ = fmt.Sprintf

type Binary []byte
type Int32 int32
type Map1 map[int32]string
type Map2 map[int32]Map1
type String string

type St struct {
B *Binary `thrift:"1,required" json:"b"`
S *String `thrift:"2,required" json:"s"`
I *Int32 `thrift:"3,required" json:"i"`
}

type Svc interface {
Call(name *string, map1 Map1, data *Binary) (Map2, error)
Ping() (*Binary, error)
}

type SvcServer struct {
Implementation Svc
}

func (s *SvcServer) Call(req *SvcCallRequest, res *SvcCallResponse) error {
val, err := s.Implementation.Call(req.Name, req.Map1, req.Data)
res.Value = val
return err
}

func (s *SvcServer) Ping(req *SvcPingRequest, res *SvcPingResponse) error {
val, err := s.Implementation.Ping()
res.Value = val
return err
}

type SvcCallRequest struct {
Name *string `thrift:"1,required" json:"name"`
Map1 Map1 `thrift:"2,required" json:"map1"`
Data *Binary `thrift:"3,required" json:"data"`
}

type SvcCallResponse struct {
Value Map2 `thrift:"0" json:"value,omitempty"`
}

type SvcPingRequest struct {
}

type SvcPingResponse struct {
Value *Binary `thrift:"0" json:"value,omitempty"`
}

type SvcClient struct {
Client RPCClient
}

func (s *SvcClient) Call(name *string, map1 Map1, data *Binary) (ret Map2, err error) {
req := &SvcCallRequest{
Name: name,
Map1: map1,
Data: data,
}
res := &SvcCallResponse{}
err = s.Client.Call("call", req, res)
if err == nil {
ret = res.Value
}
return
}

func (s *SvcClient) Ping() (ret *Binary, err error) {
req := &SvcPingRequest{}
res := &SvcPingResponse{}
err = s.Client.Call("ping", req, res)
if err == nil {
ret = res.Value
}
return
}
11 changes: 11 additions & 0 deletions testfiles/generator/typedefs.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ namespace go gentest
typedef binary Binary
typedef string String
typedef i32 Int32
typedef map<i32,string> Map1
typedef map<i32,Map1> Map2

struct St {
1: Binary b,
2: String s,
3: Int32 i
}

service Svc {
Binary ping(),
Map2 call(
1:string name,
2:Map1 map1,
3:Binary data)
}