go.uber.org/yarpc@v1.72.1/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather/weatherclient/client.go (about) 1 // Code generated by thriftrw-plugin-yarpc 2 // @generated 3 4 package weatherclient 5 6 import ( 7 context "context" 8 tchannel "github.com/uber/tchannel-go" 9 wire "go.uber.org/thriftrw/wire" 10 yarpc "go.uber.org/yarpc" 11 transport "go.uber.org/yarpc/api/transport" 12 thrift "go.uber.org/yarpc/encoding/thrift" 13 weather "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather" 14 reflect "reflect" 15 ) 16 17 // Interface is a client for the Weather service. 18 type Interface interface { 19 Check( 20 ctx context.Context, 21 opts ...yarpc.CallOption, 22 ) (string, error) 23 } 24 25 // New builds a new client for the Weather service. 26 // 27 // client := weatherclient.New(dispatcher.ClientConfig("weather")) 28 func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { 29 return client{ 30 c: thrift.New(thrift.Config{ 31 Service: "Weather", 32 ClientConfig: c, 33 }, opts...), 34 nwc: thrift.NewNoWire(thrift.Config{ 35 Service: "Weather", 36 ClientConfig: c, 37 }, opts...), 38 } 39 } 40 41 func init() { 42 yarpc.RegisterClientBuilder( 43 func(c transport.ClientConfig, f reflect.StructField) Interface { 44 return New(c, thrift.ClientBuilderOptions(c, f)...) 45 }, 46 ) 47 } 48 49 type client struct { 50 c thrift.Client 51 nwc thrift.NoWireClient 52 } 53 54 func (c client) Check( 55 ctx context.Context, 56 opts ...yarpc.CallOption, 57 ) (success string, err error) { 58 59 var result weather.Weather_Check_Result 60 args := weather.Weather_Check_Helper.Args() 61 62 ctx = tchannel.WithoutHeaders(ctx) 63 if c.nwc != nil && c.nwc.Enabled() { 64 if err = c.nwc.Call(ctx, args, &result, opts...); err != nil { 65 return 66 } 67 } else { 68 var body wire.Value 69 if body, err = c.c.Call(ctx, args, opts...); err != nil { 70 return 71 } 72 73 if err = result.FromWire(body); err != nil { 74 return 75 } 76 } 77 78 success, err = weather.Weather_Check_Helper.UnwrapResponse(&result) 79 return 80 }