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に星⭐️をつけてくれる?
Please make sure you have tools below:
Go version >= 1.16
go install github.com/layotto/protoc-gen-p6@latest
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:
You can then move these code to Layotto project.
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:
If you don't want to generate quickstart docs for the proto file, add a command /* @exclude skip quickstart_generator */
in it.
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{
//......
}
If you don't want to generate golang-sdk code for the proto file, add a command /* @exclude skip sdk_generator */
in it.
If you don't want to generate CI configuration for the proto file, add a command /* @exclude skip ci_generator */
in it.
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.