go.uber.org/yarpc@v1.72.1/api/transport/outboundconfig.go (about)

     1  // Copyright (c) 2022 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package transport
    22  
    23  import "fmt"
    24  
    25  // OutboundConfig is a configuration for how to call into another service.  It
    26  // is used in conjunction with an encoding to send a request through one of the
    27  // outbounds.
    28  type OutboundConfig struct {
    29  	CallerName string
    30  	Outbounds  Outbounds
    31  }
    32  
    33  var _ ClientConfig = (*OutboundConfig)(nil)
    34  
    35  // Caller is the name of the service making the request.
    36  //
    37  // Implements ClientConfig#Caller (for backwards compatibility).
    38  func (o *OutboundConfig) Caller() string {
    39  	// TODO: This function should be deprecated, it's for legacy support.
    40  	// Use CallerName instead.
    41  	return o.CallerName
    42  }
    43  
    44  // Service is the name of the service to which the request is being made.
    45  //
    46  // Implements ClientConfig#Service (for backwards compatibility).
    47  func (o *OutboundConfig) Service() string {
    48  	// TODO: This function should be deprecated, it's for legacy support.
    49  	// Use Outbounds.ServiceName instead.
    50  	return o.Outbounds.ServiceName
    51  }
    52  
    53  // GetUnaryOutbound returns an outbound to send the request through or panics
    54  // if there is no unary outbound for this service.
    55  //
    56  // Implements ClientConfig#GetUnaryOutbound.
    57  func (o *OutboundConfig) GetUnaryOutbound() UnaryOutbound {
    58  	// TODO: This function should be deprecated, it's for legacy support.
    59  	// Use Outbounds.Unary instead (and panic if you want).
    60  	if o.Outbounds.Unary == nil {
    61  		panic(fmt.Sprintf("service %q does not have a unary outbound", o.Outbounds.ServiceName))
    62  	}
    63  	return o.Outbounds.Unary
    64  }
    65  
    66  // GetOnewayOutbound returns an outbound to send the request through or panics
    67  // if there is no oneway outbound for this service.
    68  //
    69  // Implements ClientConfig#GetOnewayOutbound.
    70  func (o *OutboundConfig) GetOnewayOutbound() OnewayOutbound {
    71  	// TODO: This function should be deprecated, it's for legacy support.
    72  	// Use o.Outbounds.Oneway instead (and panic if you want).
    73  	if o.Outbounds.Oneway == nil {
    74  		panic(fmt.Sprintf("service %q does not have a oneway outbound", o.Outbounds.ServiceName))
    75  	}
    76  	return o.Outbounds.Oneway
    77  }