go.uber.org/yarpc@v1.72.1/encoding/protobuf/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 protobuf implements Protocol Buffers encoding support for YARPC.
    22  //
    23  // To use this package, you must have protoc installed, as well as the
    24  // Golang protoc plugin from either github.com/golang/protobuf or
    25  // github.com/gogo/protobuf. We recommend github.com/gogo/protobuf.
    26  //
    27  //   go get github.com/gogo/protobuf/protoc-gen-gogoslick
    28  //
    29  // You must also install the Protobuf plugin for YARPC:
    30  //
    31  //   go get go.uber.org/yarpc/encoding/protobuf/protoc-gen-yarpc-go
    32  //
    33  // To generate YARPC compatible code from a Protobuf file, use the command:
    34  //
    35  //   protoc --gogoslick_out=. --yarpc-go_out=. foo.proto
    36  //
    37  // The Golang protoc plugin will generate the Golang types in foo.pb.go,
    38  // while the YARPC plugin will generate the YARPC types in foo.pb.yarpc.go.
    39  //
    40  // The client interface for a service named Bar will be generated with
    41  // the name BarYARPCClient, and can be instantiated with a
    42  // transport.ClientConfig.
    43  //
    44  //   barClient := foo.NewBarYARPCClient(dispatcher.ClientConfig("myservice"))
    45  //
    46  // The server interface will be generated with the name BarYARPCServer. This
    47  // is the interface that should be implemented on the server-side. Procedures
    48  // can be constructed from an implementation of BarYARPCServer using the
    49  // BuildBarYARPCProcedures method.
    50  //
    51  //   dispatcher.Register(foo.BuildBarYARPCProcedures(barServer))
    52  //
    53  // Proto3 defines a mapping to JSON, so for every RPC method, two Procedures
    54  // are created for every RPC method: one that will handle the standard Protobuf
    55  // binary encoding, and one that will handle the JSON encoding.
    56  //
    57  // If coupled with an HTTP Inbound, Protobuf procedures can be called using
    58  // curl. Given the following Protobuf definition:
    59  //
    60  //   syntax = "proto3;
    61  //
    62  //   package foo.bar;
    63  //
    64  //   message EchoRequest {
    65  //     string value = 1;
    66  //   }
    67  //
    68  //   message EchoResponse {
    69  //     string value = 1;
    70  //   }
    71  //
    72  //   service Baz {
    73  //     rpc Echo(EchoRequest) returns (EchoResponse) {}
    74  //   }
    75  //
    76  // And the following configuration:
    77  //
    78  //   service:
    79  //     name: hello
    80  //   yarpc:
    81  //     inbounds:
    82  //       http:
    83  //          address: ":8080"
    84  //
    85  // If running locally, one could make the following call:
    86  //
    87  //   curl \
    88  //     http://0.0.0.0:8080 \
    89  //     -H 'context-ttl-ms: 2000' \
    90  //     -H "rpc-caller: curl-$(whoami)" \
    91  //     -H 'rpc-service: hello' \
    92  //     -H 'rpc-encoding: json' \
    93  //     -H 'rpc-procedure: foo.bar.Baz::Echo' \
    94  //     -d '{"value":"sample"}'
    95  //
    96  // Where context-ttl-ms is the timeout in milliseconds, rpc-caller is the name of the entity making the request,
    97  // rpc-service is the name of the configured service, rpc-encoding is json, rpc-procedure is the name of the
    98  // Protobuf method being called in the form proto_package.proto_service::proto_method, and the data is the JSON
    99  // representation of the request.
   100  //
   101  // If using Yab, one can also use:
   102  //
   103  //   yab -p http://0.0.0.0:8080 -e json -s hello -p foo.bar.Baz::Echo -r '{"value":"sample"}'
   104  //
   105  // See https://github.com/yarpc/yab for more details.
   106  //
   107  // Except for any ClientOptions (such as UseJSON), the types and functions
   108  // defined in this package should not be directly used in applications,
   109  // instead use the code generated from protoc-gen-yarpc-go.
   110  package protobuf