ameliaikeda / protoc-gen-router

(WIP) Generate a router from protobuf files for microservices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protoc-gen-router

protoc-gen-router generates routers from protobuf messages.

Currently supported:

  • Go

In-progress:

  • Python
  • Java
  • Node

Usage

syntax = "proto3";
import "github.com/ameliaikeda/protoc-gen-router/proto/router.proto";

servicee myservice {
    option (router).name = "service.foo";
    option (router).short_name = "s-foo";
    
    rpc GETReadUser(GETReadUserRequest) returns (GETReadUSerResponse) {
        option (handler).method = "GET"; // optional with name
        option (handler).path = "/user/read";
    }
}

message GETReadUserRequest {
    string id = 1;
}
message GETReadUserResponse {
    User user = 1;
}

message User {
    string id = 1;
}

Now, when you get to code, requesting is pretty easy.

package main

import (
	userproto "mymodule/user/proto"
)

func main() {
	ctx := context.TODO()
    rsp, err := userproto.GETReadUserRequest{
    	Id: "foo",
    }.Response(ctx)
    if err != nil {
    	panic(err)
    }
    
    // rsp.User
}

About

(WIP) Generate a router from protobuf files for microservices.


Languages

Language:Go 100.0%