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

Related tags

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
Issues
  • 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
  • webrpc does not build

    webrpc does not build

    protobuf interfaces have changed and webrpc is no longer buildable

    opened by vstech 1
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
A Protocol Buffers compiler that generates optimized marshaling & unmarshaling Go code for ProtoBuf APIv2

vtprotobuf, the Vitess Protocol Buffers compiler This repository provides the protoc-gen-go-vtproto plug-in for protoc, which is used by Vitess to gen

PlanetScale 262 Jul 23, 2021
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 25 Jul 21, 2021
Simple Web based configuration generator for WireGuard. Demo:

Wg Gen Web Simple Web based configuration generator for WireGuard. Why another one ? All WireGuard UI implementations are trying to manage the service

vx3r 572 Jul 23, 2021
A simple RPC framework with protobuf service definitions

Twirp is a framework for service-to-service communication emphasizing simplicity and minimalism. It generates routing and serialization from API defin

Twitch 4.9k Jul 21, 2021
A protoc-gen-go wrapper including an RPC stub generator

// 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 fi

Kyle Lemons 35 May 13, 2020
webrpc is a schema-driven approach to writing backend services for modern Web apps and networks

webrpc is a schema-driven approach to writing backend servers for the Web. Write your server's api interface in a schema format of RIDL or JSON, and t

null 378 Jul 16, 2021
Erda's infrastructure framework

Erda Infra Translations: English | 简体中文 Erda Infra is a lightweight microservices framework implements by golang, which offers many useful modules and

Erda 31 Jul 22, 2021
A new way of working with Protocol Buffers.

Buf All documentation is hosted at https://buf.build. Please head over there for more details. Goal Buf’s long-term goal is to enable schema-driven de

null 2.5k Jul 27, 2021
Easily generate gRPC services in Go ⚡️

Lile is a application generator (think create-react-app, rails new or django startproject) for gRPC services in Go and a set of tools/libraries. The p

Lile 1.3k Jul 18, 2021
A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

A pluggable "Application State Gateway" that enforces the Event Sourcing Pattern for securely persisting & broadcasting application state changes

null 24 Apr 15, 2021
Generate types and service clients from protobuf definitions annotated with http rules.

protoc-gen-typescript-http Generates Typescript types and service clients from protobuf definitions annotated with http rules. The generated types fol

Einride 14 Jul 7, 2021
Create a gRPC server from code generated by sqlc

sqlc-grpc Create a gRPC Server from the generated code by the awesome sqlc project. Dependencies Go 1.16 or superior protoc sqlc, protoc-gen-go and pr

Walter Wanderley 35 Jul 8, 2021
Create a gRPC Server from Database

xo-grpc Create a gRPC Server from the generated code by the xo project. Requirements Go 1.16 or superior protoc xo, protoc-gen-go and protoc-gen-go-gr

Walter Wanderley 17 Jun 23, 2021
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 637 Jul 7, 2021