go.uber.org/yarpc@v1.72.1/encoding/thrift/doc.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 thrift implements Thrift encoding support for YARPC.
    22  //
    23  // To use this package, you must install ThriftRW 1.0 or newer.
    24  //
    25  // 	go get go.uber.org/thriftrw
    26  //
    27  // You must also install the ThriftRW plugin for YARPC.
    28  //
    29  // 	go get go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc
    30  //
    31  // To generate YARPC compatible code from a Thrift file, use the command,
    32  //
    33  // 	thriftrw --plugin yarpc myservice.thrift
    34  //
    35  // In addition to generating code for types specified in your Thrift file,
    36  // this will generate the following packages for each service in the file: a
    37  // client package, a server package, a test package, and an UberFx module.
    38  //
    39  // 	myservice
    40  // 	   |- myserviceclient
    41  // 	   |- myserviceserver
    42  // 	   |- myservicefx
    43  // 	   |- myservicetest
    44  //
    45  // The client package allows sending requests through a YARPC dispatcher.
    46  //
    47  // 	client := myserviceclient.New(dispatcher.ClientConfig("myservice"))
    48  //
    49  // The server package facilitates registration of service implementations with
    50  // a YARPC dispatcher.
    51  //
    52  // 	handler := myHandler{}
    53  // 	dispatcher.Register(myserviceserver.New(handler))
    54  //
    55  // The test package provides a gomock-compatible mock client for the service.
    56  //
    57  // 	mockCtrl := gomock.NewController(t)
    58  // 	client := myservicetest.NewMockClient(mockCtrl)
    59  // 	client.EXPECT().Hello(request).Return(response, nil)
    60  //
    61  // The Fx package provides an UberFx-compatible constructor for service
    62  // clients. This may be used with Provide to make service clients available in
    63  // the container.
    64  //
    65  // 	fx.Provide(myservicefx.Client("myservice"))
    66  //
    67  // The Fx package also provides an UberFx-compatible constructor for
    68  // registering service procedures. This expects an instance of the service
    69  // interface to be available in the container and provides the list of
    70  // procedures resulting from that to the "yarpcfx" value group.
    71  //
    72  // 	fx.Provide(
    73  // 		myservicefx.Server(),
    74  // 		NewMyServiceHandler,  // func(...) myserviceserver.Interface
    75  // 	)
    76  //
    77  // Automatically Building Clients
    78  //
    79  // All clients generated by the YARPC ThriftRW plugin are compatible with
    80  // YARPC's yarpc.InjectClients function.
    81  //
    82  // 	var handler struct{ Client keyvalueclient.Interface `service:"keyvalue"` }
    83  // 	yarpc.Injectclients(dispatcher, &handler)
    84  //
    85  // These clients may further be customized by providing a "thrift" tag. The
    86  // following options may be provided on the tag using a comma-separated list.
    87  //
    88  // 	enveloped:   Requests and responses will be wrapped inside a standard
    89  // 	             Apache Thrift envelope. This flag is needed to call existing
    90  // 	             Apache Thrift services with clients generated by YARPC.
    91  // 	             Equivalent to passing thrift.Enveloped.
    92  // 	multiplexed: Requests are being sent to an Apache Thrift server which has
    93  // 	             multiplexing enabled. Equivalent to passing
    94  // 	             thrift.Multiplexed. This option has no effect if enveloped
    95  // 	             was not set.
    96  //
    97  // For example,
    98  //
    99  // 	type handler struct {
   100  // 		Client keyvalueclient.Interface `service:"keyvalue" thrift:"multiplexed,enveloped"`
   101  // 	}
   102  //
   103  // 	var h handler
   104  // 	yarpc.Injectclients(dispatcher, &h)
   105  //
   106  // Calling Existing Apache Thrift Services
   107  //
   108  // You can call existing Apache Thrift services with YARPC by passing in the
   109  // thrift.Enveloped option when constructing the corresponding clients.
   110  //
   111  // 	client := myserviceclient.New(dispatcher.ClientConfig("myservice"), thrift.Enveloped)
   112  //
   113  // With yarpc.InjectClients, you can pass the tag `thrift:"enveloped"` to
   114  // enable this option on automatically instantiated clients.
   115  //
   116  // 	type handler struct {
   117  // 		Client myserviceclient.Interface `service:"myservice" thrift:"enveloped"`
   118  // 	}
   119  //
   120  // 	var h handler
   121  // 	yarpc.InjectClients(dispatcher, &h)
   122  //
   123  // Automatically Sanitizing TChannel Contexts
   124  //
   125  // Contexts created with `tchannel.ContextWithHeaders` are incompatible with YARPC clients generated from Thrift.
   126  // Using such a context will cause a YARPC client to error on any call. Using the `sanitize-tchannel` flag will
   127  // generate a YARPC client such that all TChannel headers from any context supplied are removed before making a YARPC call.
   128  // The option can be used like so:
   129  //
   130  // 	thriftrw --plugin "yarpc --sanitize-tchannel" myservice.thrift
   131  package thrift