Skip to content

layotto/protoc-gen-p6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protoc-gen-p6

p6 is a protoc plugin.

She is good at coding and writes code for Layotto project.

p6 works hard.

Can you give cute p6 a star ⭐️?

各位哥哥,可以给可爱的 p6 一个star ⭐️吗?

お兄ちゃん、かわいいp6に星⭐️をつけてくれる?

Install

Please make sure you have tools below:

Go version >= 1.16

go install github.com/layotto/protoc-gen-p6@latest

How to give p6 new work

Suppose you have a new proto file example/api/product/app/v1/blog.proto , and you want to implement this API in Layotto .

It's a tedious job because you have to write lots of boring code. You don't want to do it yourself.

Then you can ask p6 to do it. For example:

protoc -I ./example/api \
      --go_out ./example/api --go_opt=paths=source_relative \
      --go-grpc_out=./example/api \
      --go-grpc_opt=require_unimplemented_servers=false,paths=source_relative \
      --p6_out ./example/api --p6_opt=paths=source_relative \
      example/api/product/app/v1/blog.proto

or, you can give her an example work by:

make work.example

And p6 will write the code very quickly:

image

You can then move these code to Layotto project.

Master's commands

You can give "master's commands" to p6 by adding special comments in your .proto files.

The commands tell p6 how to handle the files. They need to be written in comments, starting with @exclude .

Here is the list of commands:

skip quickstart_generator

If you don't want to generate quickstart docs for the proto file, add a command /* @exclude skip quickstart_generator */ in it.

skip code_generator

If you don't want to generate sdk & sidecar code for the proto file, add a command /* @exclude skip code_generator */ in it.

For example:

/* @exclude skip quickstart_generator */
/* @exclude skip code_generator */
// ObjectStorageService is an abstraction for blob storage or so called "object storage", such as alibaba cloud OSS, such as AWS S3.
// You invoke ObjectStorageService API to do some CRUD operations on your binary file, e.g. query my file, delete my file, etc.
service ObjectStorageService{
  //......
}

skip sdk_generator

If you don't want to generate golang-sdk code for the proto file, add a command /* @exclude skip sdk_generator */ in it.

skip ci_generator

If you don't want to generate CI configuration for the proto file, add a command /* @exclude skip ci_generator */ in it.

extends xxx

If you want to add new methods to an existing API, you can use this command.

Let's say you want to add a PublishTransactionalMessage method to pubsub API. You write a new proto file example/api/product/app/v1/advanced_queue.proto and then add a command /* @exclude extends pub_subs */ in it:

/* @exclude extends pub_subs */
// AdvancedQueue is advanced pubsub API
service AdvancedQueue {

  rpc PublishTransactionalMessage(TransactionalMessageRequest) returns (TransactionalMessageResponse);

}

message TransactionalMessageRequest {
  string store_name = 1;

  string content = 2;
}

message TransactionalMessageResponse {
  string message_id = 1;
}

You can generate code for it:

protoc -I ./example/api \
          --go_out ./example/api --go_opt=paths=source_relative \
          --go-grpc_out=./example/api \
          --go-grpc_opt=require_unimplemented_servers=false,paths=source_relative \
          --p6_out ./example/api --p6_opt=paths=source_relative \
          example/api/product/app/v1/advanced_queue.proto

The generated code is an extension of the pubsub API.

Talk with p6

talk with p6 in chinese

About

p6 is a protoc plugin. She is good at coding and writes code for Layotto project. p6 works hard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published