A protoc-gen-go wrapper including an RPC stub generator

Related tags

Network go-rpcgen
Overview
// Copyright 2013 Google. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

// The go-rpcgen project is an attempt to create an easy-to-use, open source
// protobuf service binding for the standard Go RPC package.  It provides a
// protoc-gen-go (based on the standard "main" from goprotobuf and leveraging
// its libraries) which has a plugin added to also output RPC stub code.
//
// Prerequisites
//
// You will need the protobuf compiler for your operating system of choice.
// You can retrieve this from http://code.google.com/p/protobuf/downloads/list
// if you do not have it already.  As this package builds a plugin for the
// protoc from that package, you will need to have your $GOPATH/bin in your
// path when you run protoc.
//
// Installation
//
// To install, run the following command:
//   go get -v -u github.com/kylelemons/go-rpcgen/protoc-gen-go
//
// Usage
//
// Usage of the package is pretty straightforward.  Once you have installed the
// protoc-gen-go plugin, you can compile protobufs with the following command
// (where file.proto is the protocol buffer file(s) in question):
//   protoc --go_out=. file.proto
//
// This will generate a file named like file.pb.go which contains, in addition
// to the usual Go bindings for the messages, an interface for each service
// containing the methods for that service and functions for creating and using
// them with the RPC package and a webrpc package.
//
// Configuration
//
// By default, protoc-gen-go will generate both RPC and web-based stubs,
// but this can be configured by setting the GO_STUBS environment variable.
// This variable is a comma-separated list of the stubs to generate.  The known
// stubs are:
//
//   rpc // Generate stubs for net/rpc
//   web // Generate stubs for direct HTTP access, e.g. via AppEngine
//
// Generated Code for RPC
//
// Given the following basic .proto definition:
//
//   package echoservice;
//   message payload {
//       required string message = 1;
//   }
//   service echo_service {
//       rpc echo (payload) returns (payload);
//   }
//
// The protoc-gen-go plugin will generate a service definition similar to below:
//
//   // EchoService is an interface satisfied by the generated client and
//   // which must be implemented by the object wrapped by the server.
//   type EchoService interface {
//       Echo(in *Payload, out *Payload) error
//   }
//
//   // DialEchoService returns a EchoService for calling the EchoService servince.
//   func DialEchoService(addr string) (EchoService, error) {
//
//   // NewEchoServiceClient returns an *rpc.Client wrapper for calling the methods
//   // of EchoService remotely.
//   func NewEchoServiceClient(conn net.Conn) EchoService
//
//   // ListenAndServeEchoService serves the given EchoService backend implementation
//   // on all connections accepted as a result of listening on addr (TCP).
//   func ListenAndServeEchoService(addr string, backend EchoService) error
//
//   // ServeEchoService serves the given EchoService backend implementation on conn.
//   func ServeEchoService(conn net.Conn, backend EchoService) error
//
// Any type which implements EchoService can thus be registered via ServeEchoService
// or ListenAndServeEchoService to be called remotely via NewEchoServiceClient or
// DialEchoService.
//
// Generated Code for WebRPC
//
// In addition to the above, the following are also generated to facilitate
// serving RPCs over the web (e.g. AppEngine; see example_ae/):
//
//   // EchoServiceWeb is the web-based RPC version of the interface which
//   // must be implemented by the object wrapped by the webrpc server.
//   type EchoServiceWeb interface {
//     Echo(r *http.Request, in *Payload, out *Payload) error
//   }
//
//   // NewEchoServiceWebClient returns a webrpc wrapper for calling EchoService
//   // remotely via the web.  The remote URL is the base URL of the webrpc server.
//   func NewEchoServiceWebClient(remote *url.URL, pro webrpc.Protocol) EchoService
//
//   // Register a EchoServiceWeb implementation with the given webrpc ServeMux.
//   // If mux is nil, the default webrpc.ServeMux is used.
//   func RegisterEchoServiceWeb(this EchoServiceWeb, mux webrpc.ServeMux) error
//
// Any type which implements EchoServiceWeb (notice that the handlers also
// receive the *http.Request) can be registered.  The RegisterEchoServiceWeb
// function registers the given backend implementation to be called from the
// web via the webrpc package.
//
// Examples
//
// See the examples/ subdirectory for some complete examples demonstrating
// basic usage.  See the example_ae/ subdirectory for an appengine example and
// for directions about how to deploy go-rpcgen on appengine.
//
// Acknowledgements
//
// Thanks to the following people:
//   Bill Broadley <[email protected]> - for beta testing and examples
package rpcgendoc
Comments
  • Error with errors

    Error with errors

    Changed the WriteResponse function to always write the header, and conditionally write a body if there is no error in the rpc.Response.

    Changed the ReadResponseBody to not attempt to read the object if it is nil, as the net/rpc Client passes a nil object on error and when there is no pending call (http://golang.org/src/pkg/net/rpc/client.go line

    opened by pguelpa 3
  • Cleaned up the add + TLS example.

    Cleaned up the add + TLS example.

    I added "example/add", cleaned it up, and added a readme.

    It does run as is on my system. I think it's useful as is, but am interested in any improvements/suggestions you have.

    Nothing changed outside of example/add.

    opened by spikebike 2
  • Can't return `error` from service

    Can't return `error` from service

    While building out a system using this library (thank you for providing it by the way) I noticed that I was unable to return errors, the system just hangs. A cursory look at the code didn't give me any suggestions as to why, it looks to me like the codec is doing the right thing. I've created a basic example using the AddService that you provided to show what happens: https://github.com/pguelpa/go-rpcgen/tree/error-with-errors

    Any idea on why this might be happening? I'll continue to try and debug it as well.

    opened by pguelpa 1
  • Hook to be called with the body of every new request

    Hook to be called with the body of every new request

    I have not been able to find any extensibility point to the codec to be able to read the body of every new request. I have implemented this logic which fulfills our needs.

    Feel free to close this pull request if you don't find it useful, or provide some guidelines if the fic can be improved in any way.

    opened by acasas 0
  • Extra SSL demo for go-rpcgen

    Extra SSL demo for go-rpcgen

    I made all the changes I could find. Hopefully this is cleaner. It's all been goformatted.

    Logging messages have been reorganized and occur in less statements.

    Readme is formatter nicer and is clearer.

    Server, client, and AddService have been organized like the others.

    Relative imports have been fixed.

    I've done this from the $GOPATH/serv/github.com/kylelemons/go-rpcgen dir so the naming matching.

    opened by spikebike 0
  • New example for AddService (sum 2 numbers), and a failed example with TLS + AddService.

    New example for AddService (sum 2 numbers), and a failed example with TLS + AddService.

    It's a bit complicated. First I have an unrelated server/client example that uses TLS: https://gist.github.com/2233075

    To test/run: ./mkcerts [email protected] go run server.go

    In another terminal: go run client.go

    Now a working example, much like your echo, just slightly more complicated: https://gist.github.com/2300125

    It compiles/runs just like go-rpcgen's echo.

    Now I tried to merge the two: https://gist.github.com/2300144

    So basically I merged my TLS code and the Add Example code.

    In add.go (the server) instead of calling ListenAndServeAddService with connection information I call NewAddServiceClient with my connection.

    In client.go (the client) instead of calling DialAddService I call NewAddServiceClient with my connection.

    I do wonder if my code that's mostly dealing with a TLS.conn is compatible with go-rpcgen code which seems to be expecting a net.conn.

    Any ideas?

    opened by spikebike 0
  • Misc. Improvements and Customizations

    Misc. Improvements and Customizations

    Wanted to see if there's anything you'd like to reintegrate here, and to just get and feedback you might have on approach, etc., with the new features.

    I'm mostly interested in seeing the client stuff land as the existing client stuff is a little weak for (real) production use.

    Features

    1. Connection pooling for RPC clients, making connections between services much more robust.
    2. Support for "void" RPC calls

    Minor improvements

    1. Move everything to new protobuf upstream.

    Happy to hear any feedback you might have and to pull out specific pieces. Particularly, the references to my fork (github.com/bradhe/...) could be problematic--if you're in to any of this stuff I'd be happy to issue another commit that reverts it back to mainline.

    opened by bradhe 1
protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript clients that connect the web frontend and golang backend fronted by grpc-gateway.

protoc-gen-grpc-gateway-ts protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript

gRPC Ecosystem 94 Dec 19, 2022
A Twirp RPC OpenAPI generator implemented as `protoc` plugin

twirp-openapi-gen A Twirp RPC OpenAPI generator implemented as protoc plugin Currently supports only OpenAPI 2.0 Usage Installing the generator for pr

Albenik's Golang Projects 1 May 26, 2022
gRPC merupakan metode pendistribusian data melalui sebuah protofile atau stub.

gRPC Definisi gRPC merupakan metode pendistribusian data melalui sebuah protofile atau stub. Kenapa Harus Belajar gRPC? Lebih simple dibanding REST da

Fany Ervansyah 0 Feb 13, 2022
Antenna RPC is an RPC protocol for distributed computing, it's based on QUIC and Colfer. its currently an WIP.

aRPC - Antenna Remote Procedure Call Antenna remote procedure call (aRPC) is an RPC protocol focused on distributed processing and HPC. aRPC is implem

Raphael de Carvalho Almeida 3 Jun 16, 2021
rpc/v2 support for JSON-RPC 2.0 Specification.

rpc rpc/v2 support for JSON-RPC 2.0 Specification. gorilla/rpc is a foundation for RPC over HTTP services, providing access to the exported methods of

High Performance, Kubernetes Native Object Storage 3 Jul 4, 2021
Go Substrate RPC Client (GSRPC)Go Substrate RPC Client (GSRPC)

Go Substrate RPC Client (GSRPC) Substrate RPC client in Go. It provides APIs and types around Polkadot and any Substrate-based chain RPC calls. This c

Chino Chang 1 Nov 11, 2021
protobuf ではなく JSON でやり取りするファイルを出力する protoc プラグイン

protoc-gen-jsonif proto ファイルから、JSON フォーマットでやりとりする型定義ファイルを出力する protoc プラグインです。 proto ファイルで言語を越えて型定義が出来るのはとても良い しかし protobuf ライブラリを入れるのが面倒 今のプロジェクトには既に

melpon 3 Feb 28, 2022
🎉 An awesome version control tool for protoc and its related plugins.

❤️ PowerProto is actively maintained! Any questions in use can be directly raised issue, I will respond to you as fast as possible. If you think the p

storyicon 165 Dec 29, 2022
Protoc plugin to generate contract tests for gRPC in Go

Deal - Go Introduction WE DO NOT SUPPORT THE SERVER SIDE YET This plugin allows us to write Consumer-Driver Contracts tests! Usage example Proto servi

Faunists 15 Sep 3, 2022
A plugin of protoc that for using a service of Protocol Buffers as http.Handler definition

protoc-gen-gohttp protoc-gen-gohttp is a plugin of protoc that for using a service of Protocol Buffers as http.Handler definition. The generated inter

John_Suu 1 Dec 9, 2021
Protoc plugin used to generate go-kit grpc code

protoc-gen-gokit-endpoint protoc plugin used to generate go-kit grpc code 安装 go install github.com/wwbweibo/protoc-gen-gokit-endpoint/cmd/protoc-gen-g

wangweibo 4 Sep 29, 2022
Protoc plugin used to generate go-kit grpc code

protoc-gen-gokit-endpoint protoc plugin used to generate go-kit grpc code 安装 go

wangweibo 4 Sep 29, 2022
pb: a tool for managing protoc builds and dependencies

pb pb is a Protocol Buffers Build tool that manages dependencies and build confi

Dan Enman 3 Nov 20, 2022
The `protoc` compiler plugin which dumps the generation request details

Progotgen DUMP The protoc compiler plugin which dumps the generation request details in "google.golang.org/protobuf/compiler/protogen format to stderr

Albenik's Golang Projects 0 Jan 23, 2022
Just another "what is my IP address" service, including geolocation and headers information

What is my IP address What is my IP address Features Endpoints Build Usage Examples Run a default TCP server Run a TLS (HTTP/2) server only Run a defa

dcarrillo 12 Nov 21, 2022
Simple, fast and scalable golang rpc library for high load

gorpc Simple, fast and scalable golang RPC library for high load and microservices. Gorpc provides the following features useful for highly loaded pro

Aliaksandr Valialkin 667 Dec 19, 2022
A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

Realtime API Gateway Synchronize Your Clients Visit Resgate.io for guides, live demos, and resources. Resgate is a Go project implementing a realtime

Resgate.io - Synchronize Your Clients 609 Dec 31, 2022
network multiplexing and framing protocol for RPC

TChannel Network multiplexing and framing protocol for RPC Read the Docs Languages: Node.js, Python, Go, Java Questions: Open a Github issue Uber's OS

Uber Open Source 1.2k Nov 26, 2022