Codebase list golang-github-go-kit-kit / 52bb1a8
Merge pull request #678 from go-kit/test-commit Fix Thrift, if it needs fixing Bas van Beek authored 6 years ago GitHub committed 6 years ago
4 changed file(s) with 56 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
00 #!/usr/bin/env sh
11
2 # See also https://thrift.apache.org/tutorial/go
2 # See also https://thrift.apache.org/tutorial/go.
3 #
4 # An old version can be obtained via `brew install thrift`.
5 # For the latest, here's the annoying dance:
6 #
7 # brew install automake bison pkg-config openssl
8 # ln -s /usr/local/opt/openssl/include/openssl /usr/local/include # if it isn't already
9 # git clone git@github.com:apache/thrift
10 # ./bootstrap.sh
11 # bash
12 # export PATH=/usr/local/Cellar/bison/*/bin:$PATH
13 # ./configure ./configure --without-qt4 --without-qt5 --without-c_glib --without-csharp --without-java --without-erlang --without-nodejs --without-lua --without-python --without-perl --without-php --without-php_extension --without-dart --without-ruby --without-haskell --without-rs --without-cl --without-haxe --without-dotnetcore --without-d
14 # make
15 # sudo make install
316
417 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" addsvc.thrift
2727 os.Exit(0)
2828 }
2929
30 type httpHeaders map[string]string
31
32 func (h httpHeaders) String() string {
33 var m map[string]string = h
34 return fmt.Sprintf("%s", m)
35 }
36
37 func (h httpHeaders) Set(value string) error {
38 parts := strings.Split(value, ": ")
39 if len(parts) != 2 {
40 return fmt.Errorf("header should be of format 'Key: Value'")
41 }
42 h[parts[0]] = parts[1]
43 return nil
44 }
45
3046 func main() {
3147 flag.Usage = Usage
3248 var host string
3551 var urlString string
3652 var framed bool
3753 var useHttp bool
38 var parsedUrl url.URL
54 headers := make(httpHeaders)
55 var parsedUrl *url.URL
3956 var trans thrift.TTransport
4057 _ = strconv.Atoi
4158 _ = math.Abs
4663 flag.StringVar(&urlString, "u", "", "Specify the url")
4764 flag.BoolVar(&framed, "framed", false, "Use framed transport")
4865 flag.BoolVar(&useHttp, "http", false, "Use http")
66 flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")")
4967 flag.Parse()
5068
5169 if len(urlString) > 0 {
52 parsedUrl, err := url.Parse(urlString)
70 var err error
71 parsedUrl, err = url.Parse(urlString)
5372 if err != nil {
5473 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
5574 flag.Usage()
5675 }
5776 host = parsedUrl.Host
58 useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
77 useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https"
5978 } else if useHttp {
6079 _, err := url.Parse(fmt.Sprint("http://", host, ":", port))
6180 if err != nil {
6887 var err error
6988 if useHttp {
7089 trans, err = thrift.NewTHttpClient(parsedUrl.String())
90 if len(headers) > 0 {
91 httptrans := trans.(*thrift.THttpClient)
92 for key, value := range headers {
93 httptrans.SetHeader(key, value)
94 }
95 }
7196 } else {
7297 portStr := fmt.Sprint(port)
7398 if strings.Contains(host, ":") {
44
55 import (
66 "bytes"
7 "context"
78 "reflect"
8 "context"
99 "fmt"
1010 "github.com/apache/thrift/lib/go/thrift"
1111 )
44
55 import (
66 "bytes"
7 "context"
78 "reflect"
8 "context"
99 "fmt"
1010 "github.com/apache/thrift/lib/go/thrift"
1111 )
286286 c thrift.TClient
287287 }
288288
289 // Deprecated: Use NewAddService instead
290289 func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient {
291290 return &AddServiceClient{
292291 c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
293292 }
294293 }
295294
296 // Deprecated: Use NewAddService instead
297295 func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient {
298296 return &AddServiceClient{
299297 c: thrift.NewTStandardClient(iprot, oprot),
306304 }
307305 }
308306
307 func (p *AddServiceClient) Client_() thrift.TClient {
308 return p.c
309 }
309310 // Parameters:
310311 // - A
311312 // - B
314315 _args0.A = a
315316 _args0.B = b
316317 var _result1 AddServiceSumResult
317 if err = p.c.Call(ctx, "Sum", &_args0, &_result1); err != nil {
318 if err = p.Client_().Call(ctx, "Sum", &_args0, &_result1); err != nil {
318319 return
319320 }
320321 return _result1.GetSuccess(), nil
328329 _args2.A = a
329330 _args2.B = b
330331 var _result3 AddServiceConcatResult
331 if err = p.c.Call(ctx, "Concat", &_args2, &_result3); err != nil {
332 if err = p.Client_().Call(ctx, "Concat", &_args2, &_result3); err != nil {
332333 return
333334 }
334335 return _result3.GetSuccess(), nil
372373 oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
373374 x5.Write(oprot)
374375 oprot.WriteMessageEnd()
375 oprot.Flush()
376 oprot.Flush(ctx)
376377 return false, x5
377378
378379 }
389390 oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId)
390391 x.Write(oprot)
391392 oprot.WriteMessageEnd()
392 oprot.Flush()
393 oprot.Flush(ctx)
393394 return false, err
394395 }
395396
402403 oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId)
403404 x.Write(oprot)
404405 oprot.WriteMessageEnd()
405 oprot.Flush()
406 oprot.Flush(ctx)
406407 return true, err2
407408 } else {
408409 result.Success = retval
416417 if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
417418 err = err2
418419 }
419 if err2 = oprot.Flush(); err == nil && err2 != nil {
420 if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
420421 err = err2
421422 }
422423 if err != nil {
437438 oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId)
438439 x.Write(oprot)
439440 oprot.WriteMessageEnd()
440 oprot.Flush()
441 oprot.Flush(ctx)
441442 return false, err
442443 }
443444
450451 oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId)
451452 x.Write(oprot)
452453 oprot.WriteMessageEnd()
453 oprot.Flush()
454 oprot.Flush(ctx)
454455 return true, err2
455456 } else {
456457 result.Success = retval
464465 if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
465466 err = err2
466467 }
467 if err2 = oprot.Flush(); err == nil && err2 != nil {
468 if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
468469 err = err2
469470 }
470471 if err != nil {