go.uber.org/yarpc@v1.72.1/encoding/thrift/internal/observabilitytest/test/testserviceclient/client.go (about)

     1  // Code generated by thriftrw-plugin-yarpc
     2  // @generated
     3  
     4  // Copyright (c) 2022 Uber Technologies, Inc.
     5  //
     6  // Permission is hereby granted, free of charge, to any person obtaining a copy
     7  // of this software and associated documentation files (the "Software"), to deal
     8  // in the Software without restriction, including without limitation the rights
     9  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10  // copies of the Software, and to permit persons to whom the Software is
    11  // furnished to do so, subject to the following conditions:
    12  //
    13  // The above copyright notice and this permission notice shall be included in
    14  // all copies or substantial portions of the Software.
    15  //
    16  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    21  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    22  // THE SOFTWARE.
    23  
    24  package testserviceclient
    25  
    26  import (
    27  	context "context"
    28  	wire "go.uber.org/thriftrw/wire"
    29  	yarpc "go.uber.org/yarpc"
    30  	transport "go.uber.org/yarpc/api/transport"
    31  	thrift "go.uber.org/yarpc/encoding/thrift"
    32  	test "go.uber.org/yarpc/encoding/thrift/internal/observabilitytest/test"
    33  	reflect "reflect"
    34  )
    35  
    36  // Interface is a client for the TestService service.
    37  type Interface interface {
    38  	Call(
    39  		ctx context.Context,
    40  		Key string,
    41  		opts ...yarpc.CallOption,
    42  	) (string, error)
    43  }
    44  
    45  // New builds a new client for the TestService service.
    46  //
    47  // 	client := testserviceclient.New(dispatcher.ClientConfig("testservice"))
    48  func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface {
    49  	return client{
    50  		c: thrift.New(thrift.Config{
    51  			Service:      "TestService",
    52  			ClientConfig: c,
    53  		}, opts...),
    54  		nwc: thrift.NewNoWire(thrift.Config{
    55  			Service:      "TestService",
    56  			ClientConfig: c,
    57  		}, opts...),
    58  	}
    59  }
    60  
    61  func init() {
    62  	yarpc.RegisterClientBuilder(
    63  		func(c transport.ClientConfig, f reflect.StructField) Interface {
    64  			return New(c, thrift.ClientBuilderOptions(c, f)...)
    65  		},
    66  	)
    67  }
    68  
    69  type client struct {
    70  	c   thrift.Client
    71  	nwc thrift.NoWireClient
    72  }
    73  
    74  func (c client) Call(
    75  	ctx context.Context,
    76  	_Key string,
    77  	opts ...yarpc.CallOption,
    78  ) (success string, err error) {
    79  
    80  	var result test.TestService_Call_Result
    81  	args := test.TestService_Call_Helper.Args(_Key)
    82  
    83  	if c.nwc != nil && c.nwc.Enabled() {
    84  		if err = c.nwc.Call(ctx, args, &result, opts...); err != nil {
    85  			return
    86  		}
    87  	} else {
    88  		var body wire.Value
    89  		if body, err = c.c.Call(ctx, args, opts...); err != nil {
    90  			return
    91  		}
    92  
    93  		if err = result.FromWire(body); err != nil {
    94  			return
    95  		}
    96  	}
    97  
    98  	success, err = test.TestService_Call_Helper.UnwrapResponse(&result)
    99  	return
   100  }