Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c6caa0d3ac | |||
5ecc4986dd | |||
9ed1ca9a89 | |||
805b52cf8d |
@@ -15,8 +15,9 @@ $> protoc --micro_out=debug=true,components="micro|http":. input.proto
|
||||
|
||||
| Option | Default Value | Accepted Values | Description
|
||||
|-----------------------|---------------|---------------------------|-----------------------
|
||||
| `tag_path` | `.` | `any local path` | path contains generated protobuf code that needs to be tagged
|
||||
| `debug` | *false* | `true` or `false` | if *true*, `protoc` will generate a more verbose output
|
||||
| `components` | `micro` | `micro rpc http chi gorilla` | some values cant coexists like gorilla/chi or rpc/http, values must be concatinated with pipe symbol
|
||||
| `components` | `micro` | `micro rpc http chi gorilla client server` | some values can't coexists like gorilla/chi or rpc/http, values must be concatinated with pipe symbol
|
||||
|
||||
## Install
|
||||
|
||||
|
8
ast.go
8
ast.go
@@ -20,6 +20,9 @@ var (
|
||||
)
|
||||
|
||||
func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
if g.tagPath == "" {
|
||||
return nil
|
||||
}
|
||||
for _, file := range plugin.Files {
|
||||
if !file.Generate {
|
||||
continue
|
||||
@@ -41,7 +44,10 @@ func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
if !ok {
|
||||
mp = make(map[string]map[string]*structtag.Tags)
|
||||
}
|
||||
nmp := make(map[string]*structtag.Tags)
|
||||
nmp, ok := mp[message.GoIdent.GoName]
|
||||
if !ok {
|
||||
nmp = make(map[string]*structtag.Tags)
|
||||
}
|
||||
tags, err := structtag.Parse(opts.(string))
|
||||
if err != nil {
|
||||
return err
|
||||
|
44
example/example.proto
Normal file
44
example/example.proto
Normal file
@@ -0,0 +1,44 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package example;
|
||||
|
||||
option go_package = "github.com/unistack-org/protoc-gen-micro/v3/example;examplepb";
|
||||
|
||||
import "tag/tag.proto";
|
||||
import "api/annotations.proto";
|
||||
import "openapiv2/annotations.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
service Example {
|
||||
rpc Call(CallReq) returns (CallRsp) {
|
||||
option (micro.openapiv2.openapiv2_operation) = {
|
||||
operation_id: "Call";
|
||||
responses: {
|
||||
key: "default";
|
||||
value: {
|
||||
description: "Error response";
|
||||
schema: {
|
||||
json_schema: {
|
||||
ref: ".example.Error";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
option (micro.api.http) = { post: "/v1/example/call/{name}"; body: "*"; };
|
||||
option (micro.api.micro_method) = { timeout: 5; };
|
||||
};
|
||||
};
|
||||
|
||||
message CallReq {
|
||||
string name = 1 [(micro.tag.tags) = "xml:\",attr\"" ];
|
||||
string req = 2;
|
||||
};
|
||||
|
||||
message CallRsp {
|
||||
string rsp = 2;
|
||||
};
|
||||
|
||||
message Error {
|
||||
string msg = 1;
|
||||
};
|
2
main.go
2
main.go
@@ -13,7 +13,7 @@ var (
|
||||
flagDebug = flag.Bool("debug", false, "")
|
||||
flagStandalone = flag.Bool("standalone", false, "")
|
||||
flagComponents = flag.String("components", "micro|rpc|http|client|server", "")
|
||||
flagTagPath = flag.String("tag_path", ".", "")
|
||||
flagTagPath = flag.String("tag_path", "", "")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
Reference in New Issue
Block a user