Giter VIP home page Giter VIP logo

lazyrpc's Introduction

Disclaimer: this is just a thing I slapped together, this is not supported and is just for fun. Try it out though!

lazyrpc

This is a protoc plugin that generates a basic CRUD service proto for messages of the input protos. I made this because I was tired of writing the same boilerplate request/response messages and service methods for simple APIs.

I also wanted to play around with the rich descriptor facilities of protoreflect in the context of building a protoc plugin.

Using lazyrpc

Install

You can either install the plugin directly:

$ go get github.com/noahdietz/lazyrpc/cmd/protoc-gen-lazyrpc

Or build it from source:

$ cd $GOPATH/src
$ mkdir -p github.com/noahdietz
$ cd github.com/noahdietz
$ git clone https://github.com/noahdietz/lazyrpc.git
$ cd lazyrpc/cmd/protoc-gen-lazyrpc
$ go get
$ go install 

Configuration Options

The configuration of lazyrpc generation is defined using proto Message options. The option available options are as follows:

  • Methods: a list of methods to generate for this message's service
    • Supported methods are: CREATE, GET, LIST, UPDATE, DELETE
  • Key: a single field name for use as a key in get & delete methods.
    • Omission of this phrase results in the entire message being used as input

Example:

import "lazy.proto"

...

message Todo {
  option (lazy.config) = {
    methods: [CREATE, GET, LIST, UPDATE, DELETE]
    key: "id"
  };
  
  int32 id = 1;
  string task = 2;
  bool done = 3;
}

A message without a lazy.config.methods field will be ignored entirely.

The extension defintion can be found in proto/lazy.proto.

The compiled Go definition can be imported as github.com/noahdietz/lazyrpc/config and found in config/lazy.pb.go.

Invocation

Invoke the plugin like any other protoc plugin:

export LAZY_RPC_PROTOS=$GOPATH/src/github.com/noahdietz/lazyrpc/protos
$ protoc -I $LAZY_RPC_PROTOS -I my/protos/ --lazyrpc_out my/protos/ my/protos/a.proto

Output

A proto file is created for each input proto, containing all of the services & request/response messages for the messages defined & configured in the input.

This generated proto file takes the name {input file}_service.proto. For example, using todo.proto as input, a todo_service.proto file is generated.

Note: currently, files will be overwritten

Looking forward

In the future, lazyrpc could support:

  • configuration for streaming method generation
  • plugin option to signal merging of services/messages as an alternative to overwritting existing files

lazyrpc's People

Contributors

noahdietz avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.