go.uber.org/yarpc@v1.72.1/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient/client.go (about)

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