chore(*): update plugin default options && add examples

Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
storyicon 2021-07-28 11:57:21 +08:00
parent bc28762992
commit 4f4006ee7d
No known key found for this signature in database
GPG key ID: 245915D985F966CF
18 changed files with 342 additions and 10 deletions

View file

@ -160,6 +160,7 @@ powerproto env
## Examples
For example, you have the following file structure in the `/mnt/data/hello` directory:
```
@ -234,6 +235,9 @@ $POWERPROTO_HOME/protoc/3.17.3/protoc --go_out=. \
/mnt/data/hello/apis/hello.proto
```
More examples can be found in `https://github.com/storyicon/powerproto/tree/master/examples`.
## Config File
The config file is used to describe the versions of various dependencies and parameters when compiling the proto file.

View file

@ -223,6 +223,9 @@ $POWERPROTO_HOME/protoc/3.17.3/protoc --go_out=. \
/mnt/data/hello/apis/hello.proto
```
更多的例子可以参考 `https://github.com/storyicon/powerproto/tree/master/examples`.
## 配置文件
配置文件用于描述编译proto文件时各种依赖的版本以及参数等。

View file

@ -15,8 +15,6 @@
package build
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
@ -113,7 +111,6 @@ func CommandInit(log logger.Logger) *cobra.Command {
config.Options = append(config.Options, plugin.Options...)
}
}
fmt.Println(">>>>>>>>>>>>>>", preference.Repositories)
for _, val := range preference.Repositories {
if repo, ok := GetRepositoryFromOptionsValue(val); ok {
config.Repositories[repo.Name] = repo.Pkg

View file

@ -69,6 +69,7 @@ func GetWellKnownPlugins() []*Plugin {
Pkg: "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest",
Options: []string{
"--grpc-gateway_out=.",
"--grpc-gateway_opt=paths=source_relative",
},
},
{
@ -91,14 +92,16 @@ func GetWellKnownPlugins() []*Plugin {
Name: "protoc-gen-gogo",
Pkg: "github.com/gogo/protobuf/protoc-gen-gogo@latest",
Options: []string{
"--gogo_out=.",
"--gogo_out=plugins=grpc:.",
"--gogo_opt=paths=source_relative",
},
},
{
Name: "protoc-gen-gofast",
Pkg: "github.com/gogo/protobuf/protoc-gen-gofast@latest",
Options: []string{
"--gofast_out=.",
"--gofast_out=plugins=grpc:.",
"--gofast_opt=paths=source_relative",
},
},
{

View file

@ -0,0 +1,26 @@
# Greeter
This is the simplest grpc example, which does not reference any external grpc libraries.
The following plug-ins are used:
* [protoc-gen-go](google.golang.org/protobuf/cmd/protoc-gen-go)
* [protoc-gen-go-grpc](google.golang.org/grpc/cmd/protoc-gen-go-grpc)
You can compile the proto file in this directory by executing the following command:
```
powerproto build -r ./apis
```
Not surprisingly, you will get the following output:
```
➜ tree
.
├── README.md
├── apis
│   ├── greeter.pb.go
│   ├── greeter.proto
│   └── greeter_grpc.pb.go
└── powerproto.yaml
1 directory, 5 files
```

View file

@ -0,0 +1,16 @@
syntax = "proto3";
package powerproto.examples.greeter;
option go_package = "github.com/storyicon/powerproto/examples/greeter/apis;apis";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}

View file

@ -0,0 +1,22 @@
scopes:
- ./
protoc: v3.17.3
protocWorkDir: ""
plugins:
protoc-gen-go: google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
protoc-gen-go-grpc: google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
repositories:
GOOGLE_APIS: https://github.com/googleapis/googleapis@75e9812478607db997376ccea247dd6928f70f45
options:
- --go_out=.
- --go_opt=paths=source_relative
- --go-grpc_out=.
- --go-grpc_opt=paths=source_relative
importPaths:
- .
- $GOPATH
- $POWERPROTO_INCLUDE
- $SOURCE_RELATIVE
- $GOOGLE_APIS/github.com/googleapis/googleapis
postActions: []
postShell: ""

View file

@ -0,0 +1,28 @@
# Using GoGo
This example uses the following public libraries:
* [googleapis](https://github.com/googleapis/googleapis)
* [gogoproto](https://github.com/gogo/protobuf/tree/master/gogoproto)
The following plug-ins are used:
* [protoc-gen-gogo](github.com/gogo/protobuf/protoc-gen-gogo)
* [protoc-gen-grpc-gateway](github.com/grpc-ecosystem/grpc-gateway)
You can compile the proto file in this directory by executing the following command:
```
powerproto build -r ./apis
```
Not surprisingly, you will get the following output:
```
➜ tree
.
├── README.md
├── apis
│   ├── service.pb.go
│   ├── service.pb.gw.go
│   └── service.proto
└── powerproto.yaml
1 directory, 5 files
```

View file

@ -0,0 +1,40 @@
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/api/annotations.proto";
package powerproto.examples.using_gogo;
option go_package = "github.com/storyicon/powerproto/examples/using_gogo/apis;apis";
option java_multiple_files = true;
option java_package = "com.powerproto.examples.using_gogo";
option objc_class_prefix = "BAPIMetadata";
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.goproto_registration) = true;
service Mocker {
rpc Echo (EchoRequest) returns (EchoResponse) {
option (google.api.http) = {
post: "/echo"
body: "*"
};
};
}
message EchoRequest {
string message = 1;
int64 timestamp = 2;
uint32 code = 3;
uint32 delay = 4;
}
message EchoResponse {
string message = 1;
int64 timestamp = 2;
string server = 3;
}

View file

@ -0,0 +1,24 @@
scopes:
- ./
protoc: v3.17.3
protocWorkDir: ""
plugins:
protoc-gen-gogo: github.com/gogo/protobuf/protoc-gen-gogo@v1.3.2
protoc-gen-grpc-gateway: github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.5.0
repositories:
GOGO_PROTOBUF: https://github.com/gogo/protobuf@226206f39bd7276e88ec684ea0028c18ec2c91ae
GOOGLE_APIS: https://github.com/googleapis/googleapis@75e9812478607db997376ccea247dd6928f70f45
options:
- --grpc-gateway_out=.
- --grpc-gateway_opt=paths=source_relative
- --gogo_out=plugins=grpc:.
- --gogo_opt=paths=source_relative
importPaths:
- .
- $GOPATH
- $POWERPROTO_INCLUDE
- $SOURCE_RELATIVE
- $GOOGLE_APIS/github.com/googleapis/googleapis
- $GOGO_PROTOBUF
postActions: []
postShell: ""

View file

@ -0,0 +1,28 @@
# Using GoGoFast
This example uses the following public libraries:
* [googleapis](https://github.com/googleapis/googleapis)
* [gogoproto](https://github.com/gogo/protobuf/tree/master/gogoproto)
The following plug-ins are used:
* [protoc-gen-gofast](github.com/gogo/protobuf/protoc-gen-gofast)
* [protoc-gen-grpc-gateway](github.com/grpc-ecosystem/grpc-gateway)
You can compile the proto file in this directory by executing the following command:
```
powerproto build -r ./apis
```
Not surprisingly, you will get the following output:
```
➜ tree
.
├── README.md
├── apis
│   ├── service.pb.go
│   ├── service.pb.gw.go
│   └── service.proto
└── powerproto.yaml
1 directory, 5 files
```

View file

@ -0,0 +1,40 @@
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/api/annotations.proto";
package powerproto.examples.using_gogo;
option go_package = "github.com/storyicon/powerproto/examples/using_gogo/apis;apis";
option java_multiple_files = true;
option java_package = "com.powerproto.examples.using_gogo";
option objc_class_prefix = "BAPIMetadata";
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.goproto_registration) = true;
service Mocker {
rpc Echo (EchoRequest) returns (EchoResponse) {
option (google.api.http) = {
post: "/echo"
body: "*"
};
};
}
message EchoRequest {
string message = 1;
int64 timestamp = 2;
uint32 code = 3;
uint32 delay = 4;
}
message EchoResponse {
string message = 1;
int64 timestamp = 2;
string server = 3;
}

View file

@ -0,0 +1,24 @@
scopes:
- ./
protoc: v3.17.3
protocWorkDir: ""
plugins:
protoc-gen-gofast: github.com/gogo/protobuf/protoc-gen-gofast@v1.3.2
protoc-gen-grpc-gateway: github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.5.0
repositories:
GOGO_PROTOBUF: https://github.com/gogo/protobuf@226206f39bd7276e88ec684ea0028c18ec2c91ae
GOOGLE_APIS: https://github.com/googleapis/googleapis@75e9812478607db997376ccea247dd6928f70f45
options:
- --grpc-gateway_out=.
- --grpc-gateway_opt=paths=source_relative
- --gofast_out=plugins=grpc:.
- --gofast_opt=paths=source_relative
importPaths:
- .
- $GOPATH
- $POWERPROTO_INCLUDE
- $SOURCE_RELATIVE
- $GOOGLE_APIS/github.com/googleapis/googleapis
- $GOGO_PROTOBUF
postActions: []
postShell: ""

View file

@ -0,0 +1,29 @@
# Using Googleapis
This example uses the following public libraries:
* [googleapis](https://github.com/googleapis/googleapis)
The following plug-ins are used:
* [protoc-gen-go](google.golang.org/protobuf/cmd/protoc-gen-go)
* [protoc-gen-go-grpc](google.golang.org/grpc/cmd/protoc-gen-go-grpc)
* [protoc-gen-grpc-gateway](github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway)
You can compile the proto file in this directory by executing the following command:
```
powerproto build -r ./apis
```
Not surprisingly, you will get the following output:
```
➜ tree
.
├── README.md
├── apis
│   ├── service.pb.go
│   ├── service.pb.gw.go
│   ├── service.proto
│   └── service_grpc.pb.go
└── powerproto.yaml
1 directory, 6 files
```

View file

@ -0,0 +1,28 @@
syntax = "proto3";
package powerproto.examples.using_googleapis;
option go_package = "github.com/storyicon/powerproto/examples/using_googleapis/apis;apis";
import "google/api/annotations.proto";
service Mocker {
rpc Echo (EchoRequest) returns (EchoResponse) {
option (google.api.http) = {
post: "/echo"
body: "*"
};
};
}
message EchoRequest {
string message = 1;
int64 timestamp = 2;
uint32 code = 3;
uint32 delay = 4;
}
message EchoResponse {
string message = 1;
int64 timestamp = 2;
string server = 3;
}

View file

@ -0,0 +1,25 @@
scopes:
- ./
protoc: v3.17.3
protocWorkDir: ""
plugins:
protoc-gen-go: google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
protoc-gen-go-grpc: google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
protoc-gen-grpc-gateway: github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.5.0
repositories:
GOOGLE_APIS: https://github.com/googleapis/googleapis@75e9812478607db997376ccea247dd6928f70f45
options:
- --go_out=.
- --go_opt=paths=source_relative
- --go-grpc_out=.
- --go-grpc_opt=paths=source_relative
- --grpc-gateway_out=.
- --grpc-gateway_opt=paths=source_relative
importPaths:
- .
- $GOPATH
- $POWERPROTO_INCLUDE
- $SOURCE_RELATIVE
- $GOOGLE_APIS/github.com/googleapis/googleapis
postActions: []
postShell: ""

2
go.mod
View file

@ -20,9 +20,7 @@ require (
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/rs/zerolog v1.23.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vbauerster/mpb/v7 v7.0.3
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect

3
go.sum
View file

@ -327,9 +327,6 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g=
github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=