Compare commits
6 Commits
v3
...
d6307cc251
| Author | SHA1 | Date | |
|---|---|---|---|
| d6307cc251 | |||
| e4433a0257 | |||
| 4f94497f82 | |||
| 3e1a0a83cf | |||
|
|
91c4cba229 | ||
|
|
76e6924d40 |
@@ -6,20 +6,24 @@ option go_package = "github.com/unistack-org/protoc-gen-go-micro/v3/example;exam
|
||||
|
||||
import "tag/tag.proto";
|
||||
import "api/annotations.proto";
|
||||
import "openapiv3/annotations.proto";
|
||||
//import "google/protobuf/wrappers.proto";
|
||||
import "graphql/graphql.proto";
|
||||
import "openapiv2/annotations.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
service Example {
|
||||
rpc Call(CallReq) returns (CallRsp) {
|
||||
option (micro.graphql.rpc) = {type: QUERY};
|
||||
option (micro.openapiv3.openapiv3_operation) = {
|
||||
option (micro.openapiv3.openapiv3_operation) = {
|
||||
operation_id: "Call";
|
||||
responses: {
|
||||
default: {
|
||||
reference: {_ref: ".example.Error"};
|
||||
};
|
||||
};
|
||||
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: "5s"; };
|
||||
@@ -27,7 +31,7 @@ service Example {
|
||||
};
|
||||
|
||||
message CallReq {
|
||||
string name = 1 [(micro.graphql.field) = {required: true}];
|
||||
string name = 1 [(micro.tag.tags) = "xml:\",attr\"" ];
|
||||
string req = 2;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
directive @Example on FIELD_DEFINITION
|
||||
input CallReqInput {
|
||||
name: String!
|
||||
req: String
|
||||
}
|
||||
type CallRsp {
|
||||
rsp: String
|
||||
}
|
||||
type Query {
|
||||
exampleCall(in: CallReqInput): CallRsp
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate sh -xc "protoc -I./example -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components=graphqls,graphql_file=./schema.graphql:./example example/example.proto"
|
||||
19
go.mod
19
go.mod
@@ -1,21 +1,10 @@
|
||||
module go.unistack.org/protoc-gen-go-micro/v3
|
||||
|
||||
go 1.24.0
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/fatih/structtag v1.2.0
|
||||
go.unistack.org/micro-proto/v3 v3.4.5
|
||||
golang.org/x/tools v0.42.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/gnostic v0.6.9 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/rogpeppe/go-internal v1.13.1 // indirect
|
||||
golang.org/x/mod v0.33.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
go.unistack.org/micro-proto/v3 v3.3.1
|
||||
golang.org/x/tools v0.1.9
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
||||
55
go.sum
55
go.sum
@@ -10,7 +10,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
@@ -38,9 +37,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=
|
||||
github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -48,26 +46,18 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
@@ -76,34 +66,37 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.unistack.org/micro-proto/v3 v3.4.5 h1:3ULfegE+DCnZYIjBxGe2u5NlOVruvxjkYBpf86N2pFM=
|
||||
go.unistack.org/micro-proto/v3 v3.4.5/go.mod h1:cV8qSOP9Z3Dztd+xOX8ijhERl3sBgvv2bcAPEMZfnWE=
|
||||
go.unistack.org/micro-proto/v3 v3.3.1 h1:nQ0MtWvP2G3QrpOgawVOPhpZZYkq6umTGDqs8FxJYIo=
|
||||
go.unistack.org/micro-proto/v3 v3.3.1/go.mod h1:cwRyv8uInM2I7EbU7O8Fx2Ls3N90Uw9UCCcq4olOdfE=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
||||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -112,19 +105,26 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
|
||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
|
||||
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
@@ -152,16 +152,15 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
9
http.go
9
http.go
@@ -38,15 +38,14 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
|
||||
}
|
||||
|
||||
for _, service := range file.Services {
|
||||
g.generateServiceEndpoints(gfile, service, component)
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, file, service, component)
|
||||
g.generateServiceClient(gfile, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
}
|
||||
if genServer {
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
generateServiceServer(gfile, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
g.generateServiceRegister(gfile, service, component)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
main.go
22
main.go
@@ -15,10 +15,9 @@ var (
|
||||
flagDebug = flagSet.Bool("debug", false, "debug output")
|
||||
flagStandalone = flagSet.Bool("standalone", false, "generate file to standalone dir")
|
||||
flagFieldaligment = flagSet.Bool("fieldaligment", false, "align struct fields in generated code")
|
||||
flagComponents = flagSet.String("components", "micro|rpc|http|client|server|openapiv3|graphql", "specify components to generate")
|
||||
flagComponents = flagSet.String("components", "micro|rpc|http|client|server|openapiv3", "specify components to generate")
|
||||
flagTagPath = flagSet.String("tag_path", "", "tag rewriting dir")
|
||||
flagOpenapiFile = flagSet.String("openapi_file", "apidocs.swagger.yaml", "openapi file name")
|
||||
flagGraphqlFile = flagSet.String("graphql_file", "schema.graphqls", "graphql file name")
|
||||
flagOpenapiFile = flagSet.String("openapi_file", "apidocs.swagger.json", "openapi file name")
|
||||
flagReflection = flagSet.Bool("reflection", false, "enable server reflection support")
|
||||
flagHelp = flagSet.Bool("help", false, "display help message")
|
||||
)
|
||||
@@ -28,7 +27,7 @@ func main() {
|
||||
ParamFunc: flagSet.Set,
|
||||
}
|
||||
|
||||
_ = flagSet.Parse(os.Args[1:])
|
||||
flagSet.Parse(os.Args[1:])
|
||||
|
||||
if *flagHelp {
|
||||
flagSet.PrintDefaults()
|
||||
@@ -47,7 +46,6 @@ type Generator struct {
|
||||
fieldaligment bool
|
||||
tagPath string
|
||||
openapiFile string
|
||||
graphqlFile string
|
||||
reflection bool
|
||||
plugin *protogen.Plugin
|
||||
}
|
||||
@@ -62,12 +60,11 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
g.fieldaligment = *flagFieldaligment
|
||||
g.tagPath = *flagTagPath
|
||||
g.openapiFile = *flagOpenapiFile
|
||||
g.graphqlFile = *flagGraphqlFile
|
||||
g.reflection = *flagReflection
|
||||
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
||||
|
||||
genClient := true
|
||||
genServer := true
|
||||
var genClient bool
|
||||
var genServer bool
|
||||
var genNone bool
|
||||
|
||||
if strings.Contains(g.components, "server") {
|
||||
@@ -93,9 +90,6 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
continue
|
||||
case "micro":
|
||||
err = g.microGenerate(component, plugin, genClient, genServer)
|
||||
if err == nil {
|
||||
err = g.writeErrors(plugin)
|
||||
}
|
||||
case "http":
|
||||
err = g.httpGenerate(component, plugin, genClient, genServer)
|
||||
case "grpc", "drpc", "rpc":
|
||||
@@ -105,11 +99,7 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
case "chi":
|
||||
err = g.chiGenerate(component, plugin)
|
||||
case "openapiv3":
|
||||
err = g.openapiv3Generate(plugin)
|
||||
// case "graphqls":
|
||||
// err = g.graphqlsGenerate(plugin)
|
||||
// case "graphql":
|
||||
// err = g.graphqlGenerate(plugin)
|
||||
err = g.openapiv3Generate(component, plugin)
|
||||
case "none":
|
||||
break
|
||||
default:
|
||||
|
||||
1
micro.go
1
micro.go
@@ -40,6 +40,7 @@ func (g *Generator) microGenerate(component string, plugin *protogen.Plugin, gen
|
||||
// generate services
|
||||
for _, service := range file.Services {
|
||||
g.generateServiceName(gfile, service)
|
||||
g.generateServiceEndpoints(gfile, service)
|
||||
if genClient {
|
||||
g.generateServiceClientInterface(gfile, service)
|
||||
g.generateServiceClientStreamInterface(gfile, service)
|
||||
|
||||
@@ -62,7 +62,7 @@ func protofilesAdd(plugin *protogen.Plugin) {
|
||||
}
|
||||
|
||||
// openapiv3Generate creates a new generator for a protoc plugin invocation.
|
||||
func (g *Generator) openapiv3Generate(plugin *protogen.Plugin) error {
|
||||
func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin) error {
|
||||
og := &openapiv3Generator{
|
||||
circularDepth: 2,
|
||||
plugin: plugin,
|
||||
|
||||
8
rpc.go
8
rpc.go
@@ -37,13 +37,13 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
|
||||
}
|
||||
for _, service := range file.Services {
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, file, service, component)
|
||||
g.generateServiceClient(gfile, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
}
|
||||
if genServer {
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
generateServiceServer(gfile, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
g.generateServiceRegister(gfile, service, component)
|
||||
}
|
||||
if component == "grpc" && g.reflection {
|
||||
g.generateServiceDesc(gfile, file, service)
|
||||
|
||||
7
tools.go
7
tools.go
@@ -1,7 +0,0 @@
|
||||
//go:build ignore
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
// _ "go.unistack.org/micro-proto/v3/graphql"
|
||||
)
|
||||
231
util.go
231
util.go
@@ -31,7 +31,7 @@ func unexport(s string) string {
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
|
||||
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
// if rule, ok := getMicroApiService(service); ok {
|
||||
// gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", "))
|
||||
@@ -41,24 +41,20 @@ func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *p
|
||||
gfile.P("name string")
|
||||
gfile.P("}")
|
||||
|
||||
//if g.standalone {
|
||||
// gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", file.GoImportPath.Ident(serviceName), "Client {")
|
||||
//} else {
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", serviceName, "Client {")
|
||||
//}
|
||||
gfile.P("return &", unexport(serviceName), "Client{c: c, name: name}")
|
||||
gfile.P("}")
|
||||
gfile.P()
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service, component string) {
|
||||
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
serviceName := service.GoName
|
||||
for _, method := range service.Methods {
|
||||
methodName := fmt.Sprintf("%s.%s", serviceName, method.GoName)
|
||||
if component == "drpc" {
|
||||
methodName = fmt.Sprintf("%s.%s", method.Parent.Desc.FullName(), method.Desc.Name())
|
||||
}
|
||||
g.generateClientFuncSignature(gfile, serviceName, file, method)
|
||||
g.generateClientFuncSignature(gfile, serviceName, method)
|
||||
|
||||
if component == "http" && method.Desc.Options() != nil {
|
||||
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
||||
@@ -262,7 +258,7 @@ func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile,
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
if method.Desc.IsStreamingClient() /*&& !method.Desc.IsStreamingServer()*/ {
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error) {")
|
||||
gfile.P("msg := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}")
|
||||
gfile.P("err := s.RecvMsg(msg)")
|
||||
@@ -323,14 +319,10 @@ func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceServer(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
|
||||
func generateServiceServer(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
gfile.P("type ", unexport(serviceName), "Server struct {")
|
||||
//if g.standalone {
|
||||
// gfile.P(file.GoImportPath.Ident(serviceName), "Server")
|
||||
//} else {
|
||||
gfile.P(serviceName, "Server")
|
||||
//}
|
||||
gfile.P("}")
|
||||
gfile.P()
|
||||
}
|
||||
@@ -432,7 +424,7 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
if /*method.Desc.IsStreamingClient() && !*/ method.Desc.IsStreamingServer() {
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
gfile.P("func (s *", unexport(serviceName), method.GoName, "Stream) SendAndClose(msg *", gfile.QualifiedGoIdent(method.Output.GoIdent), ") error {")
|
||||
gfile.P("err := s.SendMsg(msg)")
|
||||
gfile.P("if err == nil {")
|
||||
@@ -485,32 +477,23 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service, component string) {
|
||||
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
serviceName := service.GoName
|
||||
// if g.standalone {
|
||||
// gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", file.GoImportPath.Ident(serviceName), "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
// } else {
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
// }
|
||||
gfile.P("type ", unexport(serviceName), " interface {")
|
||||
var generate bool
|
||||
for _, method := range service.Methods {
|
||||
generateServerSignature(gfile, serviceName, method, true)
|
||||
if endpoints, _ := generateEndpoints(method); endpoints != nil {
|
||||
generate = true
|
||||
}
|
||||
}
|
||||
gfile.P("}")
|
||||
gfile.P("type ", serviceName, " struct {")
|
||||
gfile.P(unexport(serviceName))
|
||||
gfile.P("}")
|
||||
gfile.P("h := &", unexport(serviceName), "Server{sh}")
|
||||
|
||||
if component == "http" && generate {
|
||||
gfile.P("opts = append(opts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
|
||||
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
|
||||
if component == "http" {
|
||||
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
|
||||
}
|
||||
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, opts...))")
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
@@ -558,7 +541,7 @@ func generateServerSignature(gfile *protogen.GeneratedFile, serviceName string,
|
||||
gfile.P(args...)
|
||||
}
|
||||
|
||||
func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, file *protogen.File, method *protogen.Method) {
|
||||
func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, method *protogen.Method) {
|
||||
args := append([]interface{}{},
|
||||
"func (c *",
|
||||
unexport(serviceName),
|
||||
@@ -573,9 +556,7 @@ func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, s
|
||||
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
args = append(args, "*", gfile.QualifiedGoIdent(method.Output.GoIdent))
|
||||
} else {
|
||||
// TODO
|
||||
// args = append(args, gfile.QualifiedGoIdent(protogen.GoIdent{GoName: serviceName + "_" + method.GoName + "Client", GoImportPath: method.Output.GoIdent.GoImportPath}))
|
||||
args = append(args, serviceName+"_"+method.GoName+"Client")
|
||||
args = append(args, serviceName, "_", method.GoName, "Client")
|
||||
}
|
||||
args = append(args, ", error) {")
|
||||
gfile.P(args...)
|
||||
@@ -630,9 +611,9 @@ func (g *Generator) generateServiceClientStreamInterface(gfile *protogen.Generat
|
||||
gfile.P("Context() ", contextPackage.Ident("Context"))
|
||||
gfile.P("SendMsg(msg interface{}) error")
|
||||
gfile.P("RecvMsg(msg interface{}) error")
|
||||
if method.Desc.IsStreamingClient() /*&& !method.Desc.IsStreamingServer()*/ {
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
gfile.P("CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error)")
|
||||
gfile.P("CloseSend() error")
|
||||
gfile.P("CloseSend() () error")
|
||||
}
|
||||
gfile.P("Close() error")
|
||||
if method.Desc.IsStreamingClient() {
|
||||
@@ -658,9 +639,9 @@ func (g *Generator) generateServiceServerStreamInterface(gfile *protogen.Generat
|
||||
gfile.P("Context() ", contextPackage.Ident("Context"))
|
||||
gfile.P("SendMsg(msg interface{}) error")
|
||||
gfile.P("RecvMsg(msg interface{}) error")
|
||||
if /*method.Desc.IsStreamingClient() && !*/ method.Desc.IsStreamingServer() {
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
gfile.P("SendAndClose(msg *", gfile.QualifiedGoIdent(method.Output.GoIdent), ") error")
|
||||
// gfile.P("CloseSend() error")
|
||||
gfile.P("CloseSend() error")
|
||||
}
|
||||
gfile.P("Close() error")
|
||||
if method.Desc.IsStreamingClient() {
|
||||
@@ -795,35 +776,6 @@ func (g *Generator) getGoIdentByXref(xref string) (protogen.GoIdent, error) {
|
||||
return protogen.GoIdent{}, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
func (g *Generator) getMessageByXref(xref string) (*protogen.Message, error) {
|
||||
idx := strings.LastIndex(xref, ".")
|
||||
pkg := xref[:idx]
|
||||
msg := xref[idx+1:]
|
||||
for _, file := range g.plugin.Files {
|
||||
if strings.Compare(pkg, *(file.Proto.Package)) != 0 {
|
||||
continue
|
||||
}
|
||||
if pmsg, err := getProtoMessage(file.Messages, msg); err == nil {
|
||||
return pmsg, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
func getProtoMessage(messages []*protogen.Message, msg string) (*protogen.Message, error) {
|
||||
for _, message := range messages {
|
||||
if strings.Compare(msg, message.GoIdent.GoName) == 0 {
|
||||
return message, nil
|
||||
}
|
||||
if len(message.Messages) > 0 {
|
||||
if pmsg, err := getProtoMessage(message.Messages, msg); err == nil {
|
||||
return pmsg, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
func getGoIdentByMessage(messages []*protogen.Message, msg string) (protogen.GoIdent, error) {
|
||||
for _, message := range messages {
|
||||
if strings.Compare(msg, message.GoIdent.GoName) == 0 {
|
||||
@@ -887,22 +839,15 @@ func (g *Generator) generateServiceName(gfile *protogen.GeneratedFile, service *
|
||||
gfile.P(")")
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
if component != "http" {
|
||||
return
|
||||
}
|
||||
|
||||
var generate bool
|
||||
func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "ServerEndpoints = []", microServerHttpPackage.Ident("EndpointMetadata"), "{")
|
||||
|
||||
for _, method := range service.Methods {
|
||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
if endpoints, streaming := generateEndpoints(method); endpoints != nil {
|
||||
if !generate {
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "ServerEndpoints = []", microServerHttpPackage.Ident("EndpointMetadata"), "{")
|
||||
generate = true
|
||||
}
|
||||
for _, ep := range endpoints {
|
||||
epath, emethod, ebody := getEndpoint(ep)
|
||||
gfile.P("{")
|
||||
@@ -917,136 +862,6 @@ func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, serv
|
||||
}
|
||||
}
|
||||
|
||||
if generate {
|
||||
gfile.P("}")
|
||||
gfile.P(")")
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) writeErrors(plugin *protogen.Plugin) error {
|
||||
errorsMap := make(map[string]struct{})
|
||||
|
||||
for _, file := range plugin.Files {
|
||||
for _, service := range file.Services {
|
||||
for _, method := range service.Methods {
|
||||
if method.Desc.Options() != nil {
|
||||
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
||||
opts := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
||||
if opts != nil {
|
||||
r := opts.(*v2.Operation)
|
||||
if r.Responses == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rsp := range r.Responses.ResponseCode {
|
||||
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
||||
xref := schema.XRef
|
||||
if xref[0] == '.' {
|
||||
xref = xref[1:]
|
||||
}
|
||||
if g.fileMessage(plugin.Files, xref) {
|
||||
errorsMap[xref] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if proto.HasExtension(method.Desc.Options(), v3.E_Openapiv3Operation) {
|
||||
opts := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
||||
if opts != nil {
|
||||
r := opts.(*v3.Operation)
|
||||
if r.Responses == nil {
|
||||
continue
|
||||
}
|
||||
resps := r.Responses.ResponseOrReference
|
||||
if r.Responses.GetDefault() != nil {
|
||||
resps = append(resps, &v3.NamedResponseOrReference{Name: "default", Value: r.Responses.GetDefault()})
|
||||
}
|
||||
for _, rsp := range resps {
|
||||
if schema := rsp.Value.GetReference(); schema != nil {
|
||||
xref := schema.XRef
|
||||
if xref[0] == '.' {
|
||||
xref = xref[1:]
|
||||
}
|
||||
if g.fileMessage(plugin.Files, xref) {
|
||||
errorsMap[xref] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var gfile *protogen.GeneratedFile
|
||||
var importPath protogen.GoImportPath
|
||||
|
||||
if len(errorsMap) > 0 {
|
||||
|
||||
var packageName string
|
||||
|
||||
for _, file := range plugin.Files {
|
||||
if !file.Generate {
|
||||
continue
|
||||
}
|
||||
if len(file.Services) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
packageName = string(file.GoPackageName)
|
||||
importPath = file.GoImportPath
|
||||
break
|
||||
}
|
||||
|
||||
if g.standalone {
|
||||
importPath = "."
|
||||
}
|
||||
|
||||
gfile = plugin.NewGeneratedFile("micro_errors.pb.go", importPath)
|
||||
|
||||
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gfile.P()
|
||||
gfile.P("package ", packageName)
|
||||
gfile.P()
|
||||
|
||||
gfile.Import(protojsonPackage)
|
||||
|
||||
gfile.P("var (")
|
||||
gfile.P("marshaler = ", protojsonPackage.Ident("MarshalOptions"), "{}")
|
||||
gfile.P(")")
|
||||
}
|
||||
|
||||
for xref := range errorsMap {
|
||||
msg, err := g.getMessageByXref(xref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, field := range msg.Fields {
|
||||
if field.GoName == "Error" {
|
||||
return fmt.Errorf("failed generate Error() string interface for %s message %s already have Error field", field.Location.SourceFile, msg.Desc.Name())
|
||||
}
|
||||
}
|
||||
|
||||
gfile.P(`func (m *`, msg.GoIdent.GoName, `) Error() string {`)
|
||||
gfile.P(`buf, _ := marshaler.Marshal(m)`)
|
||||
gfile.P("return string(buf)")
|
||||
gfile.P(`}`)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Generator) fileMessage(files []*protogen.File, xref string) bool {
|
||||
for _, file := range files {
|
||||
for _, msg := range file.Messages {
|
||||
if xref == string(msg.Desc.FullName()) && file.Generate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
gfile.P("}")
|
||||
gfile.P(")")
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package main
|
||||
import "google.golang.org/protobuf/compiler/protogen"
|
||||
|
||||
var (
|
||||
ioPackage = protogen.GoImportPath("io")
|
||||
graphqlPackage = protogen.GoImportPath("github.com/99designs/gqlgen/graphql")
|
||||
reflectPackage = protogen.GoImportPath("reflect")
|
||||
stringsPackage = protogen.GoImportPath("strings")
|
||||
fmtPackage = protogen.GoImportPath("fmt")
|
||||
@@ -18,11 +16,10 @@ var (
|
||||
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v3/server")
|
||||
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v3")
|
||||
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v3")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v3/codec")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro/v3/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v3/errors")
|
||||
grpcPackage = protogen.GoImportPath("google.golang.org/grpc")
|
||||
protojsonPackage = protogen.GoImportPath("google.golang.org/protobuf/encoding/protojson")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v3.10.4"
|
||||
versionComment = "v3.10.2"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user