New Thrift release, no more hacks required
Peter Bourgon
8 years ago
0 | struct SumReply { | |
1 | 1: i64 value | |
2 | } | |
3 | ||
4 | struct ConcatReply { | |
5 | 1: string value | |
6 | } | |
7 | ||
8 | service AddService { | |
9 | SumReply Sum(1: i64 a, 2: i64 b) | |
10 | ConcatReply Concat(1: string a, 2: string b) | |
11 | } |
0 | #!/usr/bin/env sh | |
1 | ||
2 | # Thrift code generation for Go is broken in the current stable (0.9.2) | |
3 | # release. See https://issues.apache.org/jira/browse/THRIFT-3021. We prefix | |
4 | # `thrift` as `_thrift` so the `go` tool ignores the subdir. | |
5 | # | |
6 | # See also | |
7 | # https://thrift.apache.org/tutorial/go | |
8 | ||
9 | thrift -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift add.thrift |
0 | // Autogenerated by Thrift Compiler (0.9.2) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package main | |
4 | ||
5 | import ( | |
6 | "add" | |
7 | "flag" | |
8 | "fmt" | |
9 | "github.com/apache/thrift/lib/go/thrift" | |
10 | "math" | |
11 | "net" | |
12 | "net/url" | |
13 | "os" | |
14 | "strconv" | |
15 | "strings" | |
16 | ) | |
17 | ||
18 | func Usage() { | |
19 | fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") | |
20 | flag.PrintDefaults() | |
21 | fmt.Fprintln(os.Stderr, "\nFunctions:") | |
22 | fmt.Fprintln(os.Stderr, " SumReply Sum(i64 a, i64 b)") | |
23 | fmt.Fprintln(os.Stderr, " ConcatReply Concat(string a, string b)") | |
24 | fmt.Fprintln(os.Stderr) | |
25 | os.Exit(0) | |
26 | } | |
27 | ||
28 | func main() { | |
29 | flag.Usage = Usage | |
30 | var host string | |
31 | var port int | |
32 | var protocol string | |
33 | var urlString string | |
34 | var framed bool | |
35 | var useHttp bool | |
36 | var parsedUrl url.URL | |
37 | var trans thrift.TTransport | |
38 | _ = strconv.Atoi | |
39 | _ = math.Abs | |
40 | flag.Usage = Usage | |
41 | flag.StringVar(&host, "h", "localhost", "Specify host and port") | |
42 | flag.IntVar(&port, "p", 9090, "Specify port") | |
43 | flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") | |
44 | flag.StringVar(&urlString, "u", "", "Specify the url") | |
45 | flag.BoolVar(&framed, "framed", false, "Use framed transport") | |
46 | flag.BoolVar(&useHttp, "http", false, "Use http") | |
47 | flag.Parse() | |
48 | ||
49 | if len(urlString) > 0 { | |
50 | parsedUrl, err := url.Parse(urlString) | |
51 | if err != nil { | |
52 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) | |
53 | flag.Usage() | |
54 | } | |
55 | host = parsedUrl.Host | |
56 | useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" | |
57 | } else if useHttp { | |
58 | _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) | |
59 | if err != nil { | |
60 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) | |
61 | flag.Usage() | |
62 | } | |
63 | } | |
64 | ||
65 | cmd := flag.Arg(0) | |
66 | var err error | |
67 | if useHttp { | |
68 | trans, err = thrift.NewTHttpClient(parsedUrl.String()) | |
69 | } else { | |
70 | portStr := fmt.Sprint(port) | |
71 | if strings.Contains(host, ":") { | |
72 | host, portStr, err = net.SplitHostPort(host) | |
73 | if err != nil { | |
74 | fmt.Fprintln(os.Stderr, "error with host:", err) | |
75 | os.Exit(1) | |
76 | } | |
77 | } | |
78 | trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) | |
79 | if err != nil { | |
80 | fmt.Fprintln(os.Stderr, "error resolving address:", err) | |
81 | os.Exit(1) | |
82 | } | |
83 | if framed { | |
84 | trans = thrift.NewTFramedTransport(trans) | |
85 | } | |
86 | } | |
87 | if err != nil { | |
88 | fmt.Fprintln(os.Stderr, "Error creating transport", err) | |
89 | os.Exit(1) | |
90 | } | |
91 | defer trans.Close() | |
92 | var protocolFactory thrift.TProtocolFactory | |
93 | switch protocol { | |
94 | case "compact": | |
95 | protocolFactory = thrift.NewTCompactProtocolFactory() | |
96 | break | |
97 | case "simplejson": | |
98 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() | |
99 | break | |
100 | case "json": | |
101 | protocolFactory = thrift.NewTJSONProtocolFactory() | |
102 | break | |
103 | case "binary", "": | |
104 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() | |
105 | break | |
106 | default: | |
107 | fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) | |
108 | Usage() | |
109 | os.Exit(1) | |
110 | } | |
111 | client := add.NewAddServiceClientFactory(trans, protocolFactory) | |
112 | if err := trans.Open(); err != nil { | |
113 | fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) | |
114 | os.Exit(1) | |
115 | } | |
116 | ||
117 | switch cmd { | |
118 | case "Sum": | |
119 | if flag.NArg()-1 != 2 { | |
120 | fmt.Fprintln(os.Stderr, "Sum requires 2 args") | |
121 | flag.Usage() | |
122 | } | |
123 | argvalue0, err6 := (strconv.ParseInt(flag.Arg(1), 10, 64)) | |
124 | if err6 != nil { | |
125 | Usage() | |
126 | return | |
127 | } | |
128 | value0 := argvalue0 | |
129 | argvalue1, err7 := (strconv.ParseInt(flag.Arg(2), 10, 64)) | |
130 | if err7 != nil { | |
131 | Usage() | |
132 | return | |
133 | } | |
134 | value1 := argvalue1 | |
135 | fmt.Print(client.Sum(value0, value1)) | |
136 | fmt.Print("\n") | |
137 | break | |
138 | case "Concat": | |
139 | if flag.NArg()-1 != 2 { | |
140 | fmt.Fprintln(os.Stderr, "Concat requires 2 args") | |
141 | flag.Usage() | |
142 | } | |
143 | argvalue0 := flag.Arg(1) | |
144 | value0 := argvalue0 | |
145 | argvalue1 := flag.Arg(2) | |
146 | value1 := argvalue1 | |
147 | fmt.Print(client.Concat(value0, value1)) | |
148 | fmt.Print("\n") | |
149 | break | |
150 | case "": | |
151 | Usage() | |
152 | break | |
153 | default: | |
154 | fmt.Fprintln(os.Stderr, "Invalid function ", cmd) | |
155 | } | |
156 | } |
0 | // Autogenerated by Thrift Compiler (0.9.2) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | type AddService interface { | |
17 | // Parameters: | |
18 | // - A | |
19 | // - B | |
20 | Sum(a int64, b int64) (r *SumReply, err error) | |
21 | // Parameters: | |
22 | // - A | |
23 | // - B | |
24 | Concat(a string, b string) (r *ConcatReply, err error) | |
25 | } | |
26 | ||
27 | type AddServiceClient struct { | |
28 | Transport thrift.TTransport | |
29 | ProtocolFactory thrift.TProtocolFactory | |
30 | InputProtocol thrift.TProtocol | |
31 | OutputProtocol thrift.TProtocol | |
32 | SeqId int32 | |
33 | } | |
34 | ||
35 | func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { | |
36 | return &AddServiceClient{Transport: t, | |
37 | ProtocolFactory: f, | |
38 | InputProtocol: f.GetProtocol(t), | |
39 | OutputProtocol: f.GetProtocol(t), | |
40 | SeqId: 0, | |
41 | } | |
42 | } | |
43 | ||
44 | func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { | |
45 | return &AddServiceClient{Transport: t, | |
46 | ProtocolFactory: nil, | |
47 | InputProtocol: iprot, | |
48 | OutputProtocol: oprot, | |
49 | SeqId: 0, | |
50 | } | |
51 | } | |
52 | ||
53 | // Parameters: | |
54 | // - A | |
55 | // - B | |
56 | func (p *AddServiceClient) Sum(a int64, b int64) (r *SumReply, err error) { | |
57 | if err = p.sendSum(a, b); err != nil { | |
58 | return | |
59 | } | |
60 | return p.recvSum() | |
61 | } | |
62 | ||
63 | func (p *AddServiceClient) sendSum(a int64, b int64) (err error) { | |
64 | oprot := p.OutputProtocol | |
65 | if oprot == nil { | |
66 | oprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
67 | p.OutputProtocol = oprot | |
68 | } | |
69 | p.SeqId++ | |
70 | if err = oprot.WriteMessageBegin("Sum", thrift.CALL, p.SeqId); err != nil { | |
71 | return | |
72 | } | |
73 | args := SumArgs{ | |
74 | A: a, | |
75 | B: b, | |
76 | } | |
77 | if err = args.Write(oprot); err != nil { | |
78 | return | |
79 | } | |
80 | if err = oprot.WriteMessageEnd(); err != nil { | |
81 | return | |
82 | } | |
83 | return oprot.Flush() | |
84 | } | |
85 | ||
86 | func (p *AddServiceClient) recvSum() (value *SumReply, err error) { | |
87 | iprot := p.InputProtocol | |
88 | if iprot == nil { | |
89 | iprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
90 | p.InputProtocol = iprot | |
91 | } | |
92 | _, mTypeId, seqId, err := iprot.ReadMessageBegin() | |
93 | if err != nil { | |
94 | return | |
95 | } | |
96 | if mTypeId == thrift.EXCEPTION { | |
97 | error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") | |
98 | var error1 error | |
99 | error1, err = error0.Read(iprot) | |
100 | if err != nil { | |
101 | return | |
102 | } | |
103 | if err = iprot.ReadMessageEnd(); err != nil { | |
104 | return | |
105 | } | |
106 | err = error1 | |
107 | return | |
108 | } | |
109 | if p.SeqId != seqId { | |
110 | err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Sum failed: out of sequence response") | |
111 | return | |
112 | } | |
113 | result := SumResult{} | |
114 | if err = result.Read(iprot); err != nil { | |
115 | return | |
116 | } | |
117 | if err = iprot.ReadMessageEnd(); err != nil { | |
118 | return | |
119 | } | |
120 | value = result.GetSuccess() | |
121 | return | |
122 | } | |
123 | ||
124 | // Parameters: | |
125 | // - A | |
126 | // - B | |
127 | func (p *AddServiceClient) Concat(a string, b string) (r *ConcatReply, err error) { | |
128 | if err = p.sendConcat(a, b); err != nil { | |
129 | return | |
130 | } | |
131 | return p.recvConcat() | |
132 | } | |
133 | ||
134 | func (p *AddServiceClient) sendConcat(a string, b string) (err error) { | |
135 | oprot := p.OutputProtocol | |
136 | if oprot == nil { | |
137 | oprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
138 | p.OutputProtocol = oprot | |
139 | } | |
140 | p.SeqId++ | |
141 | if err = oprot.WriteMessageBegin("Concat", thrift.CALL, p.SeqId); err != nil { | |
142 | return | |
143 | } | |
144 | args := ConcatArgs{ | |
145 | A: a, | |
146 | B: b, | |
147 | } | |
148 | if err = args.Write(oprot); err != nil { | |
149 | return | |
150 | } | |
151 | if err = oprot.WriteMessageEnd(); err != nil { | |
152 | return | |
153 | } | |
154 | return oprot.Flush() | |
155 | } | |
156 | ||
157 | func (p *AddServiceClient) recvConcat() (value *ConcatReply, err error) { | |
158 | iprot := p.InputProtocol | |
159 | if iprot == nil { | |
160 | iprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
161 | p.InputProtocol = iprot | |
162 | } | |
163 | _, mTypeId, seqId, err := iprot.ReadMessageBegin() | |
164 | if err != nil { | |
165 | return | |
166 | } | |
167 | if mTypeId == thrift.EXCEPTION { | |
168 | error2 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") | |
169 | var error3 error | |
170 | error3, err = error2.Read(iprot) | |
171 | if err != nil { | |
172 | return | |
173 | } | |
174 | if err = iprot.ReadMessageEnd(); err != nil { | |
175 | return | |
176 | } | |
177 | err = error3 | |
178 | return | |
179 | } | |
180 | if p.SeqId != seqId { | |
181 | err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Concat failed: out of sequence response") | |
182 | return | |
183 | } | |
184 | result := ConcatResult{} | |
185 | if err = result.Read(iprot); err != nil { | |
186 | return | |
187 | } | |
188 | if err = iprot.ReadMessageEnd(); err != nil { | |
189 | return | |
190 | } | |
191 | value = result.GetSuccess() | |
192 | return | |
193 | } | |
194 | ||
195 | type AddServiceProcessor struct { | |
196 | processorMap map[string]thrift.TProcessorFunction | |
197 | handler AddService | |
198 | } | |
199 | ||
200 | func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { | |
201 | p.processorMap[key] = processor | |
202 | } | |
203 | ||
204 | func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { | |
205 | processor, ok = p.processorMap[key] | |
206 | return processor, ok | |
207 | } | |
208 | ||
209 | func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { | |
210 | return p.processorMap | |
211 | } | |
212 | ||
213 | func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { | |
214 | ||
215 | self4 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} | |
216 | self4.processorMap["Sum"] = &addServiceProcessorSum{handler: handler} | |
217 | self4.processorMap["Concat"] = &addServiceProcessorConcat{handler: handler} | |
218 | return self4 | |
219 | } | |
220 | ||
221 | func (p *AddServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
222 | name, _, seqId, err := iprot.ReadMessageBegin() | |
223 | if err != nil { | |
224 | return false, err | |
225 | } | |
226 | if processor, ok := p.GetProcessorFunction(name); ok { | |
227 | return processor.Process(seqId, iprot, oprot) | |
228 | } | |
229 | iprot.Skip(thrift.STRUCT) | |
230 | iprot.ReadMessageEnd() | |
231 | x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) | |
232 | oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) | |
233 | x5.Write(oprot) | |
234 | oprot.WriteMessageEnd() | |
235 | oprot.Flush() | |
236 | return false, x5 | |
237 | ||
238 | } | |
239 | ||
240 | type addServiceProcessorSum struct { | |
241 | handler AddService | |
242 | } | |
243 | ||
244 | func (p *addServiceProcessorSum) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
245 | args := SumArgs{} | |
246 | if err = args.Read(iprot); err != nil { | |
247 | iprot.ReadMessageEnd() | |
248 | x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) | |
249 | oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) | |
250 | x.Write(oprot) | |
251 | oprot.WriteMessageEnd() | |
252 | oprot.Flush() | |
253 | return false, err | |
254 | } | |
255 | ||
256 | iprot.ReadMessageEnd() | |
257 | result := SumResult{} | |
258 | var retval *SumReply | |
259 | var err2 error | |
260 | if retval, err2 = p.handler.Sum(args.A, args.B); err2 != nil { | |
261 | x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Sum: "+err2.Error()) | |
262 | oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) | |
263 | x.Write(oprot) | |
264 | oprot.WriteMessageEnd() | |
265 | oprot.Flush() | |
266 | return true, err2 | |
267 | } else { | |
268 | result.Success = retval | |
269 | } | |
270 | if err2 = oprot.WriteMessageBegin("Sum", thrift.REPLY, seqId); err2 != nil { | |
271 | err = err2 | |
272 | } | |
273 | if err2 = result.Write(oprot); err == nil && err2 != nil { | |
274 | err = err2 | |
275 | } | |
276 | if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { | |
277 | err = err2 | |
278 | } | |
279 | if err2 = oprot.Flush(); err == nil && err2 != nil { | |
280 | err = err2 | |
281 | } | |
282 | if err != nil { | |
283 | return | |
284 | } | |
285 | return true, err | |
286 | } | |
287 | ||
288 | type addServiceProcessorConcat struct { | |
289 | handler AddService | |
290 | } | |
291 | ||
292 | func (p *addServiceProcessorConcat) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
293 | args := ConcatArgs{} | |
294 | if err = args.Read(iprot); err != nil { | |
295 | iprot.ReadMessageEnd() | |
296 | x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) | |
297 | oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) | |
298 | x.Write(oprot) | |
299 | oprot.WriteMessageEnd() | |
300 | oprot.Flush() | |
301 | return false, err | |
302 | } | |
303 | ||
304 | iprot.ReadMessageEnd() | |
305 | result := ConcatResult{} | |
306 | var retval *ConcatReply | |
307 | var err2 error | |
308 | if retval, err2 = p.handler.Concat(args.A, args.B); err2 != nil { | |
309 | x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Concat: "+err2.Error()) | |
310 | oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) | |
311 | x.Write(oprot) | |
312 | oprot.WriteMessageEnd() | |
313 | oprot.Flush() | |
314 | return true, err2 | |
315 | } else { | |
316 | result.Success = retval | |
317 | } | |
318 | if err2 = oprot.WriteMessageBegin("Concat", thrift.REPLY, seqId); err2 != nil { | |
319 | err = err2 | |
320 | } | |
321 | if err2 = result.Write(oprot); err == nil && err2 != nil { | |
322 | err = err2 | |
323 | } | |
324 | if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { | |
325 | err = err2 | |
326 | } | |
327 | if err2 = oprot.Flush(); err == nil && err2 != nil { | |
328 | err = err2 | |
329 | } | |
330 | if err != nil { | |
331 | return | |
332 | } | |
333 | return true, err | |
334 | } | |
335 | ||
336 | // HELPER FUNCTIONS AND STRUCTURES | |
337 | ||
338 | type SumArgs struct { | |
339 | A int64 `thrift:"a,1" json:"a"` | |
340 | B int64 `thrift:"b,2" json:"b"` | |
341 | } | |
342 | ||
343 | func NewSumArgs() *SumArgs { | |
344 | return &SumArgs{} | |
345 | } | |
346 | ||
347 | func (p *SumArgs) GetA() int64 { | |
348 | return p.A | |
349 | } | |
350 | ||
351 | func (p *SumArgs) GetB() int64 { | |
352 | return p.B | |
353 | } | |
354 | func (p *SumArgs) Read(iprot thrift.TProtocol) error { | |
355 | if _, err := iprot.ReadStructBegin(); err != nil { | |
356 | return fmt.Errorf("%T read error: %s", p, err) | |
357 | } | |
358 | for { | |
359 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
360 | if err != nil { | |
361 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
362 | } | |
363 | if fieldTypeId == thrift.STOP { | |
364 | break | |
365 | } | |
366 | switch fieldId { | |
367 | case 1: | |
368 | if err := p.ReadField1(iprot); err != nil { | |
369 | return err | |
370 | } | |
371 | case 2: | |
372 | if err := p.ReadField2(iprot); err != nil { | |
373 | return err | |
374 | } | |
375 | default: | |
376 | if err := iprot.Skip(fieldTypeId); err != nil { | |
377 | return err | |
378 | } | |
379 | } | |
380 | if err := iprot.ReadFieldEnd(); err != nil { | |
381 | return err | |
382 | } | |
383 | } | |
384 | if err := iprot.ReadStructEnd(); err != nil { | |
385 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
386 | } | |
387 | return nil | |
388 | } | |
389 | ||
390 | func (p *SumArgs) ReadField1(iprot thrift.TProtocol) error { | |
391 | if v, err := iprot.ReadI64(); err != nil { | |
392 | return fmt.Errorf("error reading field 1: %s", err) | |
393 | } else { | |
394 | p.A = v | |
395 | } | |
396 | return nil | |
397 | } | |
398 | ||
399 | func (p *SumArgs) ReadField2(iprot thrift.TProtocol) error { | |
400 | if v, err := iprot.ReadI64(); err != nil { | |
401 | return fmt.Errorf("error reading field 2: %s", err) | |
402 | } else { | |
403 | p.B = v | |
404 | } | |
405 | return nil | |
406 | } | |
407 | ||
408 | func (p *SumArgs) Write(oprot thrift.TProtocol) error { | |
409 | if err := oprot.WriteStructBegin("Sum_args"); err != nil { | |
410 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
411 | } | |
412 | if err := p.writeField1(oprot); err != nil { | |
413 | return err | |
414 | } | |
415 | if err := p.writeField2(oprot); err != nil { | |
416 | return err | |
417 | } | |
418 | if err := oprot.WriteFieldStop(); err != nil { | |
419 | return fmt.Errorf("write field stop error: %s", err) | |
420 | } | |
421 | if err := oprot.WriteStructEnd(); err != nil { | |
422 | return fmt.Errorf("write struct stop error: %s", err) | |
423 | } | |
424 | return nil | |
425 | } | |
426 | ||
427 | func (p *SumArgs) writeField1(oprot thrift.TProtocol) (err error) { | |
428 | if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { | |
429 | return fmt.Errorf("%T write field begin error 1:a: %s", p, err) | |
430 | } | |
431 | if err := oprot.WriteI64(int64(p.A)); err != nil { | |
432 | return fmt.Errorf("%T.a (1) field write error: %s", p, err) | |
433 | } | |
434 | if err := oprot.WriteFieldEnd(); err != nil { | |
435 | return fmt.Errorf("%T write field end error 1:a: %s", p, err) | |
436 | } | |
437 | return err | |
438 | } | |
439 | ||
440 | func (p *SumArgs) writeField2(oprot thrift.TProtocol) (err error) { | |
441 | if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { | |
442 | return fmt.Errorf("%T write field begin error 2:b: %s", p, err) | |
443 | } | |
444 | if err := oprot.WriteI64(int64(p.B)); err != nil { | |
445 | return fmt.Errorf("%T.b (2) field write error: %s", p, err) | |
446 | } | |
447 | if err := oprot.WriteFieldEnd(); err != nil { | |
448 | return fmt.Errorf("%T write field end error 2:b: %s", p, err) | |
449 | } | |
450 | return err | |
451 | } | |
452 | ||
453 | func (p *SumArgs) String() string { | |
454 | if p == nil { | |
455 | return "<nil>" | |
456 | } | |
457 | return fmt.Sprintf("SumArgs(%+v)", *p) | |
458 | } | |
459 | ||
460 | type SumResult struct { | |
461 | Success *SumReply `thrift:"success,0" json:"success"` | |
462 | } | |
463 | ||
464 | func NewSumResult() *SumResult { | |
465 | return &SumResult{} | |
466 | } | |
467 | ||
468 | var SumResult_Success_DEFAULT *SumReply | |
469 | ||
470 | func (p *SumResult) GetSuccess() *SumReply { | |
471 | if !p.IsSetSuccess() { | |
472 | return SumResult_Success_DEFAULT | |
473 | } | |
474 | return p.Success | |
475 | } | |
476 | func (p *SumResult) IsSetSuccess() bool { | |
477 | return p.Success != nil | |
478 | } | |
479 | ||
480 | func (p *SumResult) Read(iprot thrift.TProtocol) error { | |
481 | if _, err := iprot.ReadStructBegin(); err != nil { | |
482 | return fmt.Errorf("%T read error: %s", p, err) | |
483 | } | |
484 | for { | |
485 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
486 | if err != nil { | |
487 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
488 | } | |
489 | if fieldTypeId == thrift.STOP { | |
490 | break | |
491 | } | |
492 | switch fieldId { | |
493 | case 0: | |
494 | if err := p.ReadField0(iprot); err != nil { | |
495 | return err | |
496 | } | |
497 | default: | |
498 | if err := iprot.Skip(fieldTypeId); err != nil { | |
499 | return err | |
500 | } | |
501 | } | |
502 | if err := iprot.ReadFieldEnd(); err != nil { | |
503 | return err | |
504 | } | |
505 | } | |
506 | if err := iprot.ReadStructEnd(); err != nil { | |
507 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
508 | } | |
509 | return nil | |
510 | } | |
511 | ||
512 | func (p *SumResult) ReadField0(iprot thrift.TProtocol) error { | |
513 | p.Success = &SumReply{} | |
514 | if err := p.Success.Read(iprot); err != nil { | |
515 | return fmt.Errorf("%T error reading struct: %s", p.Success, err) | |
516 | } | |
517 | return nil | |
518 | } | |
519 | ||
520 | func (p *SumResult) Write(oprot thrift.TProtocol) error { | |
521 | if err := oprot.WriteStructBegin("Sum_result"); err != nil { | |
522 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
523 | } | |
524 | if err := p.writeField0(oprot); err != nil { | |
525 | return err | |
526 | } | |
527 | if err := oprot.WriteFieldStop(); err != nil { | |
528 | return fmt.Errorf("write field stop error: %s", err) | |
529 | } | |
530 | if err := oprot.WriteStructEnd(); err != nil { | |
531 | return fmt.Errorf("write struct stop error: %s", err) | |
532 | } | |
533 | return nil | |
534 | } | |
535 | ||
536 | func (p *SumResult) writeField0(oprot thrift.TProtocol) (err error) { | |
537 | if p.IsSetSuccess() { | |
538 | if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { | |
539 | return fmt.Errorf("%T write field begin error 0:success: %s", p, err) | |
540 | } | |
541 | if err := p.Success.Write(oprot); err != nil { | |
542 | return fmt.Errorf("%T error writing struct: %s", p.Success, err) | |
543 | } | |
544 | if err := oprot.WriteFieldEnd(); err != nil { | |
545 | return fmt.Errorf("%T write field end error 0:success: %s", p, err) | |
546 | } | |
547 | } | |
548 | return err | |
549 | } | |
550 | ||
551 | func (p *SumResult) String() string { | |
552 | if p == nil { | |
553 | return "<nil>" | |
554 | } | |
555 | return fmt.Sprintf("SumResult(%+v)", *p) | |
556 | } | |
557 | ||
558 | type ConcatArgs struct { | |
559 | A string `thrift:"a,1" json:"a"` | |
560 | B string `thrift:"b,2" json:"b"` | |
561 | } | |
562 | ||
563 | func NewConcatArgs() *ConcatArgs { | |
564 | return &ConcatArgs{} | |
565 | } | |
566 | ||
567 | func (p *ConcatArgs) GetA() string { | |
568 | return p.A | |
569 | } | |
570 | ||
571 | func (p *ConcatArgs) GetB() string { | |
572 | return p.B | |
573 | } | |
574 | func (p *ConcatArgs) Read(iprot thrift.TProtocol) error { | |
575 | if _, err := iprot.ReadStructBegin(); err != nil { | |
576 | return fmt.Errorf("%T read error: %s", p, err) | |
577 | } | |
578 | for { | |
579 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
580 | if err != nil { | |
581 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
582 | } | |
583 | if fieldTypeId == thrift.STOP { | |
584 | break | |
585 | } | |
586 | switch fieldId { | |
587 | case 1: | |
588 | if err := p.ReadField1(iprot); err != nil { | |
589 | return err | |
590 | } | |
591 | case 2: | |
592 | if err := p.ReadField2(iprot); err != nil { | |
593 | return err | |
594 | } | |
595 | default: | |
596 | if err := iprot.Skip(fieldTypeId); err != nil { | |
597 | return err | |
598 | } | |
599 | } | |
600 | if err := iprot.ReadFieldEnd(); err != nil { | |
601 | return err | |
602 | } | |
603 | } | |
604 | if err := iprot.ReadStructEnd(); err != nil { | |
605 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
606 | } | |
607 | return nil | |
608 | } | |
609 | ||
610 | func (p *ConcatArgs) ReadField1(iprot thrift.TProtocol) error { | |
611 | if v, err := iprot.ReadString(); err != nil { | |
612 | return fmt.Errorf("error reading field 1: %s", err) | |
613 | } else { | |
614 | p.A = v | |
615 | } | |
616 | return nil | |
617 | } | |
618 | ||
619 | func (p *ConcatArgs) ReadField2(iprot thrift.TProtocol) error { | |
620 | if v, err := iprot.ReadString(); err != nil { | |
621 | return fmt.Errorf("error reading field 2: %s", err) | |
622 | } else { | |
623 | p.B = v | |
624 | } | |
625 | return nil | |
626 | } | |
627 | ||
628 | func (p *ConcatArgs) Write(oprot thrift.TProtocol) error { | |
629 | if err := oprot.WriteStructBegin("Concat_args"); err != nil { | |
630 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
631 | } | |
632 | if err := p.writeField1(oprot); err != nil { | |
633 | return err | |
634 | } | |
635 | if err := p.writeField2(oprot); err != nil { | |
636 | return err | |
637 | } | |
638 | if err := oprot.WriteFieldStop(); err != nil { | |
639 | return fmt.Errorf("write field stop error: %s", err) | |
640 | } | |
641 | if err := oprot.WriteStructEnd(); err != nil { | |
642 | return fmt.Errorf("write struct stop error: %s", err) | |
643 | } | |
644 | return nil | |
645 | } | |
646 | ||
647 | func (p *ConcatArgs) writeField1(oprot thrift.TProtocol) (err error) { | |
648 | if err := oprot.WriteFieldBegin("a", thrift.STRING, 1); err != nil { | |
649 | return fmt.Errorf("%T write field begin error 1:a: %s", p, err) | |
650 | } | |
651 | if err := oprot.WriteString(string(p.A)); err != nil { | |
652 | return fmt.Errorf("%T.a (1) field write error: %s", p, err) | |
653 | } | |
654 | if err := oprot.WriteFieldEnd(); err != nil { | |
655 | return fmt.Errorf("%T write field end error 1:a: %s", p, err) | |
656 | } | |
657 | return err | |
658 | } | |
659 | ||
660 | func (p *ConcatArgs) writeField2(oprot thrift.TProtocol) (err error) { | |
661 | if err := oprot.WriteFieldBegin("b", thrift.STRING, 2); err != nil { | |
662 | return fmt.Errorf("%T write field begin error 2:b: %s", p, err) | |
663 | } | |
664 | if err := oprot.WriteString(string(p.B)); err != nil { | |
665 | return fmt.Errorf("%T.b (2) field write error: %s", p, err) | |
666 | } | |
667 | if err := oprot.WriteFieldEnd(); err != nil { | |
668 | return fmt.Errorf("%T write field end error 2:b: %s", p, err) | |
669 | } | |
670 | return err | |
671 | } | |
672 | ||
673 | func (p *ConcatArgs) String() string { | |
674 | if p == nil { | |
675 | return "<nil>" | |
676 | } | |
677 | return fmt.Sprintf("ConcatArgs(%+v)", *p) | |
678 | } | |
679 | ||
680 | type ConcatResult struct { | |
681 | Success *ConcatReply `thrift:"success,0" json:"success"` | |
682 | } | |
683 | ||
684 | func NewConcatResult() *ConcatResult { | |
685 | return &ConcatResult{} | |
686 | } | |
687 | ||
688 | var ConcatResult_Success_DEFAULT *ConcatReply | |
689 | ||
690 | func (p *ConcatResult) GetSuccess() *ConcatReply { | |
691 | if !p.IsSetSuccess() { | |
692 | return ConcatResult_Success_DEFAULT | |
693 | } | |
694 | return p.Success | |
695 | } | |
696 | func (p *ConcatResult) IsSetSuccess() bool { | |
697 | return p.Success != nil | |
698 | } | |
699 | ||
700 | func (p *ConcatResult) Read(iprot thrift.TProtocol) error { | |
701 | if _, err := iprot.ReadStructBegin(); err != nil { | |
702 | return fmt.Errorf("%T read error: %s", p, err) | |
703 | } | |
704 | for { | |
705 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
706 | if err != nil { | |
707 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
708 | } | |
709 | if fieldTypeId == thrift.STOP { | |
710 | break | |
711 | } | |
712 | switch fieldId { | |
713 | case 0: | |
714 | if err := p.ReadField0(iprot); err != nil { | |
715 | return err | |
716 | } | |
717 | default: | |
718 | if err := iprot.Skip(fieldTypeId); err != nil { | |
719 | return err | |
720 | } | |
721 | } | |
722 | if err := iprot.ReadFieldEnd(); err != nil { | |
723 | return err | |
724 | } | |
725 | } | |
726 | if err := iprot.ReadStructEnd(); err != nil { | |
727 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
728 | } | |
729 | return nil | |
730 | } | |
731 | ||
732 | func (p *ConcatResult) ReadField0(iprot thrift.TProtocol) error { | |
733 | p.Success = &ConcatReply{} | |
734 | if err := p.Success.Read(iprot); err != nil { | |
735 | return fmt.Errorf("%T error reading struct: %s", p.Success, err) | |
736 | } | |
737 | return nil | |
738 | } | |
739 | ||
740 | func (p *ConcatResult) Write(oprot thrift.TProtocol) error { | |
741 | if err := oprot.WriteStructBegin("Concat_result"); err != nil { | |
742 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
743 | } | |
744 | if err := p.writeField0(oprot); err != nil { | |
745 | return err | |
746 | } | |
747 | if err := oprot.WriteFieldStop(); err != nil { | |
748 | return fmt.Errorf("write field stop error: %s", err) | |
749 | } | |
750 | if err := oprot.WriteStructEnd(); err != nil { | |
751 | return fmt.Errorf("write struct stop error: %s", err) | |
752 | } | |
753 | return nil | |
754 | } | |
755 | ||
756 | func (p *ConcatResult) writeField0(oprot thrift.TProtocol) (err error) { | |
757 | if p.IsSetSuccess() { | |
758 | if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { | |
759 | return fmt.Errorf("%T write field begin error 0:success: %s", p, err) | |
760 | } | |
761 | if err := p.Success.Write(oprot); err != nil { | |
762 | return fmt.Errorf("%T error writing struct: %s", p.Success, err) | |
763 | } | |
764 | if err := oprot.WriteFieldEnd(); err != nil { | |
765 | return fmt.Errorf("%T write field end error 0:success: %s", p, err) | |
766 | } | |
767 | } | |
768 | return err | |
769 | } | |
770 | ||
771 | func (p *ConcatResult) String() string { | |
772 | if p == nil { | |
773 | return "<nil>" | |
774 | } | |
775 | return fmt.Sprintf("ConcatResult(%+v)", *p) | |
776 | } |
0 | // Autogenerated by Thrift Compiler (0.9.2) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | func init() { | |
17 | } |
0 | // Autogenerated by Thrift Compiler (0.9.2) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | var GoUnusedProtection__ int | |
17 | ||
18 | type SumReply struct { | |
19 | Value int64 `thrift:"value,1" json:"value"` | |
20 | } | |
21 | ||
22 | func NewSumReply() *SumReply { | |
23 | return &SumReply{} | |
24 | } | |
25 | ||
26 | func (p *SumReply) GetValue() int64 { | |
27 | return p.Value | |
28 | } | |
29 | func (p *SumReply) Read(iprot thrift.TProtocol) error { | |
30 | if _, err := iprot.ReadStructBegin(); err != nil { | |
31 | return fmt.Errorf("%T read error: %s", p, err) | |
32 | } | |
33 | for { | |
34 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
35 | if err != nil { | |
36 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
37 | } | |
38 | if fieldTypeId == thrift.STOP { | |
39 | break | |
40 | } | |
41 | switch fieldId { | |
42 | case 1: | |
43 | if err := p.ReadField1(iprot); err != nil { | |
44 | return err | |
45 | } | |
46 | default: | |
47 | if err := iprot.Skip(fieldTypeId); err != nil { | |
48 | return err | |
49 | } | |
50 | } | |
51 | if err := iprot.ReadFieldEnd(); err != nil { | |
52 | return err | |
53 | } | |
54 | } | |
55 | if err := iprot.ReadStructEnd(); err != nil { | |
56 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
57 | } | |
58 | return nil | |
59 | } | |
60 | ||
61 | func (p *SumReply) ReadField1(iprot thrift.TProtocol) error { | |
62 | if v, err := iprot.ReadI64(); err != nil { | |
63 | return fmt.Errorf("error reading field 1: %s", err) | |
64 | } else { | |
65 | p.Value = v | |
66 | } | |
67 | return nil | |
68 | } | |
69 | ||
70 | func (p *SumReply) Write(oprot thrift.TProtocol) error { | |
71 | if err := oprot.WriteStructBegin("SumReply"); err != nil { | |
72 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
73 | } | |
74 | if err := p.writeField1(oprot); err != nil { | |
75 | return err | |
76 | } | |
77 | if err := oprot.WriteFieldStop(); err != nil { | |
78 | return fmt.Errorf("write field stop error: %s", err) | |
79 | } | |
80 | if err := oprot.WriteStructEnd(); err != nil { | |
81 | return fmt.Errorf("write struct stop error: %s", err) | |
82 | } | |
83 | return nil | |
84 | } | |
85 | ||
86 | func (p *SumReply) writeField1(oprot thrift.TProtocol) (err error) { | |
87 | if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { | |
88 | return fmt.Errorf("%T write field begin error 1:value: %s", p, err) | |
89 | } | |
90 | if err := oprot.WriteI64(int64(p.Value)); err != nil { | |
91 | return fmt.Errorf("%T.value (1) field write error: %s", p, err) | |
92 | } | |
93 | if err := oprot.WriteFieldEnd(); err != nil { | |
94 | return fmt.Errorf("%T write field end error 1:value: %s", p, err) | |
95 | } | |
96 | return err | |
97 | } | |
98 | ||
99 | func (p *SumReply) String() string { | |
100 | if p == nil { | |
101 | return "<nil>" | |
102 | } | |
103 | return fmt.Sprintf("SumReply(%+v)", *p) | |
104 | } | |
105 | ||
106 | type ConcatReply struct { | |
107 | Value string `thrift:"value,1" json:"value"` | |
108 | } | |
109 | ||
110 | func NewConcatReply() *ConcatReply { | |
111 | return &ConcatReply{} | |
112 | } | |
113 | ||
114 | func (p *ConcatReply) GetValue() string { | |
115 | return p.Value | |
116 | } | |
117 | func (p *ConcatReply) Read(iprot thrift.TProtocol) error { | |
118 | if _, err := iprot.ReadStructBegin(); err != nil { | |
119 | return fmt.Errorf("%T read error: %s", p, err) | |
120 | } | |
121 | for { | |
122 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
123 | if err != nil { | |
124 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) | |
125 | } | |
126 | if fieldTypeId == thrift.STOP { | |
127 | break | |
128 | } | |
129 | switch fieldId { | |
130 | case 1: | |
131 | if err := p.ReadField1(iprot); err != nil { | |
132 | return err | |
133 | } | |
134 | default: | |
135 | if err := iprot.Skip(fieldTypeId); err != nil { | |
136 | return err | |
137 | } | |
138 | } | |
139 | if err := iprot.ReadFieldEnd(); err != nil { | |
140 | return err | |
141 | } | |
142 | } | |
143 | if err := iprot.ReadStructEnd(); err != nil { | |
144 | return fmt.Errorf("%T read struct end error: %s", p, err) | |
145 | } | |
146 | return nil | |
147 | } | |
148 | ||
149 | func (p *ConcatReply) ReadField1(iprot thrift.TProtocol) error { | |
150 | if v, err := iprot.ReadString(); err != nil { | |
151 | return fmt.Errorf("error reading field 1: %s", err) | |
152 | } else { | |
153 | p.Value = v | |
154 | } | |
155 | return nil | |
156 | } | |
157 | ||
158 | func (p *ConcatReply) Write(oprot thrift.TProtocol) error { | |
159 | if err := oprot.WriteStructBegin("ConcatReply"); err != nil { | |
160 | return fmt.Errorf("%T write struct begin error: %s", p, err) | |
161 | } | |
162 | if err := p.writeField1(oprot); err != nil { | |
163 | return err | |
164 | } | |
165 | if err := oprot.WriteFieldStop(); err != nil { | |
166 | return fmt.Errorf("write field stop error: %s", err) | |
167 | } | |
168 | if err := oprot.WriteStructEnd(); err != nil { | |
169 | return fmt.Errorf("write struct stop error: %s", err) | |
170 | } | |
171 | return nil | |
172 | } | |
173 | ||
174 | func (p *ConcatReply) writeField1(oprot thrift.TProtocol) (err error) { | |
175 | if err := oprot.WriteFieldBegin("value", thrift.STRING, 1); err != nil { | |
176 | return fmt.Errorf("%T write field begin error 1:value: %s", p, err) | |
177 | } | |
178 | if err := oprot.WriteString(string(p.Value)); err != nil { | |
179 | return fmt.Errorf("%T.value (1) field write error: %s", p, err) | |
180 | } | |
181 | if err := oprot.WriteFieldEnd(); err != nil { | |
182 | return fmt.Errorf("%T write field end error 1:value: %s", p, err) | |
183 | } | |
184 | return err | |
185 | } | |
186 | ||
187 | func (p *ConcatReply) String() string { | |
188 | if p == nil { | |
189 | return "<nil>" | |
190 | } | |
191 | return fmt.Sprintf("ConcatReply(%+v)", *p) | |
192 | } |
0 | struct SumReply { | |
1 | 1: i64 value | |
2 | } | |
3 | ||
4 | struct ConcatReply { | |
5 | 1: string value | |
6 | } | |
7 | ||
8 | service AddService { | |
9 | SumReply Sum(1: i64 a, 2: i64 b) | |
10 | ConcatReply Concat(1: string a, 2: string b) | |
11 | } |
0 | #!/usr/bin/env sh | |
1 | ||
2 | # See also https://thrift.apache.org/tutorial/go | |
3 | ||
4 | thrift -r --gen "go:package_prefix=github.com/go-kit/kit/examples/addsvc/thrift/gen-go/,thrift_import=github.com/apache/thrift/lib/go/thrift" add.thrift |
0 | // Autogenerated by Thrift Compiler (0.9.3) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package main | |
4 | ||
5 | import ( | |
6 | "flag" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/add" | |
10 | "math" | |
11 | "net" | |
12 | "net/url" | |
13 | "os" | |
14 | "strconv" | |
15 | "strings" | |
16 | ) | |
17 | ||
18 | func Usage() { | |
19 | fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") | |
20 | flag.PrintDefaults() | |
21 | fmt.Fprintln(os.Stderr, "\nFunctions:") | |
22 | fmt.Fprintln(os.Stderr, " SumReply Sum(i64 a, i64 b)") | |
23 | fmt.Fprintln(os.Stderr, " ConcatReply Concat(string a, string b)") | |
24 | fmt.Fprintln(os.Stderr) | |
25 | os.Exit(0) | |
26 | } | |
27 | ||
28 | func main() { | |
29 | flag.Usage = Usage | |
30 | var host string | |
31 | var port int | |
32 | var protocol string | |
33 | var urlString string | |
34 | var framed bool | |
35 | var useHttp bool | |
36 | var parsedUrl url.URL | |
37 | var trans thrift.TTransport | |
38 | _ = strconv.Atoi | |
39 | _ = math.Abs | |
40 | flag.Usage = Usage | |
41 | flag.StringVar(&host, "h", "localhost", "Specify host and port") | |
42 | flag.IntVar(&port, "p", 9090, "Specify port") | |
43 | flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") | |
44 | flag.StringVar(&urlString, "u", "", "Specify the url") | |
45 | flag.BoolVar(&framed, "framed", false, "Use framed transport") | |
46 | flag.BoolVar(&useHttp, "http", false, "Use http") | |
47 | flag.Parse() | |
48 | ||
49 | if len(urlString) > 0 { | |
50 | parsedUrl, err := url.Parse(urlString) | |
51 | if err != nil { | |
52 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) | |
53 | flag.Usage() | |
54 | } | |
55 | host = parsedUrl.Host | |
56 | useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" | |
57 | } else if useHttp { | |
58 | _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) | |
59 | if err != nil { | |
60 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) | |
61 | flag.Usage() | |
62 | } | |
63 | } | |
64 | ||
65 | cmd := flag.Arg(0) | |
66 | var err error | |
67 | if useHttp { | |
68 | trans, err = thrift.NewTHttpClient(parsedUrl.String()) | |
69 | } else { | |
70 | portStr := fmt.Sprint(port) | |
71 | if strings.Contains(host, ":") { | |
72 | host, portStr, err = net.SplitHostPort(host) | |
73 | if err != nil { | |
74 | fmt.Fprintln(os.Stderr, "error with host:", err) | |
75 | os.Exit(1) | |
76 | } | |
77 | } | |
78 | trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) | |
79 | if err != nil { | |
80 | fmt.Fprintln(os.Stderr, "error resolving address:", err) | |
81 | os.Exit(1) | |
82 | } | |
83 | if framed { | |
84 | trans = thrift.NewTFramedTransport(trans) | |
85 | } | |
86 | } | |
87 | if err != nil { | |
88 | fmt.Fprintln(os.Stderr, "Error creating transport", err) | |
89 | os.Exit(1) | |
90 | } | |
91 | defer trans.Close() | |
92 | var protocolFactory thrift.TProtocolFactory | |
93 | switch protocol { | |
94 | case "compact": | |
95 | protocolFactory = thrift.NewTCompactProtocolFactory() | |
96 | break | |
97 | case "simplejson": | |
98 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() | |
99 | break | |
100 | case "json": | |
101 | protocolFactory = thrift.NewTJSONProtocolFactory() | |
102 | break | |
103 | case "binary", "": | |
104 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() | |
105 | break | |
106 | default: | |
107 | fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) | |
108 | Usage() | |
109 | os.Exit(1) | |
110 | } | |
111 | client := add.NewAddServiceClientFactory(trans, protocolFactory) | |
112 | if err := trans.Open(); err != nil { | |
113 | fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) | |
114 | os.Exit(1) | |
115 | } | |
116 | ||
117 | switch cmd { | |
118 | case "Sum": | |
119 | if flag.NArg()-1 != 2 { | |
120 | fmt.Fprintln(os.Stderr, "Sum requires 2 args") | |
121 | flag.Usage() | |
122 | } | |
123 | argvalue0, err6 := (strconv.ParseInt(flag.Arg(1), 10, 64)) | |
124 | if err6 != nil { | |
125 | Usage() | |
126 | return | |
127 | } | |
128 | value0 := argvalue0 | |
129 | argvalue1, err7 := (strconv.ParseInt(flag.Arg(2), 10, 64)) | |
130 | if err7 != nil { | |
131 | Usage() | |
132 | return | |
133 | } | |
134 | value1 := argvalue1 | |
135 | fmt.Print(client.Sum(value0, value1)) | |
136 | fmt.Print("\n") | |
137 | break | |
138 | case "Concat": | |
139 | if flag.NArg()-1 != 2 { | |
140 | fmt.Fprintln(os.Stderr, "Concat requires 2 args") | |
141 | flag.Usage() | |
142 | } | |
143 | argvalue0 := flag.Arg(1) | |
144 | value0 := argvalue0 | |
145 | argvalue1 := flag.Arg(2) | |
146 | value1 := argvalue1 | |
147 | fmt.Print(client.Concat(value0, value1)) | |
148 | fmt.Print("\n") | |
149 | break | |
150 | case "": | |
151 | Usage() | |
152 | break | |
153 | default: | |
154 | fmt.Fprintln(os.Stderr, "Invalid function ", cmd) | |
155 | } | |
156 | } |
0 | // Autogenerated by Thrift Compiler (0.9.3) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | type AddService interface { | |
17 | // Parameters: | |
18 | // - A | |
19 | // - B | |
20 | Sum(a int64, b int64) (r *SumReply, err error) | |
21 | // Parameters: | |
22 | // - A | |
23 | // - B | |
24 | Concat(a string, b string) (r *ConcatReply, err error) | |
25 | } | |
26 | ||
27 | type AddServiceClient struct { | |
28 | Transport thrift.TTransport | |
29 | ProtocolFactory thrift.TProtocolFactory | |
30 | InputProtocol thrift.TProtocol | |
31 | OutputProtocol thrift.TProtocol | |
32 | SeqId int32 | |
33 | } | |
34 | ||
35 | func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { | |
36 | return &AddServiceClient{Transport: t, | |
37 | ProtocolFactory: f, | |
38 | InputProtocol: f.GetProtocol(t), | |
39 | OutputProtocol: f.GetProtocol(t), | |
40 | SeqId: 0, | |
41 | } | |
42 | } | |
43 | ||
44 | func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { | |
45 | return &AddServiceClient{Transport: t, | |
46 | ProtocolFactory: nil, | |
47 | InputProtocol: iprot, | |
48 | OutputProtocol: oprot, | |
49 | SeqId: 0, | |
50 | } | |
51 | } | |
52 | ||
53 | // Parameters: | |
54 | // - A | |
55 | // - B | |
56 | func (p *AddServiceClient) Sum(a int64, b int64) (r *SumReply, err error) { | |
57 | if err = p.sendSum(a, b); err != nil { | |
58 | return | |
59 | } | |
60 | return p.recvSum() | |
61 | } | |
62 | ||
63 | func (p *AddServiceClient) sendSum(a int64, b int64) (err error) { | |
64 | oprot := p.OutputProtocol | |
65 | if oprot == nil { | |
66 | oprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
67 | p.OutputProtocol = oprot | |
68 | } | |
69 | p.SeqId++ | |
70 | if err = oprot.WriteMessageBegin("Sum", thrift.CALL, p.SeqId); err != nil { | |
71 | return | |
72 | } | |
73 | args := AddServiceSumArgs{ | |
74 | A: a, | |
75 | B: b, | |
76 | } | |
77 | if err = args.Write(oprot); err != nil { | |
78 | return | |
79 | } | |
80 | if err = oprot.WriteMessageEnd(); err != nil { | |
81 | return | |
82 | } | |
83 | return oprot.Flush() | |
84 | } | |
85 | ||
86 | func (p *AddServiceClient) recvSum() (value *SumReply, err error) { | |
87 | iprot := p.InputProtocol | |
88 | if iprot == nil { | |
89 | iprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
90 | p.InputProtocol = iprot | |
91 | } | |
92 | method, mTypeId, seqId, err := iprot.ReadMessageBegin() | |
93 | if err != nil { | |
94 | return | |
95 | } | |
96 | if method != "Sum" { | |
97 | err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "Sum failed: wrong method name") | |
98 | return | |
99 | } | |
100 | if p.SeqId != seqId { | |
101 | err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Sum failed: out of sequence response") | |
102 | return | |
103 | } | |
104 | if mTypeId == thrift.EXCEPTION { | |
105 | error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") | |
106 | var error1 error | |
107 | error1, err = error0.Read(iprot) | |
108 | if err != nil { | |
109 | return | |
110 | } | |
111 | if err = iprot.ReadMessageEnd(); err != nil { | |
112 | return | |
113 | } | |
114 | err = error1 | |
115 | return | |
116 | } | |
117 | if mTypeId != thrift.REPLY { | |
118 | err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "Sum failed: invalid message type") | |
119 | return | |
120 | } | |
121 | result := AddServiceSumResult{} | |
122 | if err = result.Read(iprot); err != nil { | |
123 | return | |
124 | } | |
125 | if err = iprot.ReadMessageEnd(); err != nil { | |
126 | return | |
127 | } | |
128 | value = result.GetSuccess() | |
129 | return | |
130 | } | |
131 | ||
132 | // Parameters: | |
133 | // - A | |
134 | // - B | |
135 | func (p *AddServiceClient) Concat(a string, b string) (r *ConcatReply, err error) { | |
136 | if err = p.sendConcat(a, b); err != nil { | |
137 | return | |
138 | } | |
139 | return p.recvConcat() | |
140 | } | |
141 | ||
142 | func (p *AddServiceClient) sendConcat(a string, b string) (err error) { | |
143 | oprot := p.OutputProtocol | |
144 | if oprot == nil { | |
145 | oprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
146 | p.OutputProtocol = oprot | |
147 | } | |
148 | p.SeqId++ | |
149 | if err = oprot.WriteMessageBegin("Concat", thrift.CALL, p.SeqId); err != nil { | |
150 | return | |
151 | } | |
152 | args := AddServiceConcatArgs{ | |
153 | A: a, | |
154 | B: b, | |
155 | } | |
156 | if err = args.Write(oprot); err != nil { | |
157 | return | |
158 | } | |
159 | if err = oprot.WriteMessageEnd(); err != nil { | |
160 | return | |
161 | } | |
162 | return oprot.Flush() | |
163 | } | |
164 | ||
165 | func (p *AddServiceClient) recvConcat() (value *ConcatReply, err error) { | |
166 | iprot := p.InputProtocol | |
167 | if iprot == nil { | |
168 | iprot = p.ProtocolFactory.GetProtocol(p.Transport) | |
169 | p.InputProtocol = iprot | |
170 | } | |
171 | method, mTypeId, seqId, err := iprot.ReadMessageBegin() | |
172 | if err != nil { | |
173 | return | |
174 | } | |
175 | if method != "Concat" { | |
176 | err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "Concat failed: wrong method name") | |
177 | return | |
178 | } | |
179 | if p.SeqId != seqId { | |
180 | err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Concat failed: out of sequence response") | |
181 | return | |
182 | } | |
183 | if mTypeId == thrift.EXCEPTION { | |
184 | error2 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") | |
185 | var error3 error | |
186 | error3, err = error2.Read(iprot) | |
187 | if err != nil { | |
188 | return | |
189 | } | |
190 | if err = iprot.ReadMessageEnd(); err != nil { | |
191 | return | |
192 | } | |
193 | err = error3 | |
194 | return | |
195 | } | |
196 | if mTypeId != thrift.REPLY { | |
197 | err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "Concat failed: invalid message type") | |
198 | return | |
199 | } | |
200 | result := AddServiceConcatResult{} | |
201 | if err = result.Read(iprot); err != nil { | |
202 | return | |
203 | } | |
204 | if err = iprot.ReadMessageEnd(); err != nil { | |
205 | return | |
206 | } | |
207 | value = result.GetSuccess() | |
208 | return | |
209 | } | |
210 | ||
211 | type AddServiceProcessor struct { | |
212 | processorMap map[string]thrift.TProcessorFunction | |
213 | handler AddService | |
214 | } | |
215 | ||
216 | func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { | |
217 | p.processorMap[key] = processor | |
218 | } | |
219 | ||
220 | func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { | |
221 | processor, ok = p.processorMap[key] | |
222 | return processor, ok | |
223 | } | |
224 | ||
225 | func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { | |
226 | return p.processorMap | |
227 | } | |
228 | ||
229 | func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { | |
230 | ||
231 | self4 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} | |
232 | self4.processorMap["Sum"] = &addServiceProcessorSum{handler: handler} | |
233 | self4.processorMap["Concat"] = &addServiceProcessorConcat{handler: handler} | |
234 | return self4 | |
235 | } | |
236 | ||
237 | func (p *AddServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
238 | name, _, seqId, err := iprot.ReadMessageBegin() | |
239 | if err != nil { | |
240 | return false, err | |
241 | } | |
242 | if processor, ok := p.GetProcessorFunction(name); ok { | |
243 | return processor.Process(seqId, iprot, oprot) | |
244 | } | |
245 | iprot.Skip(thrift.STRUCT) | |
246 | iprot.ReadMessageEnd() | |
247 | x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) | |
248 | oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) | |
249 | x5.Write(oprot) | |
250 | oprot.WriteMessageEnd() | |
251 | oprot.Flush() | |
252 | return false, x5 | |
253 | ||
254 | } | |
255 | ||
256 | type addServiceProcessorSum struct { | |
257 | handler AddService | |
258 | } | |
259 | ||
260 | func (p *addServiceProcessorSum) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
261 | args := AddServiceSumArgs{} | |
262 | if err = args.Read(iprot); err != nil { | |
263 | iprot.ReadMessageEnd() | |
264 | x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) | |
265 | oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) | |
266 | x.Write(oprot) | |
267 | oprot.WriteMessageEnd() | |
268 | oprot.Flush() | |
269 | return false, err | |
270 | } | |
271 | ||
272 | iprot.ReadMessageEnd() | |
273 | result := AddServiceSumResult{} | |
274 | var retval *SumReply | |
275 | var err2 error | |
276 | if retval, err2 = p.handler.Sum(args.A, args.B); err2 != nil { | |
277 | x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Sum: "+err2.Error()) | |
278 | oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) | |
279 | x.Write(oprot) | |
280 | oprot.WriteMessageEnd() | |
281 | oprot.Flush() | |
282 | return true, err2 | |
283 | } else { | |
284 | result.Success = retval | |
285 | } | |
286 | if err2 = oprot.WriteMessageBegin("Sum", thrift.REPLY, seqId); err2 != nil { | |
287 | err = err2 | |
288 | } | |
289 | if err2 = result.Write(oprot); err == nil && err2 != nil { | |
290 | err = err2 | |
291 | } | |
292 | if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { | |
293 | err = err2 | |
294 | } | |
295 | if err2 = oprot.Flush(); err == nil && err2 != nil { | |
296 | err = err2 | |
297 | } | |
298 | if err != nil { | |
299 | return | |
300 | } | |
301 | return true, err | |
302 | } | |
303 | ||
304 | type addServiceProcessorConcat struct { | |
305 | handler AddService | |
306 | } | |
307 | ||
308 | func (p *addServiceProcessorConcat) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { | |
309 | args := AddServiceConcatArgs{} | |
310 | if err = args.Read(iprot); err != nil { | |
311 | iprot.ReadMessageEnd() | |
312 | x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) | |
313 | oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) | |
314 | x.Write(oprot) | |
315 | oprot.WriteMessageEnd() | |
316 | oprot.Flush() | |
317 | return false, err | |
318 | } | |
319 | ||
320 | iprot.ReadMessageEnd() | |
321 | result := AddServiceConcatResult{} | |
322 | var retval *ConcatReply | |
323 | var err2 error | |
324 | if retval, err2 = p.handler.Concat(args.A, args.B); err2 != nil { | |
325 | x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Concat: "+err2.Error()) | |
326 | oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) | |
327 | x.Write(oprot) | |
328 | oprot.WriteMessageEnd() | |
329 | oprot.Flush() | |
330 | return true, err2 | |
331 | } else { | |
332 | result.Success = retval | |
333 | } | |
334 | if err2 = oprot.WriteMessageBegin("Concat", thrift.REPLY, seqId); err2 != nil { | |
335 | err = err2 | |
336 | } | |
337 | if err2 = result.Write(oprot); err == nil && err2 != nil { | |
338 | err = err2 | |
339 | } | |
340 | if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { | |
341 | err = err2 | |
342 | } | |
343 | if err2 = oprot.Flush(); err == nil && err2 != nil { | |
344 | err = err2 | |
345 | } | |
346 | if err != nil { | |
347 | return | |
348 | } | |
349 | return true, err | |
350 | } | |
351 | ||
352 | // HELPER FUNCTIONS AND STRUCTURES | |
353 | ||
354 | // Attributes: | |
355 | // - A | |
356 | // - B | |
357 | type AddServiceSumArgs struct { | |
358 | A int64 `thrift:"a,1" json:"a"` | |
359 | B int64 `thrift:"b,2" json:"b"` | |
360 | } | |
361 | ||
362 | func NewAddServiceSumArgs() *AddServiceSumArgs { | |
363 | return &AddServiceSumArgs{} | |
364 | } | |
365 | ||
366 | func (p *AddServiceSumArgs) GetA() int64 { | |
367 | return p.A | |
368 | } | |
369 | ||
370 | func (p *AddServiceSumArgs) GetB() int64 { | |
371 | return p.B | |
372 | } | |
373 | func (p *AddServiceSumArgs) Read(iprot thrift.TProtocol) error { | |
374 | if _, err := iprot.ReadStructBegin(); err != nil { | |
375 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
376 | } | |
377 | ||
378 | for { | |
379 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
380 | if err != nil { | |
381 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
382 | } | |
383 | if fieldTypeId == thrift.STOP { | |
384 | break | |
385 | } | |
386 | switch fieldId { | |
387 | case 1: | |
388 | if err := p.readField1(iprot); err != nil { | |
389 | return err | |
390 | } | |
391 | case 2: | |
392 | if err := p.readField2(iprot); err != nil { | |
393 | return err | |
394 | } | |
395 | default: | |
396 | if err := iprot.Skip(fieldTypeId); err != nil { | |
397 | return err | |
398 | } | |
399 | } | |
400 | if err := iprot.ReadFieldEnd(); err != nil { | |
401 | return err | |
402 | } | |
403 | } | |
404 | if err := iprot.ReadStructEnd(); err != nil { | |
405 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
406 | } | |
407 | return nil | |
408 | } | |
409 | ||
410 | func (p *AddServiceSumArgs) readField1(iprot thrift.TProtocol) error { | |
411 | if v, err := iprot.ReadI64(); err != nil { | |
412 | return thrift.PrependError("error reading field 1: ", err) | |
413 | } else { | |
414 | p.A = v | |
415 | } | |
416 | return nil | |
417 | } | |
418 | ||
419 | func (p *AddServiceSumArgs) readField2(iprot thrift.TProtocol) error { | |
420 | if v, err := iprot.ReadI64(); err != nil { | |
421 | return thrift.PrependError("error reading field 2: ", err) | |
422 | } else { | |
423 | p.B = v | |
424 | } | |
425 | return nil | |
426 | } | |
427 | ||
428 | func (p *AddServiceSumArgs) Write(oprot thrift.TProtocol) error { | |
429 | if err := oprot.WriteStructBegin("Sum_args"); err != nil { | |
430 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
431 | } | |
432 | if err := p.writeField1(oprot); err != nil { | |
433 | return err | |
434 | } | |
435 | if err := p.writeField2(oprot); err != nil { | |
436 | return err | |
437 | } | |
438 | if err := oprot.WriteFieldStop(); err != nil { | |
439 | return thrift.PrependError("write field stop error: ", err) | |
440 | } | |
441 | if err := oprot.WriteStructEnd(); err != nil { | |
442 | return thrift.PrependError("write struct stop error: ", err) | |
443 | } | |
444 | return nil | |
445 | } | |
446 | ||
447 | func (p *AddServiceSumArgs) writeField1(oprot thrift.TProtocol) (err error) { | |
448 | if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { | |
449 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) | |
450 | } | |
451 | if err := oprot.WriteI64(int64(p.A)); err != nil { | |
452 | return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) | |
453 | } | |
454 | if err := oprot.WriteFieldEnd(); err != nil { | |
455 | return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) | |
456 | } | |
457 | return err | |
458 | } | |
459 | ||
460 | func (p *AddServiceSumArgs) writeField2(oprot thrift.TProtocol) (err error) { | |
461 | if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { | |
462 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) | |
463 | } | |
464 | if err := oprot.WriteI64(int64(p.B)); err != nil { | |
465 | return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) | |
466 | } | |
467 | if err := oprot.WriteFieldEnd(); err != nil { | |
468 | return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) | |
469 | } | |
470 | return err | |
471 | } | |
472 | ||
473 | func (p *AddServiceSumArgs) String() string { | |
474 | if p == nil { | |
475 | return "<nil>" | |
476 | } | |
477 | return fmt.Sprintf("AddServiceSumArgs(%+v)", *p) | |
478 | } | |
479 | ||
480 | // Attributes: | |
481 | // - Success | |
482 | type AddServiceSumResult struct { | |
483 | Success *SumReply `thrift:"success,0" json:"success,omitempty"` | |
484 | } | |
485 | ||
486 | func NewAddServiceSumResult() *AddServiceSumResult { | |
487 | return &AddServiceSumResult{} | |
488 | } | |
489 | ||
490 | var AddServiceSumResult_Success_DEFAULT *SumReply | |
491 | ||
492 | func (p *AddServiceSumResult) GetSuccess() *SumReply { | |
493 | if !p.IsSetSuccess() { | |
494 | return AddServiceSumResult_Success_DEFAULT | |
495 | } | |
496 | return p.Success | |
497 | } | |
498 | func (p *AddServiceSumResult) IsSetSuccess() bool { | |
499 | return p.Success != nil | |
500 | } | |
501 | ||
502 | func (p *AddServiceSumResult) Read(iprot thrift.TProtocol) error { | |
503 | if _, err := iprot.ReadStructBegin(); err != nil { | |
504 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
505 | } | |
506 | ||
507 | for { | |
508 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
509 | if err != nil { | |
510 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
511 | } | |
512 | if fieldTypeId == thrift.STOP { | |
513 | break | |
514 | } | |
515 | switch fieldId { | |
516 | case 0: | |
517 | if err := p.readField0(iprot); err != nil { | |
518 | return err | |
519 | } | |
520 | default: | |
521 | if err := iprot.Skip(fieldTypeId); err != nil { | |
522 | return err | |
523 | } | |
524 | } | |
525 | if err := iprot.ReadFieldEnd(); err != nil { | |
526 | return err | |
527 | } | |
528 | } | |
529 | if err := iprot.ReadStructEnd(); err != nil { | |
530 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
531 | } | |
532 | return nil | |
533 | } | |
534 | ||
535 | func (p *AddServiceSumResult) readField0(iprot thrift.TProtocol) error { | |
536 | p.Success = &SumReply{} | |
537 | if err := p.Success.Read(iprot); err != nil { | |
538 | return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) | |
539 | } | |
540 | return nil | |
541 | } | |
542 | ||
543 | func (p *AddServiceSumResult) Write(oprot thrift.TProtocol) error { | |
544 | if err := oprot.WriteStructBegin("Sum_result"); err != nil { | |
545 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
546 | } | |
547 | if err := p.writeField0(oprot); err != nil { | |
548 | return err | |
549 | } | |
550 | if err := oprot.WriteFieldStop(); err != nil { | |
551 | return thrift.PrependError("write field stop error: ", err) | |
552 | } | |
553 | if err := oprot.WriteStructEnd(); err != nil { | |
554 | return thrift.PrependError("write struct stop error: ", err) | |
555 | } | |
556 | return nil | |
557 | } | |
558 | ||
559 | func (p *AddServiceSumResult) writeField0(oprot thrift.TProtocol) (err error) { | |
560 | if p.IsSetSuccess() { | |
561 | if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { | |
562 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) | |
563 | } | |
564 | if err := p.Success.Write(oprot); err != nil { | |
565 | return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) | |
566 | } | |
567 | if err := oprot.WriteFieldEnd(); err != nil { | |
568 | return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) | |
569 | } | |
570 | } | |
571 | return err | |
572 | } | |
573 | ||
574 | func (p *AddServiceSumResult) String() string { | |
575 | if p == nil { | |
576 | return "<nil>" | |
577 | } | |
578 | return fmt.Sprintf("AddServiceSumResult(%+v)", *p) | |
579 | } | |
580 | ||
581 | // Attributes: | |
582 | // - A | |
583 | // - B | |
584 | type AddServiceConcatArgs struct { | |
585 | A string `thrift:"a,1" json:"a"` | |
586 | B string `thrift:"b,2" json:"b"` | |
587 | } | |
588 | ||
589 | func NewAddServiceConcatArgs() *AddServiceConcatArgs { | |
590 | return &AddServiceConcatArgs{} | |
591 | } | |
592 | ||
593 | func (p *AddServiceConcatArgs) GetA() string { | |
594 | return p.A | |
595 | } | |
596 | ||
597 | func (p *AddServiceConcatArgs) GetB() string { | |
598 | return p.B | |
599 | } | |
600 | func (p *AddServiceConcatArgs) Read(iprot thrift.TProtocol) error { | |
601 | if _, err := iprot.ReadStructBegin(); err != nil { | |
602 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
603 | } | |
604 | ||
605 | for { | |
606 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
607 | if err != nil { | |
608 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
609 | } | |
610 | if fieldTypeId == thrift.STOP { | |
611 | break | |
612 | } | |
613 | switch fieldId { | |
614 | case 1: | |
615 | if err := p.readField1(iprot); err != nil { | |
616 | return err | |
617 | } | |
618 | case 2: | |
619 | if err := p.readField2(iprot); err != nil { | |
620 | return err | |
621 | } | |
622 | default: | |
623 | if err := iprot.Skip(fieldTypeId); err != nil { | |
624 | return err | |
625 | } | |
626 | } | |
627 | if err := iprot.ReadFieldEnd(); err != nil { | |
628 | return err | |
629 | } | |
630 | } | |
631 | if err := iprot.ReadStructEnd(); err != nil { | |
632 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
633 | } | |
634 | return nil | |
635 | } | |
636 | ||
637 | func (p *AddServiceConcatArgs) readField1(iprot thrift.TProtocol) error { | |
638 | if v, err := iprot.ReadString(); err != nil { | |
639 | return thrift.PrependError("error reading field 1: ", err) | |
640 | } else { | |
641 | p.A = v | |
642 | } | |
643 | return nil | |
644 | } | |
645 | ||
646 | func (p *AddServiceConcatArgs) readField2(iprot thrift.TProtocol) error { | |
647 | if v, err := iprot.ReadString(); err != nil { | |
648 | return thrift.PrependError("error reading field 2: ", err) | |
649 | } else { | |
650 | p.B = v | |
651 | } | |
652 | return nil | |
653 | } | |
654 | ||
655 | func (p *AddServiceConcatArgs) Write(oprot thrift.TProtocol) error { | |
656 | if err := oprot.WriteStructBegin("Concat_args"); err != nil { | |
657 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
658 | } | |
659 | if err := p.writeField1(oprot); err != nil { | |
660 | return err | |
661 | } | |
662 | if err := p.writeField2(oprot); err != nil { | |
663 | return err | |
664 | } | |
665 | if err := oprot.WriteFieldStop(); err != nil { | |
666 | return thrift.PrependError("write field stop error: ", err) | |
667 | } | |
668 | if err := oprot.WriteStructEnd(); err != nil { | |
669 | return thrift.PrependError("write struct stop error: ", err) | |
670 | } | |
671 | return nil | |
672 | } | |
673 | ||
674 | func (p *AddServiceConcatArgs) writeField1(oprot thrift.TProtocol) (err error) { | |
675 | if err := oprot.WriteFieldBegin("a", thrift.STRING, 1); err != nil { | |
676 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) | |
677 | } | |
678 | if err := oprot.WriteString(string(p.A)); err != nil { | |
679 | return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) | |
680 | } | |
681 | if err := oprot.WriteFieldEnd(); err != nil { | |
682 | return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) | |
683 | } | |
684 | return err | |
685 | } | |
686 | ||
687 | func (p *AddServiceConcatArgs) writeField2(oprot thrift.TProtocol) (err error) { | |
688 | if err := oprot.WriteFieldBegin("b", thrift.STRING, 2); err != nil { | |
689 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) | |
690 | } | |
691 | if err := oprot.WriteString(string(p.B)); err != nil { | |
692 | return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) | |
693 | } | |
694 | if err := oprot.WriteFieldEnd(); err != nil { | |
695 | return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) | |
696 | } | |
697 | return err | |
698 | } | |
699 | ||
700 | func (p *AddServiceConcatArgs) String() string { | |
701 | if p == nil { | |
702 | return "<nil>" | |
703 | } | |
704 | return fmt.Sprintf("AddServiceConcatArgs(%+v)", *p) | |
705 | } | |
706 | ||
707 | // Attributes: | |
708 | // - Success | |
709 | type AddServiceConcatResult struct { | |
710 | Success *ConcatReply `thrift:"success,0" json:"success,omitempty"` | |
711 | } | |
712 | ||
713 | func NewAddServiceConcatResult() *AddServiceConcatResult { | |
714 | return &AddServiceConcatResult{} | |
715 | } | |
716 | ||
717 | var AddServiceConcatResult_Success_DEFAULT *ConcatReply | |
718 | ||
719 | func (p *AddServiceConcatResult) GetSuccess() *ConcatReply { | |
720 | if !p.IsSetSuccess() { | |
721 | return AddServiceConcatResult_Success_DEFAULT | |
722 | } | |
723 | return p.Success | |
724 | } | |
725 | func (p *AddServiceConcatResult) IsSetSuccess() bool { | |
726 | return p.Success != nil | |
727 | } | |
728 | ||
729 | func (p *AddServiceConcatResult) Read(iprot thrift.TProtocol) error { | |
730 | if _, err := iprot.ReadStructBegin(); err != nil { | |
731 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
732 | } | |
733 | ||
734 | for { | |
735 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
736 | if err != nil { | |
737 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
738 | } | |
739 | if fieldTypeId == thrift.STOP { | |
740 | break | |
741 | } | |
742 | switch fieldId { | |
743 | case 0: | |
744 | if err := p.readField0(iprot); err != nil { | |
745 | return err | |
746 | } | |
747 | default: | |
748 | if err := iprot.Skip(fieldTypeId); err != nil { | |
749 | return err | |
750 | } | |
751 | } | |
752 | if err := iprot.ReadFieldEnd(); err != nil { | |
753 | return err | |
754 | } | |
755 | } | |
756 | if err := iprot.ReadStructEnd(); err != nil { | |
757 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
758 | } | |
759 | return nil | |
760 | } | |
761 | ||
762 | func (p *AddServiceConcatResult) readField0(iprot thrift.TProtocol) error { | |
763 | p.Success = &ConcatReply{} | |
764 | if err := p.Success.Read(iprot); err != nil { | |
765 | return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) | |
766 | } | |
767 | return nil | |
768 | } | |
769 | ||
770 | func (p *AddServiceConcatResult) Write(oprot thrift.TProtocol) error { | |
771 | if err := oprot.WriteStructBegin("Concat_result"); err != nil { | |
772 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
773 | } | |
774 | if err := p.writeField0(oprot); err != nil { | |
775 | return err | |
776 | } | |
777 | if err := oprot.WriteFieldStop(); err != nil { | |
778 | return thrift.PrependError("write field stop error: ", err) | |
779 | } | |
780 | if err := oprot.WriteStructEnd(); err != nil { | |
781 | return thrift.PrependError("write struct stop error: ", err) | |
782 | } | |
783 | return nil | |
784 | } | |
785 | ||
786 | func (p *AddServiceConcatResult) writeField0(oprot thrift.TProtocol) (err error) { | |
787 | if p.IsSetSuccess() { | |
788 | if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { | |
789 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) | |
790 | } | |
791 | if err := p.Success.Write(oprot); err != nil { | |
792 | return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) | |
793 | } | |
794 | if err := oprot.WriteFieldEnd(); err != nil { | |
795 | return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) | |
796 | } | |
797 | } | |
798 | return err | |
799 | } | |
800 | ||
801 | func (p *AddServiceConcatResult) String() string { | |
802 | if p == nil { | |
803 | return "<nil>" | |
804 | } | |
805 | return fmt.Sprintf("AddServiceConcatResult(%+v)", *p) | |
806 | } |
0 | // Autogenerated by Thrift Compiler (0.9.3) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | func init() { | |
17 | } |
0 | // Autogenerated by Thrift Compiler (0.9.3) | |
1 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
2 | ||
3 | package add | |
4 | ||
5 | import ( | |
6 | "bytes" | |
7 | "fmt" | |
8 | "github.com/apache/thrift/lib/go/thrift" | |
9 | ) | |
10 | ||
11 | // (needed to ensure safety because of naive import list construction.) | |
12 | var _ = thrift.ZERO | |
13 | var _ = fmt.Printf | |
14 | var _ = bytes.Equal | |
15 | ||
16 | var GoUnusedProtection__ int | |
17 | ||
18 | // Attributes: | |
19 | // - Value | |
20 | type SumReply struct { | |
21 | Value int64 `thrift:"value,1" json:"value"` | |
22 | } | |
23 | ||
24 | func NewSumReply() *SumReply { | |
25 | return &SumReply{} | |
26 | } | |
27 | ||
28 | func (p *SumReply) GetValue() int64 { | |
29 | return p.Value | |
30 | } | |
31 | func (p *SumReply) Read(iprot thrift.TProtocol) error { | |
32 | if _, err := iprot.ReadStructBegin(); err != nil { | |
33 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
34 | } | |
35 | ||
36 | for { | |
37 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
38 | if err != nil { | |
39 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
40 | } | |
41 | if fieldTypeId == thrift.STOP { | |
42 | break | |
43 | } | |
44 | switch fieldId { | |
45 | case 1: | |
46 | if err := p.readField1(iprot); err != nil { | |
47 | return err | |
48 | } | |
49 | default: | |
50 | if err := iprot.Skip(fieldTypeId); err != nil { | |
51 | return err | |
52 | } | |
53 | } | |
54 | if err := iprot.ReadFieldEnd(); err != nil { | |
55 | return err | |
56 | } | |
57 | } | |
58 | if err := iprot.ReadStructEnd(); err != nil { | |
59 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
60 | } | |
61 | return nil | |
62 | } | |
63 | ||
64 | func (p *SumReply) readField1(iprot thrift.TProtocol) error { | |
65 | if v, err := iprot.ReadI64(); err != nil { | |
66 | return thrift.PrependError("error reading field 1: ", err) | |
67 | } else { | |
68 | p.Value = v | |
69 | } | |
70 | return nil | |
71 | } | |
72 | ||
73 | func (p *SumReply) Write(oprot thrift.TProtocol) error { | |
74 | if err := oprot.WriteStructBegin("SumReply"); err != nil { | |
75 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
76 | } | |
77 | if err := p.writeField1(oprot); err != nil { | |
78 | return err | |
79 | } | |
80 | if err := oprot.WriteFieldStop(); err != nil { | |
81 | return thrift.PrependError("write field stop error: ", err) | |
82 | } | |
83 | if err := oprot.WriteStructEnd(); err != nil { | |
84 | return thrift.PrependError("write struct stop error: ", err) | |
85 | } | |
86 | return nil | |
87 | } | |
88 | ||
89 | func (p *SumReply) writeField1(oprot thrift.TProtocol) (err error) { | |
90 | if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { | |
91 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) | |
92 | } | |
93 | if err := oprot.WriteI64(int64(p.Value)); err != nil { | |
94 | return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) | |
95 | } | |
96 | if err := oprot.WriteFieldEnd(); err != nil { | |
97 | return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) | |
98 | } | |
99 | return err | |
100 | } | |
101 | ||
102 | func (p *SumReply) String() string { | |
103 | if p == nil { | |
104 | return "<nil>" | |
105 | } | |
106 | return fmt.Sprintf("SumReply(%+v)", *p) | |
107 | } | |
108 | ||
109 | // Attributes: | |
110 | // - Value | |
111 | type ConcatReply struct { | |
112 | Value string `thrift:"value,1" json:"value"` | |
113 | } | |
114 | ||
115 | func NewConcatReply() *ConcatReply { | |
116 | return &ConcatReply{} | |
117 | } | |
118 | ||
119 | func (p *ConcatReply) GetValue() string { | |
120 | return p.Value | |
121 | } | |
122 | func (p *ConcatReply) Read(iprot thrift.TProtocol) error { | |
123 | if _, err := iprot.ReadStructBegin(); err != nil { | |
124 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) | |
125 | } | |
126 | ||
127 | for { | |
128 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() | |
129 | if err != nil { | |
130 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) | |
131 | } | |
132 | if fieldTypeId == thrift.STOP { | |
133 | break | |
134 | } | |
135 | switch fieldId { | |
136 | case 1: | |
137 | if err := p.readField1(iprot); err != nil { | |
138 | return err | |
139 | } | |
140 | default: | |
141 | if err := iprot.Skip(fieldTypeId); err != nil { | |
142 | return err | |
143 | } | |
144 | } | |
145 | if err := iprot.ReadFieldEnd(); err != nil { | |
146 | return err | |
147 | } | |
148 | } | |
149 | if err := iprot.ReadStructEnd(); err != nil { | |
150 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) | |
151 | } | |
152 | return nil | |
153 | } | |
154 | ||
155 | func (p *ConcatReply) readField1(iprot thrift.TProtocol) error { | |
156 | if v, err := iprot.ReadString(); err != nil { | |
157 | return thrift.PrependError("error reading field 1: ", err) | |
158 | } else { | |
159 | p.Value = v | |
160 | } | |
161 | return nil | |
162 | } | |
163 | ||
164 | func (p *ConcatReply) Write(oprot thrift.TProtocol) error { | |
165 | if err := oprot.WriteStructBegin("ConcatReply"); err != nil { | |
166 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) | |
167 | } | |
168 | if err := p.writeField1(oprot); err != nil { | |
169 | return err | |
170 | } | |
171 | if err := oprot.WriteFieldStop(); err != nil { | |
172 | return thrift.PrependError("write field stop error: ", err) | |
173 | } | |
174 | if err := oprot.WriteStructEnd(); err != nil { | |
175 | return thrift.PrependError("write struct stop error: ", err) | |
176 | } | |
177 | return nil | |
178 | } | |
179 | ||
180 | func (p *ConcatReply) writeField1(oprot thrift.TProtocol) (err error) { | |
181 | if err := oprot.WriteFieldBegin("value", thrift.STRING, 1); err != nil { | |
182 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) | |
183 | } | |
184 | if err := oprot.WriteString(string(p.Value)); err != nil { | |
185 | return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) | |
186 | } | |
187 | if err := oprot.WriteFieldEnd(); err != nil { | |
188 | return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) | |
189 | } | |
190 | return err | |
191 | } | |
192 | ||
193 | func (p *ConcatReply) String() string { | |
194 | if p == nil { | |
195 | return "<nil>" | |
196 | } | |
197 | return fmt.Sprintf("ConcatReply(%+v)", *p) | |
198 | } |
12 | 12 | On a Mac, you may be able to `brew install thrift`. |
13 | 13 | |
14 | 14 | Then, compile your service definition, from .thrift to .go. |
15 | You'll probably want to specify the package_prefix option to the --gen go flag. | |
16 | See [THRIFT-3021](https://issues.apache.org/jira/browse/THRIFT-3021) for more details. | |
15 | 17 | |
16 | 18 | ``` |
17 | thrift -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift add.thrift | |
19 | thrift -r --gen go:package_prefix=github.com/my-org/my-repo/thrift/gen-go/ add.thrift | |
18 | 20 | ``` |
19 | 21 | |
20 | 22 | Finally, write a tiny binding from your service definition to the Thrift definition. |