Remove unneeded dep on grpc-gateway
This commit is contained in:
parent
c40779224f
commit
1594e18f3c
1
vendor/github.com/grpc-ecosystem/grpc-gateway/.gitignore
generated
vendored
1
vendor/github.com/grpc-ecosystem/grpc-gateway/.gitignore
generated
vendored
@ -1 +0,0 @@
|
|||||||
_output/
|
|
36
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis.yml
generated
vendored
36
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis.yml
generated
vendored
@ -1,36 +0,0 @@
|
|||||||
language: go
|
|
||||||
sudo: false
|
|
||||||
go:
|
|
||||||
- 1.8.x
|
|
||||||
- 1.7.x
|
|
||||||
- tip
|
|
||||||
go_import_path: github.com/grpc-ecosystem/grpc-gateway
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/local
|
|
||||||
- ${TRAVIS_BUILD_DIR}/examples/browser/node_modules
|
|
||||||
before_install:
|
|
||||||
- ./.travis/install-protoc.sh 3.1.0
|
|
||||||
- ./.travis/install-swagger-codegen.sh 2.1.6
|
|
||||||
- nvm install v6.1 && nvm use v6.1 && node --version
|
|
||||||
- go get github.com/golang/lint/golint
|
|
||||||
- go get github.com/dghubble/sling
|
|
||||||
install:
|
|
||||||
- go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
|
|
||||||
- go get github.com/grpc-ecosystem/grpc-gateway/runtime
|
|
||||||
- go get github.com/grpc-ecosystem/grpc-gateway/examples
|
|
||||||
- go get github.com/grpc-ecosystem/grpc-gateway/examples/server
|
|
||||||
before_script:
|
|
||||||
- sh -c 'cd examples/browser && npm install'
|
|
||||||
script:
|
|
||||||
- make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar"
|
|
||||||
- if (go version | grep -q 1.8) && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi
|
|
||||||
- env GLOG_logtostderr=1 go test -race -v github.com/grpc-ecosystem/grpc-gateway/...
|
|
||||||
- make lint
|
|
||||||
- sh -c 'cd examples/browser && gulp'
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- "PATH=$PATH:$HOME/local/bin"
|
|
||||||
matrix:
|
|
||||||
- GATEWAY_PLUGIN_FLAGS=
|
|
||||||
- GATEWAY_PLUGIN_FLAGS=request_context=true
|
|
19
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis/install-protoc.sh
generated
vendored
19
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis/install-protoc.sh
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh -eu
|
|
||||||
protoc_version=$1
|
|
||||||
if test -z "${protoc_version}"; then
|
|
||||||
echo "Usage: .travis/install-protoc.sh protoc-version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ "`$HOME/local/bin/protoc-${protoc_version} --version 2>/dev/null | cut -d' ' -f 2`" != ${protoc_version} ]; then
|
|
||||||
rm -rf $HOME/local/bin $HOME/local/include
|
|
||||||
|
|
||||||
mkdir -p $HOME/tmp $HOME/local
|
|
||||||
cd $HOME/tmp
|
|
||||||
wget https://github.com/google/protobuf/releases/download/v${protoc_version}/protoc-${protoc_version}-linux-x86_64.zip
|
|
||||||
unzip protoc-${protoc_version}-linux-x86_64.zip
|
|
||||||
mv bin $HOME/local/bin
|
|
||||||
mv include $HOME/local/include
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo \$ $HOME/local/bin/protoc --version
|
|
||||||
$HOME/local/bin/protoc --version
|
|
9
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis/install-swagger-codegen.sh
generated
vendored
9
vendor/github.com/grpc-ecosystem/grpc-gateway/.travis/install-swagger-codegen.sh
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
#!/bin/sh -eu
|
|
||||||
codegen_version=$1
|
|
||||||
if test -z "${codegen_version}"; then
|
|
||||||
echo "Usage: .travis/install-swagger-codegen.sh codegen-version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${codegen_version}/swagger-codegen-cli-${codegen_version}.jar \
|
|
||||||
-O $HOME/local/swagger-codegen-cli.jar
|
|
152
vendor/github.com/grpc-ecosystem/grpc-gateway/CHANGELOG.md
generated
vendored
152
vendor/github.com/grpc-ecosystem/grpc-gateway/CHANGELOG.md
generated
vendored
@ -1,152 +0,0 @@
|
|||||||
# Change Log
|
|
||||||
|
|
||||||
## [v1.2.0](https://github.com/grpc-ecosystem/grpc-gateway/tree/v1.2.0) (2017-03-30)
|
|
||||||
**Merged pull requests:**
|
|
||||||
|
|
||||||
- Update go\_out parameter to remove comma [\#333](https://github.com/grpc-ecosystem/grpc-gateway/pull/333)
|
|
||||||
- Update stale path in README [\#332](https://github.com/grpc-ecosystem/grpc-gateway/pull/332)
|
|
||||||
- improve documentation regarding external dependencies [\#330](https://github.com/grpc-ecosystem/grpc-gateway/pull/330)
|
|
||||||
- Return an error on invalid nested query parameters. [\#329](https://github.com/grpc-ecosystem/grpc-gateway/pull/329)
|
|
||||||
- Update upstream proto files and add google.golang.org/genproto support. [\#325](https://github.com/grpc-ecosystem/grpc-gateway/pull/325)
|
|
||||||
- Do not ignore the error coming from http.ListenAndServe in examples [\#319](https://github.com/grpc-ecosystem/grpc-gateway/pull/319)
|
|
||||||
- Look up enum value maps by their proto name [\#315](https://github.com/grpc-ecosystem/grpc-gateway/pull/315)
|
|
||||||
- enable parsing enums from query parameters [\#314](https://github.com/grpc-ecosystem/grpc-gateway/pull/314)
|
|
||||||
- Do not add imports from methods with no bindings. [\#312](https://github.com/grpc-ecosystem/grpc-gateway/pull/312)
|
|
||||||
- Convert the first letter of method name to upper [\#300](https://github.com/grpc-ecosystem/grpc-gateway/pull/300)
|
|
||||||
- write query parameters to swagger definition [\#297](https://github.com/grpc-ecosystem/grpc-gateway/pull/297)
|
|
||||||
- Bump swagger-client to 2.1.28 for examples/browser [\#290](https://github.com/grpc-ecosystem/grpc-gateway/pull/290)
|
|
||||||
- pin to version before es6ism [\#289](https://github.com/grpc-ecosystem/grpc-gateway/pull/289)
|
|
||||||
- Prevent lack of http bindings from generating non-building output [\#286](https://github.com/grpc-ecosystem/grpc-gateway/pull/286)
|
|
||||||
- Added support for Timestamp in URL. [\#281](https://github.com/grpc-ecosystem/grpc-gateway/pull/281)
|
|
||||||
- add plugin param 'allow\_delete\_body' [\#280](https://github.com/grpc-ecosystem/grpc-gateway/pull/280)
|
|
||||||
- Fix ruby gen command [\#275](https://github.com/grpc-ecosystem/grpc-gateway/pull/275)
|
|
||||||
- Make grpc-gateway support enum fields in path parameter [\#273](https://github.com/grpc-ecosystem/grpc-gateway/pull/273)
|
|
||||||
- remove unnecessary make\(\) [\#271](https://github.com/grpc-ecosystem/grpc-gateway/pull/271)
|
|
||||||
- preserve field order in swagger spec [\#270](https://github.com/grpc-ecosystem/grpc-gateway/pull/270)
|
|
||||||
- Merge \#228 [\#268](https://github.com/grpc-ecosystem/grpc-gateway/pull/268)
|
|
||||||
- Handle methods with no bindings more carefully [\#267](https://github.com/grpc-ecosystem/grpc-gateway/pull/267)
|
|
||||||
- describe default marshaler in README.md [\#266](https://github.com/grpc-ecosystem/grpc-gateway/pull/266)
|
|
||||||
- Add request\_context flag to utilize \(\*http.Request\).Context\(\) in handlers [\#265](https://github.com/grpc-ecosystem/grpc-gateway/pull/265)
|
|
||||||
- Regenerate examples [\#264](https://github.com/grpc-ecosystem/grpc-gateway/pull/264)
|
|
||||||
- Correct runtime.errorBody protobuf field tag [\#256](https://github.com/grpc-ecosystem/grpc-gateway/pull/256)
|
|
||||||
- Pass permanent HTTP request headers [\#252](https://github.com/grpc-ecosystem/grpc-gateway/pull/252)
|
|
||||||
- regenerate examples, fix tests for go tip [\#248](https://github.com/grpc-ecosystem/grpc-gateway/pull/248)
|
|
||||||
- Render the swagger request body properly [\#247](https://github.com/grpc-ecosystem/grpc-gateway/pull/247)
|
|
||||||
- Error output should have lowercase attribute names [\#244](https://github.com/grpc-ecosystem/grpc-gateway/pull/244)
|
|
||||||
- runtime - export prefix constants [\#236](https://github.com/grpc-ecosystem/grpc-gateway/pull/236)
|
|
||||||
- README - Add CoreOS example [\#231](https://github.com/grpc-ecosystem/grpc-gateway/pull/231)
|
|
||||||
- Docs - Add section about how HTTP maps to gRPC [\#227](https://github.com/grpc-ecosystem/grpc-gateway/pull/227)
|
|
||||||
- readme: added links to additional documentation [\#222](https://github.com/grpc-ecosystem/grpc-gateway/pull/222)
|
|
||||||
- Use a released version of protoc [\#216](https://github.com/grpc-ecosystem/grpc-gateway/pull/216)
|
|
||||||
- Add contribution guideline [\#210](https://github.com/grpc-ecosystem/grpc-gateway/pull/210)
|
|
||||||
- improve\(genswagger:template\):added support for google.protobuf.Timestamp [\#209](https://github.com/grpc-ecosystem/grpc-gateway/pull/209)
|
|
||||||
- Allowing unknown fields to be dropped instead of returning error from… [\#208](https://github.com/grpc-ecosystem/grpc-gateway/pull/208)
|
|
||||||
- Avoid Internal Server Error on zero-length input for bidi streaming [\#200](https://github.com/grpc-ecosystem/grpc-gateway/pull/200)
|
|
||||||
|
|
||||||
## [v1.1.0](https://github.com/grpc-ecosystem/grpc-gateway/tree/v1.1.0) (2016-07-23)
|
|
||||||
**Merged pull requests:**
|
|
||||||
|
|
||||||
- Rename packages to follow the repository transfer [\#192](https://github.com/grpc-ecosystem/grpc-gateway/pull/192)
|
|
||||||
- return err early if EOF to prevent logging in normal conditions [\#191](https://github.com/grpc-ecosystem/grpc-gateway/pull/191)
|
|
||||||
- send Trailer header on error [\#188](https://github.com/grpc-ecosystem/grpc-gateway/pull/188)
|
|
||||||
- generate swagger output for streaming endpoints with a basic note [\#183](https://github.com/grpc-ecosystem/grpc-gateway/pull/183)
|
|
||||||
|
|
||||||
## [v1.0.0](https://github.com/grpc-ecosystem/grpc-gateway/tree/v1.0.0) (2016-06-15)
|
|
||||||
**Merged pull requests:**
|
|
||||||
|
|
||||||
- Regenerate files with the latest protoc-gen-go [\#185](https://github.com/grpc-ecosystem/grpc-gateway/pull/185)
|
|
||||||
- Add browser examples [\#184](https://github.com/grpc-ecosystem/grpc-gateway/pull/184)
|
|
||||||
- Fix golint and go vet errors [\#182](https://github.com/grpc-ecosystem/grpc-gateway/pull/182)
|
|
||||||
- Add integration with clients generated by swagger-codegen [\#181](https://github.com/grpc-ecosystem/grpc-gateway/pull/181)
|
|
||||||
- Simplify example services [\#180](https://github.com/grpc-ecosystem/grpc-gateway/pull/180)
|
|
||||||
- Avoid errors when req.RemoteAddr is empty [\#178](https://github.com/grpc-ecosystem/grpc-gateway/pull/178)
|
|
||||||
- Feature/headers [\#176](https://github.com/grpc-ecosystem/grpc-gateway/pull/176)
|
|
||||||
- Include HTTP req.remoteAddr in gRPC ctx [\#174](https://github.com/grpc-ecosystem/grpc-gateway/pull/174)
|
|
||||||
- Update dependencies [\#171](https://github.com/grpc-ecosystem/grpc-gateway/pull/171)
|
|
||||||
- Add bidirectional streaming support by running Send\(\) and Recv\(\) concurrently [\#170](https://github.com/grpc-ecosystem/grpc-gateway/pull/170)
|
|
||||||
- make Authorization header check case-insensitive to comply with RFC 2616 4.2 [\#164](https://github.com/grpc-ecosystem/grpc-gateway/pull/164)
|
|
||||||
- jsonpb: avoid duplicating upstream's struct [\#158](https://github.com/grpc-ecosystem/grpc-gateway/pull/158)
|
|
||||||
- Generate Swagger description for service methods using proto comments. [\#156](https://github.com/grpc-ecosystem/grpc-gateway/pull/156)
|
|
||||||
- Implement gRPC timeout support for inbound HTTP headers [\#155](https://github.com/grpc-ecosystem/grpc-gateway/pull/155)
|
|
||||||
- Add more examples to marshalers [\#154](https://github.com/grpc-ecosystem/grpc-gateway/pull/154)
|
|
||||||
- custom marshaler: handle `Accept` headers correctly [\#152](https://github.com/grpc-ecosystem/grpc-gateway/pull/152)
|
|
||||||
- Simplify custom marshaler API [\#151](https://github.com/grpc-ecosystem/grpc-gateway/pull/151)
|
|
||||||
- Fix camel case path parameter handling in swagger [\#149](https://github.com/grpc-ecosystem/grpc-gateway/pull/149)
|
|
||||||
- Swagger dot in path template [\#148](https://github.com/grpc-ecosystem/grpc-gateway/pull/148)
|
|
||||||
- Support map types in swagger generator [\#147](https://github.com/grpc-ecosystem/grpc-gateway/pull/147)
|
|
||||||
- Cleanup custom marshaler [\#146](https://github.com/grpc-ecosystem/grpc-gateway/pull/146)
|
|
||||||
- Implement custom Marshaler support, add jsonpb implemention. [\#144](https://github.com/grpc-ecosystem/grpc-gateway/pull/144)
|
|
||||||
- Allow period in path URL templates when generating Swagger templates. [\#143](https://github.com/grpc-ecosystem/grpc-gateway/pull/143)
|
|
||||||
- Link to LICENSE.txt [\#142](https://github.com/grpc-ecosystem/grpc-gateway/pull/142)
|
|
||||||
- Support map types in swagger generator [\#141](https://github.com/grpc-ecosystem/grpc-gateway/pull/141)
|
|
||||||
- Conditionally stops checking if generated file are up-to-date [\#136](https://github.com/grpc-ecosystem/grpc-gateway/pull/136)
|
|
||||||
- Generate Swagger description for service methods using proto comments. [\#134](https://github.com/grpc-ecosystem/grpc-gateway/pull/134)
|
|
||||||
- Swagger definitions now have `type` set to `object`. [\#133](https://github.com/grpc-ecosystem/grpc-gateway/pull/133)
|
|
||||||
- go\_package option as go import path [\#129](https://github.com/grpc-ecosystem/grpc-gateway/pull/129)
|
|
||||||
- Fix govet errors [\#126](https://github.com/grpc-ecosystem/grpc-gateway/pull/126)
|
|
||||||
- Fix data-race in generated codes [\#125](https://github.com/grpc-ecosystem/grpc-gateway/pull/125)
|
|
||||||
- Fix \#119 - CloseNotify race with ServeHTTP [\#120](https://github.com/grpc-ecosystem/grpc-gateway/pull/120)
|
|
||||||
- Replace glog with grpclog [\#118](https://github.com/grpc-ecosystem/grpc-gateway/pull/118)
|
|
||||||
- Fix a goroutine-leak in HTTP keep-alive [\#116](https://github.com/grpc-ecosystem/grpc-gateway/pull/116)
|
|
||||||
- Fix camel case path parameter handling in swagger [\#114](https://github.com/grpc-ecosystem/grpc-gateway/pull/114)
|
|
||||||
- gofmt -s [\#112](https://github.com/grpc-ecosystem/grpc-gateway/pull/112)
|
|
||||||
- fix typo [\#111](https://github.com/grpc-ecosystem/grpc-gateway/pull/111)
|
|
||||||
- fix typo [\#110](https://github.com/grpc-ecosystem/grpc-gateway/pull/110)
|
|
||||||
- fixes missing swagger operation objects [\#109](https://github.com/grpc-ecosystem/grpc-gateway/pull/109)
|
|
||||||
- Add parser and swagger support for enum, no gengateway yet [\#108](https://github.com/grpc-ecosystem/grpc-gateway/pull/108)
|
|
||||||
- README: add protoc-gen-swagger too [\#105](https://github.com/grpc-ecosystem/grpc-gateway/pull/105)
|
|
||||||
- README: Suggest go get -u by default. [\#104](https://github.com/grpc-ecosystem/grpc-gateway/pull/104)
|
|
||||||
- Cancel context when HTTP connection is closed [\#102](https://github.com/grpc-ecosystem/grpc-gateway/pull/102)
|
|
||||||
- wait test server up [\#100](https://github.com/grpc-ecosystem/grpc-gateway/pull/100)
|
|
||||||
- Fix the swagger section of the README.md [\#98](https://github.com/grpc-ecosystem/grpc-gateway/pull/98)
|
|
||||||
- Add documentation for using Swagger [\#97](https://github.com/grpc-ecosystem/grpc-gateway/pull/97)
|
|
||||||
- Better compatibility to field names generated by protoc-gen-go [\#96](https://github.com/grpc-ecosystem/grpc-gateway/pull/96)
|
|
||||||
- Update protoc from 3.0.0-beta1 to 3.0.0-beta2 [\#95](https://github.com/grpc-ecosystem/grpc-gateway/pull/95)
|
|
||||||
- Better grpc error strings [\#94](https://github.com/grpc-ecosystem/grpc-gateway/pull/94)
|
|
||||||
- make available header and trailer metadata [\#93](https://github.com/grpc-ecosystem/grpc-gateway/pull/93)
|
|
||||||
- make grpc.DialOption configurable [\#89](https://github.com/grpc-ecosystem/grpc-gateway/pull/89)
|
|
||||||
- Add request in error handlers [\#88](https://github.com/grpc-ecosystem/grpc-gateway/pull/88)
|
|
||||||
- Improve PascalFromSnake behavior [\#85](https://github.com/grpc-ecosystem/grpc-gateway/pull/85)
|
|
||||||
- Typo grcp -\> grpc [\#81](https://github.com/grpc-ecosystem/grpc-gateway/pull/81)
|
|
||||||
- Add abstraction of code generator implementation [\#78](https://github.com/grpc-ecosystem/grpc-gateway/pull/78)
|
|
||||||
- Support multivalue of metadata [\#77](https://github.com/grpc-ecosystem/grpc-gateway/pull/77)
|
|
||||||
- Fix broken test [\#76](https://github.com/grpc-ecosystem/grpc-gateway/pull/76)
|
|
||||||
- Added missing instruction line in README [\#75](https://github.com/grpc-ecosystem/grpc-gateway/pull/75)
|
|
||||||
- Fix a complie error in generated go files [\#71](https://github.com/grpc-ecosystem/grpc-gateway/pull/71)
|
|
||||||
- Update generated .pb.go files in third\_party [\#69](https://github.com/grpc-ecosystem/grpc-gateway/pull/69)
|
|
||||||
- Add swagger support [\#68](https://github.com/grpc-ecosystem/grpc-gateway/pull/68)
|
|
||||||
- Bugfix/handling headers for `Authorization` and `Host` [\#65](https://github.com/grpc-ecosystem/grpc-gateway/pull/65)
|
|
||||||
- Fix `error` field always in chunk response [\#64](https://github.com/grpc-ecosystem/grpc-gateway/pull/64)
|
|
||||||
- Update .pb.go to latest version. [\#63](https://github.com/grpc-ecosystem/grpc-gateway/pull/63)
|
|
||||||
- Run more tests in Travis CI [\#60](https://github.com/grpc-ecosystem/grpc-gateway/pull/60)
|
|
||||||
- Added http error code and error status for responseStreamChunk error [\#59](https://github.com/grpc-ecosystem/grpc-gateway/pull/59)
|
|
||||||
- Fix parsing of verb and final path component. [\#55](https://github.com/grpc-ecosystem/grpc-gateway/pull/55)
|
|
||||||
- Add runtime.WithForwardResponseOption [\#53](https://github.com/grpc-ecosystem/grpc-gateway/pull/53)
|
|
||||||
- add grpc.WithInsecure\(\) as option for grpc.Dial call in template [\#52](https://github.com/grpc-ecosystem/grpc-gateway/pull/52)
|
|
||||||
- update .pb.go files for latest golang proto generation [\#51](https://github.com/grpc-ecosystem/grpc-gateway/pull/51)
|
|
||||||
- Fix a build error with the latest protoc-gen-go [\#50](https://github.com/grpc-ecosystem/grpc-gateway/pull/50)
|
|
||||||
- Configure Travis CI [\#49](https://github.com/grpc-ecosystem/grpc-gateway/pull/49)
|
|
||||||
- Follow a change of go package name convention in protoc-gen-go [\#48](https://github.com/grpc-ecosystem/grpc-gateway/pull/48)
|
|
||||||
- Consider tail segments after deep wildcard [\#47](https://github.com/grpc-ecosystem/grpc-gateway/pull/47)
|
|
||||||
- Fix typo in README [\#45](https://github.com/grpc-ecosystem/grpc-gateway/pull/45)
|
|
||||||
- Fix undefined variable error in generated codes [\#42](https://github.com/grpc-ecosystem/grpc-gateway/pull/42)
|
|
||||||
- Follow changes in protoc-gen-go and grpc-go [\#41](https://github.com/grpc-ecosystem/grpc-gateway/pull/41)
|
|
||||||
- Fixes \#4 [\#40](https://github.com/grpc-ecosystem/grpc-gateway/pull/40)
|
|
||||||
- fix examples to work with go1.5 [\#39](https://github.com/grpc-ecosystem/grpc-gateway/pull/39)
|
|
||||||
- rename internal to utilties for 1.5 compatibility [\#38](https://github.com/grpc-ecosystem/grpc-gateway/pull/38)
|
|
||||||
- Reflection fix of proto3 nested messages. [\#34](https://github.com/grpc-ecosystem/grpc-gateway/pull/34)
|
|
||||||
- \[Experimental\] Make the response forwarder function customizable [\#31](https://github.com/grpc-ecosystem/grpc-gateway/pull/31)
|
|
||||||
- Add f.Flush\(\) to runtime.ForwardResponseStream [\#30](https://github.com/grpc-ecosystem/grpc-gateway/pull/30)
|
|
||||||
- Format error message in JSON [\#29](https://github.com/grpc-ecosystem/grpc-gateway/pull/29)
|
|
||||||
- Update examples with HTTP header context annotation [\#28](https://github.com/grpc-ecosystem/grpc-gateway/pull/28)
|
|
||||||
- Report semantic errors in the source to protoc [\#27](https://github.com/grpc-ecosystem/grpc-gateway/pull/27)
|
|
||||||
- Add support for non-nullable nested messages. [\#21](https://github.com/grpc-ecosystem/grpc-gateway/pull/21)
|
|
||||||
- Receive GRPC metadata from HTTP headers. [\#18](https://github.com/grpc-ecosystem/grpc-gateway/pull/18)
|
|
||||||
- Implement detailed specs of google.api.http [\#14](https://github.com/grpc-ecosystem/grpc-gateway/pull/14)
|
|
||||||
- Configure travis CI [\#13](https://github.com/grpc-ecosystem/grpc-gateway/pull/13)
|
|
||||||
- Replace our own custom option with the one defined by Google [\#12](https://github.com/grpc-ecosystem/grpc-gateway/pull/12)
|
|
||||||
- Remove useless context setup [\#11](https://github.com/grpc-ecosystem/grpc-gateway/pull/11)
|
|
||||||
- Fix typo, path, missing semicolon. [\#10](https://github.com/grpc-ecosystem/grpc-gateway/pull/10)
|
|
||||||
- Use a globally unique id for the custom option [\#3](https://github.com/grpc-ecosystem/grpc-gateway/pull/3)
|
|
||||||
- implement ABitOfEverythingService [\#2](https://github.com/grpc-ecosystem/grpc-gateway/pull/2)
|
|
||||||
- support streaming API calls [\#1](https://github.com/grpc-ecosystem/grpc-gateway/pull/1)
|
|
20
vendor/github.com/grpc-ecosystem/grpc-gateway/CONTRIBUTING.md
generated
vendored
20
vendor/github.com/grpc-ecosystem/grpc-gateway/CONTRIBUTING.md
generated
vendored
@ -1,20 +0,0 @@
|
|||||||
# How to contribute
|
|
||||||
|
|
||||||
Thank you for your contribution to grpc-gateway.
|
|
||||||
Here's the recommended process of contribution.
|
|
||||||
|
|
||||||
1. `go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway`
|
|
||||||
2. `cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway`
|
|
||||||
3. hack, hack, hack...
|
|
||||||
4. Make sure that your change follows best practices in Go
|
|
||||||
* [Effective Go](https://golang.org/doc/effective_go.html)
|
|
||||||
* [Go Code Review Comments](https://golang.org/wiki/CodeReviewComments)
|
|
||||||
5. Make sure that `make test` passes. (use swagger-codegen 2.1.6, not newer versions)
|
|
||||||
6. Sign [a Contributor License Agreement](https://cla.developers.google.com/clas)
|
|
||||||
7. Open a pull request in Github
|
|
||||||
|
|
||||||
When you work on a larger contribution, it is also recommended that you get in touch
|
|
||||||
with us through the issue tracker.
|
|
||||||
|
|
||||||
### Code reviews
|
|
||||||
All submissions, including submissions by project members, require review.
|
|
27
vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt
generated
vendored
27
vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
Copyright (c) 2015, Gengo, Inc.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
* Neither the name of Gengo, Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from this
|
|
||||||
software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
143
vendor/github.com/grpc-ecosystem/grpc-gateway/Makefile
generated
vendored
143
vendor/github.com/grpc-ecosystem/grpc-gateway/Makefile
generated
vendored
@ -1,143 +0,0 @@
|
|||||||
# This is a Makefile which maintains files automatically generated but to be
|
|
||||||
# shipped together with other files.
|
|
||||||
# You don't have to rebuild these targets by yourself unless you develop
|
|
||||||
# grpc-gateway itself.
|
|
||||||
|
|
||||||
PKG=github.com/grpc-ecosystem/grpc-gateway
|
|
||||||
GO_PLUGIN=bin/protoc-gen-go
|
|
||||||
GO_PLUGIN_PKG=github.com/golang/protobuf/protoc-gen-go
|
|
||||||
SWAGGER_PLUGIN=bin/protoc-gen-swagger
|
|
||||||
SWAGGER_PLUGIN_SRC= utilities/doc.go \
|
|
||||||
utilities/pattern.go \
|
|
||||||
utilities/trie.go \
|
|
||||||
protoc-gen-swagger/genswagger/generator.go \
|
|
||||||
protoc-gen-swagger/genswagger/template.go \
|
|
||||||
protoc-gen-swagger/main.go
|
|
||||||
SWAGGER_PLUGIN_PKG=$(PKG)/protoc-gen-swagger
|
|
||||||
GATEWAY_PLUGIN=bin/protoc-gen-grpc-gateway
|
|
||||||
GATEWAY_PLUGIN_PKG=$(PKG)/protoc-gen-grpc-gateway
|
|
||||||
GATEWAY_PLUGIN_SRC= utilities/doc.go \
|
|
||||||
utilities/pattern.go \
|
|
||||||
utilities/trie.go \
|
|
||||||
protoc-gen-grpc-gateway \
|
|
||||||
protoc-gen-grpc-gateway/descriptor \
|
|
||||||
protoc-gen-grpc-gateway/descriptor/registry.go \
|
|
||||||
protoc-gen-grpc-gateway/descriptor/services.go \
|
|
||||||
protoc-gen-grpc-gateway/descriptor/types.go \
|
|
||||||
protoc-gen-grpc-gateway/generator \
|
|
||||||
protoc-gen-grpc-gateway/generator/generator.go \
|
|
||||||
protoc-gen-grpc-gateway/gengateway \
|
|
||||||
protoc-gen-grpc-gateway/gengateway/doc.go \
|
|
||||||
protoc-gen-grpc-gateway/gengateway/generator.go \
|
|
||||||
protoc-gen-grpc-gateway/gengateway/template.go \
|
|
||||||
protoc-gen-grpc-gateway/httprule \
|
|
||||||
protoc-gen-grpc-gateway/httprule/compile.go \
|
|
||||||
protoc-gen-grpc-gateway/httprule/parse.go \
|
|
||||||
protoc-gen-grpc-gateway/httprule/types.go \
|
|
||||||
protoc-gen-grpc-gateway/main.go
|
|
||||||
GATEWAY_PLUGIN_FLAGS?=
|
|
||||||
|
|
||||||
GOOGLEAPIS_DIR=third_party/googleapis
|
|
||||||
OUTPUT_DIR=_output
|
|
||||||
|
|
||||||
RUNTIME_PROTO=runtime/internal/stream_chunk.proto
|
|
||||||
RUNTIME_GO=$(RUNTIME_PROTO:.proto=.pb.go)
|
|
||||||
|
|
||||||
PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mexamples/sub/message.proto=$(PKG)/examples/sub
|
|
||||||
ADDITIONAL_FLAGS=
|
|
||||||
ifneq "$(GATEWAY_PLUGIN_FLAGS)" ""
|
|
||||||
ADDITIONAL_FLAGS=,$(GATEWAY_PLUGIN_FLAGS)
|
|
||||||
endif
|
|
||||||
SWAGGER_EXAMPLES=examples/examplepb/echo_service.proto \
|
|
||||||
examples/examplepb/a_bit_of_everything.proto
|
|
||||||
EXAMPLES=examples/examplepb/echo_service.proto \
|
|
||||||
examples/examplepb/a_bit_of_everything.proto \
|
|
||||||
examples/examplepb/stream.proto \
|
|
||||||
examples/examplepb/flow_combination.proto
|
|
||||||
EXAMPLE_SVCSRCS=$(EXAMPLES:.proto=.pb.go)
|
|
||||||
EXAMPLE_GWSRCS=$(EXAMPLES:.proto=.pb.gw.go)
|
|
||||||
EXAMPLE_SWAGGERSRCS=$(EXAMPLES:.proto=.swagger.json)
|
|
||||||
EXAMPLE_DEPS=examples/sub/message.proto examples/sub2/message.proto
|
|
||||||
EXAMPLE_DEPSRCS=$(EXAMPLE_DEPS:.proto=.pb.go)
|
|
||||||
|
|
||||||
EXAMPLE_CLIENT_DIR=examples/clients
|
|
||||||
ECHO_EXAMPLE_SPEC=examples/examplepb/echo_service.swagger.json
|
|
||||||
ECHO_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/echo/EchoServiceApi.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/echo/ExamplepbSimpleMessage.go
|
|
||||||
ABE_EXAMPLE_SPEC=examples/examplepb/a_bit_of_everything.swagger.json
|
|
||||||
ABE_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/abe/ABitOfEverythingServiceApi.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/ABitOfEverythingNested.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/ExamplepbABitOfEverything.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/ExamplepbNumericEnum.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/ExamplepbIdMessage.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/NestedDeepEnum.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/ProtobufEmpty.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/Sub2IdMessage.go \
|
|
||||||
$(EXAMPLE_CLIENT_DIR)/abe/SubStringMessage.go
|
|
||||||
EXAMPLE_CLIENT_SRCS=$(ECHO_EXAMPLE_SRCS) $(ABE_EXAMPLE_SRCS)
|
|
||||||
SWAGGER_CODEGEN=swagger-codegen
|
|
||||||
|
|
||||||
PROTOC_INC_PATH=$(dir $(shell which protoc))/../include
|
|
||||||
|
|
||||||
generate: $(RUNTIME_GO)
|
|
||||||
|
|
||||||
.SUFFIXES: .go .proto
|
|
||||||
|
|
||||||
$(GO_PLUGIN):
|
|
||||||
go get $(GO_PLUGIN_PKG)
|
|
||||||
go build -o $@ $(GO_PLUGIN_PKG)
|
|
||||||
|
|
||||||
$(RUNTIME_GO): $(RUNTIME_PROTO) $(GO_PLUGIN)
|
|
||||||
protoc -I $(PROTOC_INC_PATH) --plugin=$(GO_PLUGIN) -I. --go_out=$(PKGMAP):. $(RUNTIME_PROTO)
|
|
||||||
|
|
||||||
$(GATEWAY_PLUGIN): $(RUNTIME_GO) $(GATEWAY_PLUGIN_SRC)
|
|
||||||
go build -o $@ $(GATEWAY_PLUGIN_PKG)
|
|
||||||
|
|
||||||
$(SWAGGER_PLUGIN): $(SWAGGER_PLUGIN_SRC)
|
|
||||||
go build -o $@ $(SWAGGER_PLUGIN_PKG)
|
|
||||||
|
|
||||||
$(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(EXAMPLES)
|
|
||||||
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc:. $(EXAMPLES)
|
|
||||||
$(EXAMPLE_DEPSRCS): $(GO_PLUGIN) $(EXAMPLE_DEPS)
|
|
||||||
mkdir -p $(OUTPUT_DIR)
|
|
||||||
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc:$(OUTPUT_DIR) $(@:.pb.go=.proto)
|
|
||||||
cp $(OUTPUT_DIR)/$(PKG)/$@ $@ || cp $(OUTPUT_DIR)/$@ $@
|
|
||||||
$(EXAMPLE_GWSRCS): $(GATEWAY_PLUGIN) $(EXAMPLES)
|
|
||||||
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GATEWAY_PLUGIN) --grpc-gateway_out=logtostderr=true,$(PKGMAP)$(ADDITIONAL_FLAGS):. $(EXAMPLES)
|
|
||||||
$(EXAMPLE_SWAGGERSRCS): $(SWAGGER_PLUGIN) $(SWAGGER_EXAMPLES)
|
|
||||||
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(SWAGGER_PLUGIN) --swagger_out=logtostderr=true,$(PKGMAP):. $(SWAGGER_EXAMPLES)
|
|
||||||
|
|
||||||
$(ECHO_EXAMPLE_SRCS): $(ECHO_EXAMPLE_SPEC)
|
|
||||||
$(SWAGGER_CODEGEN) generate -i $(ECHO_EXAMPLE_SPEC) \
|
|
||||||
-l go -o examples/clients --additional-properties packageName=echo
|
|
||||||
@rm -f $(EXAMPLE_CLIENT_DIR)/README.md $(EXAMPLE_CLIENT_DIR)/git_push.sh $(EXAMPLE_CLIENT_DIR)/.gitignore
|
|
||||||
$(ABE_EXAMPLE_SRCS): $(ABE_EXAMPLE_SPEC)
|
|
||||||
$(SWAGGER_CODEGEN) generate -i $(ABE_EXAMPLE_SPEC) \
|
|
||||||
-l go -o examples/clients --additional-properties packageName=abe
|
|
||||||
@rm -f $(EXAMPLE_CLIENT_DIR)/README.md $(EXAMPLE_CLIENT_DIR)/git_push.sh $(EXAMPLE_CLIENT_DIR)/.gitignore
|
|
||||||
|
|
||||||
examples: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS) $(EXAMPLE_SWAGGERSRCS) $(EXAMPLE_CLIENT_SRCS)
|
|
||||||
test: examples
|
|
||||||
go test -race $(PKG)/...
|
|
||||||
|
|
||||||
lint:
|
|
||||||
golint --set_exit_status $(PKG)/runtime
|
|
||||||
golint --set_exit_status $(PKG)/utilities/...
|
|
||||||
golint --set_exit_status $(PKG)/protoc-gen-grpc-gateway/...
|
|
||||||
golint --set_exit_status $(PKG)/protoc-gen-swagger/...
|
|
||||||
go vet $(PKG)/runtime || true
|
|
||||||
go vet $(PKG)/utilities/...
|
|
||||||
go vet $(PKG)/protoc-gen-grpc-gateway/...
|
|
||||||
go vet $(PKG)/protoc-gen-swagger/...
|
|
||||||
|
|
||||||
clean distclean:
|
|
||||||
rm -f $(GATEWAY_PLUGIN)
|
|
||||||
realclean: distclean
|
|
||||||
rm -f $(EXAMPLE_SVCSRCS) $(EXAMPLE_DEPSRCS)
|
|
||||||
rm -f $(EXAMPLE_GWSRCS)
|
|
||||||
rm -f $(EXAMPLE_SWAGGERSRCS)
|
|
||||||
rm -f $(GO_PLUGIN)
|
|
||||||
rm -f $(SWAGGER_PLUGIN)
|
|
||||||
rm -f $(EXAMPLE_CLIENT_SRCS)
|
|
||||||
|
|
||||||
.PHONY: generate examples test lint clean distclean realclean
|
|
249
vendor/github.com/grpc-ecosystem/grpc-gateway/README.md
generated
vendored
249
vendor/github.com/grpc-ecosystem/grpc-gateway/README.md
generated
vendored
@ -1,249 +0,0 @@
|
|||||||
# grpc-gateway
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/grpc-ecosystem/grpc-gateway.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/grpc-gateway)
|
|
||||||
|
|
||||||
grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf).
|
|
||||||
It reads [gRPC](http://github.com/grpc/grpc-common) service definition,
|
|
||||||
and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.
|
|
||||||
This server is generated according to [custom options](https://cloud.google.com/service-management/reference/rpc/google.api#http) in your gRPC definition.
|
|
||||||
|
|
||||||
It helps you to provide your APIs in both gRPC and RESTful style at the same time.
|
|
||||||
|
|
||||||
![architecture introduction diagram](https://docs.google.com/drawings/d/12hp4CPqrNPFhattL_cIoJptFvlAqm5wLQ0ggqI5mkCg/pub?w=749&h=370)
|
|
||||||
|
|
||||||
## Background
|
|
||||||
gRPC is great -- it generates API clients and server stubs in many programming languages,
|
|
||||||
it is fast, easy-to-use, bandwidth-efficient and its design is combat-proven by Google.
|
|
||||||
However, you might still want to provide classic RESTful APIs too for some reasons --
|
|
||||||
compatibility with languages not supported by gRPC, API backward-compatibility or aesthetics
|
|
||||||
of RESTful architecture.
|
|
||||||
|
|
||||||
That's what grpc-gateway helps you to do. You just need to implement your gRPC service with a small amount of custom options.
|
|
||||||
Then the reverse-proxy generated by grpc-gateway serves RESTful API on top of the gRPC service.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
First you need to install ProtocolBuffers 3.0.0-beta-3 or later.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
mkdir tmp
|
|
||||||
cd tmp
|
|
||||||
git clone https://github.com/google/protobuf
|
|
||||||
cd protobuf
|
|
||||||
./autogen.sh
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make check
|
|
||||||
sudo make install
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, `go get -u` as usual the following packages:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
|
|
||||||
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
|
|
||||||
go get -u github.com/golang/protobuf/protoc-gen-go
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Make sure that your `$GOPATH/bin` is in your `$PATH`.
|
|
||||||
|
|
||||||
1. Define your service in gRPC
|
|
||||||
|
|
||||||
your_service.proto:
|
|
||||||
```protobuf
|
|
||||||
syntax = "proto3";
|
|
||||||
package example;
|
|
||||||
message StringMessage {
|
|
||||||
string value = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
service YourService {
|
|
||||||
rpc Echo(StringMessage) returns (StringMessage) {}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
2. Add a [custom option](https://cloud.google.com/service-management/reference/rpc/google.api#http) to the .proto file
|
|
||||||
|
|
||||||
your_service.proto:
|
|
||||||
```diff
|
|
||||||
syntax = "proto3";
|
|
||||||
package example;
|
|
||||||
+
|
|
||||||
+import "google/api/annotations.proto";
|
|
||||||
+
|
|
||||||
message StringMessage {
|
|
||||||
string value = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
service YourService {
|
|
||||||
- rpc Echo(StringMessage) returns (StringMessage) {}
|
|
||||||
+ rpc Echo(StringMessage) returns (StringMessage) {
|
|
||||||
+ option (google.api.http) = {
|
|
||||||
+ post: "/v1/example/echo"
|
|
||||||
+ body: "*"
|
|
||||||
+ };
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
3. Generate gRPC stub
|
|
||||||
|
|
||||||
```sh
|
|
||||||
protoc -I/usr/local/include -I. \
|
|
||||||
-I$GOPATH/src \
|
|
||||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
|
||||||
--go_out=plugins=grpc:. \
|
|
||||||
path/to/your_service.proto
|
|
||||||
```
|
|
||||||
|
|
||||||
It will generate a stub file `path/to/your_service.pb.go`.
|
|
||||||
4. Implement your service in gRPC as usual
|
|
||||||
1. (Optional) Generate gRPC stub in the language you want.
|
|
||||||
|
|
||||||
e.g.
|
|
||||||
```sh
|
|
||||||
protoc -I/usr/local/include -I. \
|
|
||||||
-I$GOPATH/src \
|
|
||||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
|
||||||
--ruby_out=. \
|
|
||||||
path/to/your/service_proto
|
|
||||||
|
|
||||||
protoc -I/usr/local/include -I. \
|
|
||||||
-I$GOPATH/src \
|
|
||||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
|
||||||
--plugin=protoc-gen-grpc=grpc_ruby_plugin \
|
|
||||||
--grpc-ruby_out=. \
|
|
||||||
path/to/your/service.proto
|
|
||||||
```
|
|
||||||
2. Add the googleapis-common-protos gem (or your language equivalent) as a dependency to your project.
|
|
||||||
3. Implement your service
|
|
||||||
|
|
||||||
5. Generate reverse-proxy
|
|
||||||
|
|
||||||
```sh
|
|
||||||
protoc -I/usr/local/include -I. \
|
|
||||||
-I$GOPATH/src \
|
|
||||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
|
||||||
--grpc-gateway_out=logtostderr=true:. \
|
|
||||||
path/to/your_service.proto
|
|
||||||
```
|
|
||||||
|
|
||||||
It will generate a reverse proxy `path/to/your_service.pb.gw.go`.
|
|
||||||
|
|
||||||
Note: After generating the code for each of the stubs, in order to build the code, you will want to run ```go get .``` from the directory containing the stubs.
|
|
||||||
|
|
||||||
6. Write an entrypoint
|
|
||||||
|
|
||||||
Now you need to write an entrypoint of the proxy server.
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
gw "path/to/your_service_package"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of YourService")
|
|
||||||
)
|
|
||||||
|
|
||||||
func run() error {
|
|
||||||
ctx := context.Background()
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
mux := runtime.NewServeMux()
|
|
||||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
|
||||||
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return http.ListenAndServe(":8080", mux)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
if err := run(); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
7. (Optional) Generate swagger definitions
|
|
||||||
|
|
||||||
```sh
|
|
||||||
protoc -I/usr/local/include -I. \
|
|
||||||
-I$GOPATH/src \
|
|
||||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
|
||||||
--swagger_out=logtostderr=true:. \
|
|
||||||
path/to/your_service.proto
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters and flags
|
|
||||||
`protoc-gen-grpc-gateway` supports custom mapping from Protobuf `import` to Golang import path.
|
|
||||||
They are compatible to [the parameters with same names in `protoc-gen-go`](https://github.com/golang/protobuf#parameters).
|
|
||||||
|
|
||||||
In addition we also support the `request_context` parameter in order to use the `http.Request`'s Context (only for Go 1.7 and above).
|
|
||||||
This parameter can be useful to pass request scoped context between the gateway and the gRPC service.
|
|
||||||
|
|
||||||
`protoc-gen-grpc-gateway` also supports some more command line flags to control logging. You can give these flags together with parameters above. Run `protoc-gen-grpc-gateway --help` for more details about the flags.
|
|
||||||
|
|
||||||
## More Examples
|
|
||||||
More examples are available under `examples` directory.
|
|
||||||
* `examplepb/echo_service.proto`, `examplepb/a_bit_of_everything.proto`: service definition
|
|
||||||
* `examplepb/echo_service.pb.go`, `examplepb/a_bit_of_everything.pb.go`: [generated] stub of the service
|
|
||||||
* `examplepb/echo_service.pb.gw.go`, `examplepb/a_bit_of_everything.pb.gw.go`: [generated] reverse proxy for the service
|
|
||||||
* `server/main.go`: service implementation
|
|
||||||
* `main.go`: entrypoint of the generated reverse proxy
|
|
||||||
|
|
||||||
To use the same port for custom HTTP handlers (e.g. serving `swagger.json`), gRPC-gateway, and a gRPC server, see [this code example by CoreOS](https://github.com/philips/grpc-gateway-example/blob/master/cmd/serve.go) (and its accompanying [blog post](https://coreos.com/blog/gRPC-protobufs-swagger.html))
|
|
||||||
|
|
||||||
## Features
|
|
||||||
### Supported
|
|
||||||
* Generating JSON API handlers
|
|
||||||
* Method parameters in request body
|
|
||||||
* Method parameters in request path
|
|
||||||
* Method parameters in query string
|
|
||||||
* Enum fields in path parameter (including repeated enum fields).
|
|
||||||
* Mapping streaming APIs to newline-delimited JSON streams
|
|
||||||
* Mapping HTTP headers with `Grpc-Metadata-` prefix to gRPC metadata (prefixed with `grpcgateway-`)
|
|
||||||
* Optionally emitting API definition for [Swagger](http://swagger.io).
|
|
||||||
* Setting [gRPC timeouts](http://www.grpc.io/docs/guides/wire.html) through inbound HTTP `Grpc-Timeout` header.
|
|
||||||
|
|
||||||
### Want to support
|
|
||||||
But not yet.
|
|
||||||
* bytes fields in path parameter. #5
|
|
||||||
* Optionally generating the entrypoint. #8
|
|
||||||
* `import_path` parameter
|
|
||||||
|
|
||||||
### No plan to support
|
|
||||||
But patch is welcome.
|
|
||||||
* Method parameters in HTTP headers
|
|
||||||
* Handling trailer metadata
|
|
||||||
* Encoding request/response body in XML
|
|
||||||
* True bi-directional streaming. (Probably impossible?)
|
|
||||||
|
|
||||||
# Mapping gRPC to HTTP
|
|
||||||
|
|
||||||
* [How gRPC error codes map to HTTP status codes in the response](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L15)
|
|
||||||
* HTTP request source IP is added as `X-Forwarded-For` gRPC request header
|
|
||||||
* HTTP request host is added as `X-Forwarded-Host` gRPC request header
|
|
||||||
* HTTP `Authorization` header is added as `authorization` gRPC request header
|
|
||||||
* Remaining Permanent HTTP header keys (as specified by the IANA [here](http://www.iana.org/assignments/message-headers/message-headers.xhtml) are prefixed with `grpcgateway-` and added with their values to gRPC request header
|
|
||||||
* HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata (prefixed with `grpcgateway-`)
|
|
||||||
* While configurable, the default {un,}marshaling uses [jsonpb](https://godoc.org/github.com/golang/protobuf/jsonpb) with `OrigName: true`.
|
|
||||||
|
|
||||||
# Contribution
|
|
||||||
See [CONTRIBUTING.md](http://github.com/grpc-ecosystem/grpc-gateway/blob/master/CONTRIBUTING.md).
|
|
||||||
|
|
||||||
# License
|
|
||||||
grpc-gateway is licensed under the BSD 3-Clause License.
|
|
||||||
See [LICENSE.txt](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt) for more details.
|
|
3
vendor/github.com/grpc-ecosystem/grpc-gateway/bin/.gitignore
generated
vendored
3
vendor/github.com/grpc-ecosystem/grpc-gateway/bin/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
/protoc-gen-go
|
|
||||||
/protoc-gen-grpc-gateway
|
|
||||||
/protoc-gen-swagger
|
|
2
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/.gitignore
generated
vendored
2
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/.gitignore
generated
vendored
@ -1,2 +0,0 @@
|
|||||||
/bower_components
|
|
||||||
/node_modules
|
|
31
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/README.md
generated
vendored
31
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/README.md
generated
vendored
@ -1,31 +0,0 @@
|
|||||||
# Browser example
|
|
||||||
|
|
||||||
This directory contains an example use of grpc-gateway with web browsers.
|
|
||||||
The following commands automatically runs integration tests with phantomjs.
|
|
||||||
|
|
||||||
```shell-session
|
|
||||||
$ npm install -g gulp-cli
|
|
||||||
$ npm install
|
|
||||||
$ gulp
|
|
||||||
```
|
|
||||||
|
|
||||||
## Other examples
|
|
||||||
|
|
||||||
### Very simple example
|
|
||||||
Run
|
|
||||||
```shell-session
|
|
||||||
$ gulp bower
|
|
||||||
$ gulp backends
|
|
||||||
```
|
|
||||||
|
|
||||||
then, open `index.html`.
|
|
||||||
|
|
||||||
|
|
||||||
### Integration test with your browser
|
|
||||||
|
|
||||||
Run
|
|
||||||
```shell-session
|
|
||||||
$ gulp serve
|
|
||||||
```
|
|
||||||
|
|
||||||
then, open `http://localhost:8000` with your browser.
|
|
@ -1,185 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var SwaggerClient = require('swagger-client');
|
|
||||||
|
|
||||||
describe('ABitOfEverythingService', function() {
|
|
||||||
var client;
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
new SwaggerClient({
|
|
||||||
url: "http://localhost:8080/swagger/a_bit_of_everything.swagger.json",
|
|
||||||
usePromise: true,
|
|
||||||
}).then(function(c) {
|
|
||||||
client = c;
|
|
||||||
}).catch(function(err) {
|
|
||||||
done.fail(err);
|
|
||||||
}).then(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Create', function() {
|
|
||||||
var created;
|
|
||||||
var expected = {
|
|
||||||
float_value: 1.5,
|
|
||||||
double_value: 2.5,
|
|
||||||
int64_value: "4294967296",
|
|
||||||
uint64_value: "9223372036854775807",
|
|
||||||
int32_value: -2147483648,
|
|
||||||
fixed64_value: "9223372036854775807",
|
|
||||||
fixed32_value: 4294967295,
|
|
||||||
bool_value: true,
|
|
||||||
string_value: "strprefix/foo",
|
|
||||||
uint32_value: 4294967295,
|
|
||||||
sfixed32_value: 2147483647,
|
|
||||||
sfixed64_value: "-4611686018427387904",
|
|
||||||
sint32_value: 2147483647,
|
|
||||||
sint64_value: "4611686018427387903",
|
|
||||||
nonConventionalNameValue: "camelCase",
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
client.ABitOfEverythingService.Create(expected).then(function(resp) {
|
|
||||||
created = resp.obj;
|
|
||||||
}).catch(function(err) {
|
|
||||||
done.fail(err);
|
|
||||||
}).then(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should assign id', function() {
|
|
||||||
expect(created.uuid).not.toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should echo the request back', function() {
|
|
||||||
delete created.uuid;
|
|
||||||
expect(created).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('CreateBody', function() {
|
|
||||||
var created;
|
|
||||||
var expected = {
|
|
||||||
float_value: 1.5,
|
|
||||||
double_value: 2.5,
|
|
||||||
int64_value: "4294967296",
|
|
||||||
uint64_value: "9223372036854775807",
|
|
||||||
int32_value: -2147483648,
|
|
||||||
fixed64_value: "9223372036854775807",
|
|
||||||
fixed32_value: 4294967295,
|
|
||||||
bool_value: true,
|
|
||||||
string_value: "strprefix/foo",
|
|
||||||
uint32_value: 4294967295,
|
|
||||||
sfixed32_value: 2147483647,
|
|
||||||
sfixed64_value: "-4611686018427387904",
|
|
||||||
sint32_value: 2147483647,
|
|
||||||
sint64_value: "4611686018427387903",
|
|
||||||
nonConventionalNameValue: "camelCase",
|
|
||||||
|
|
||||||
nested: [
|
|
||||||
{ name: "bar", amount: 10 },
|
|
||||||
{ name: "baz", amount: 20 },
|
|
||||||
],
|
|
||||||
repeated_string_value: ["a", "b", "c"],
|
|
||||||
oneof_string: "x",
|
|
||||||
// TODO(yugui) Support enum by name
|
|
||||||
map_value: { a: 1, b: 2 },
|
|
||||||
mapped_string_value: { a: "x", b: "y" },
|
|
||||||
mapped_nested_value: {
|
|
||||||
a: { name: "x", amount: 1 },
|
|
||||||
b: { name: "y", amount: 2 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
client.ABitOfEverythingService.CreateBody({
|
|
||||||
body: expected,
|
|
||||||
}).then(function(resp) {
|
|
||||||
created = resp.obj;
|
|
||||||
}).catch(function(err) {
|
|
||||||
done.fail(err);
|
|
||||||
}).then(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should assign id', function() {
|
|
||||||
expect(created.uuid).not.toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should echo the request back', function() {
|
|
||||||
delete created.uuid;
|
|
||||||
expect(created).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lookup', function() {
|
|
||||||
var created;
|
|
||||||
var expected = {
|
|
||||||
bool_value: true,
|
|
||||||
string_value: "strprefix/foo",
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
client.ABitOfEverythingService.CreateBody({
|
|
||||||
body: expected,
|
|
||||||
}).then(function(resp) {
|
|
||||||
created = resp.obj;
|
|
||||||
}).catch(function(err) {
|
|
||||||
fail(err);
|
|
||||||
}).finally(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should look up an object by uuid', function(done) {
|
|
||||||
client.ABitOfEverythingService.Lookup({
|
|
||||||
uuid: created.uuid
|
|
||||||
}).then(function(resp) {
|
|
||||||
expect(resp.obj).toEqual(created);
|
|
||||||
}).catch(function(err) {
|
|
||||||
fail(err.errObj);
|
|
||||||
}).finally(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail if no such object', function(done) {
|
|
||||||
client.ABitOfEverythingService.Lookup({
|
|
||||||
uuid: 'not_exist',
|
|
||||||
}).then(function(resp) {
|
|
||||||
fail('expected failure but succeeded');
|
|
||||||
}).catch(function(err) {
|
|
||||||
expect(err.status).toBe(404);
|
|
||||||
}).finally(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Delete', function() {
|
|
||||||
var created;
|
|
||||||
var expected = {
|
|
||||||
bool_value: true,
|
|
||||||
string_value: "strprefix/foo",
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
client.ABitOfEverythingService.CreateBody({
|
|
||||||
body: expected,
|
|
||||||
}).then(function(resp) {
|
|
||||||
created = resp.obj;
|
|
||||||
}).catch(function(err) {
|
|
||||||
fail(err);
|
|
||||||
}).finally(done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete an object by id', function(done) {
|
|
||||||
client.ABitOfEverythingService.Delete({
|
|
||||||
uuid: created.uuid
|
|
||||||
}).then(function(resp) {
|
|
||||||
expect(resp.obj).toEqual({});
|
|
||||||
}).catch(function(err) {
|
|
||||||
fail(err.errObj);
|
|
||||||
}).then(function() {
|
|
||||||
return client.ABitOfEverythingService.Lookup({
|
|
||||||
uuid: created.uuid
|
|
||||||
});
|
|
||||||
}).then(function(resp) {
|
|
||||||
fail('expected failure but succeeded');
|
|
||||||
}). catch(function(err) {
|
|
||||||
expect(err.status).toBe(404);
|
|
||||||
}).finally(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
2
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/bin/.gitignore
generated
vendored
2
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/bin/.gitignore
generated
vendored
@ -1,2 +0,0 @@
|
|||||||
/*
|
|
||||||
!/.gitignore
|
|
21
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/bower.json
generated
vendored
21
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/bower.json
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "grpc-gateway-example-browser",
|
|
||||||
"description": "Example use of grpc-gateway from browser",
|
|
||||||
"main": "index.js",
|
|
||||||
"authors": [
|
|
||||||
"Yuki Yugui Sonoda <yugui@gengo.com>"
|
|
||||||
],
|
|
||||||
"license": "SEE LICENSE IN LICENSE file",
|
|
||||||
"homepage": "https://github.com/grpc-ecosystem/grpc-gateway",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"swagger-js": "~> 2.1"
|
|
||||||
},
|
|
||||||
"ignore": [
|
|
||||||
"**/.*",
|
|
||||||
"node_modules",
|
|
||||||
"bower_components",
|
|
||||||
"test",
|
|
||||||
"tests"
|
|
||||||
]
|
|
||||||
}
|
|
43
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/echo_service.spec.js
generated
vendored
43
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/echo_service.spec.js
generated
vendored
@ -1,43 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var SwaggerClient = require('swagger-client');
|
|
||||||
|
|
||||||
describe('EchoService', function() {
|
|
||||||
var client;
|
|
||||||
|
|
||||||
beforeEach(function(done) {
|
|
||||||
new SwaggerClient({
|
|
||||||
url: "http://localhost:8080/swagger/echo_service.swagger.json",
|
|
||||||
usePromise: true,
|
|
||||||
}).then(function(c) {
|
|
||||||
client = c;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Echo', function() {
|
|
||||||
it('should echo the request back', function(done) {
|
|
||||||
client.EchoService.Echo(
|
|
||||||
{id: "foo"},
|
|
||||||
{responseContentType: "application/json"}
|
|
||||||
).then(function(resp) {
|
|
||||||
expect(resp.obj).toEqual({id: "foo"});
|
|
||||||
}).catch(function(err) {
|
|
||||||
done.fail(err);
|
|
||||||
}).then(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('EchoBody', function() {
|
|
||||||
it('should echo the request back', function(done) {
|
|
||||||
client.EchoService.EchoBody(
|
|
||||||
{body: {id: "foo"}},
|
|
||||||
{responseContentType: "application/json"}
|
|
||||||
).then(function(resp) {
|
|
||||||
expect(resp.obj).toEqual({id: "foo"});
|
|
||||||
}).catch(function(err) {
|
|
||||||
done.fail(err);
|
|
||||||
}).then(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
81
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/gulpfile.js
generated
vendored
81
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/gulpfile.js
generated
vendored
@ -1,81 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var gulp = require('gulp');
|
|
||||||
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
var bower = require('gulp-bower');
|
|
||||||
var exit = require('gulp-exit');
|
|
||||||
var gprocess = require('gulp-process');
|
|
||||||
var shell = require('gulp-shell');
|
|
||||||
var jasmineBrowser = require('gulp-jasmine-browser');
|
|
||||||
var webpack = require('webpack-stream');
|
|
||||||
|
|
||||||
gulp.task('bower', function(){
|
|
||||||
return bower();
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('server', shell.task([
|
|
||||||
'go build -o bin/example-server github.com/grpc-ecosystem/grpc-gateway/examples/server/cmd/example-server',
|
|
||||||
]));
|
|
||||||
|
|
||||||
gulp.task('gateway', shell.task([
|
|
||||||
'go build -o bin/example-gw github.com/grpc-ecosystem/grpc-gateway/examples',
|
|
||||||
]));
|
|
||||||
|
|
||||||
gulp.task('serve-server', ['server'], function(){
|
|
||||||
gprocess.start('server-server', 'bin/example-server', [
|
|
||||||
'--logtostderr',
|
|
||||||
]);
|
|
||||||
gulp.watch('bin/example-server', ['serve-server']);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('serve-gateway', ['gateway', 'serve-server'], function(){
|
|
||||||
gprocess.start('gateway-server', 'bin/example-gw', [
|
|
||||||
'--logtostderr', '--swagger_dir', path.join(__dirname, "../examplepb"),
|
|
||||||
]);
|
|
||||||
gulp.watch('bin/example-gateway', ['serve-gateway']);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('backends', ['serve-gateway', 'serve-server']);
|
|
||||||
|
|
||||||
var specFiles = ['*.spec.js'];
|
|
||||||
gulp.task('test', ['backends'], function(done) {
|
|
||||||
return gulp.src(specFiles)
|
|
||||||
.pipe(webpack({output: {filename: 'spec.js'}}))
|
|
||||||
.pipe(jasmineBrowser.specRunner({
|
|
||||||
console: true,
|
|
||||||
sourceMappedStacktrace: true,
|
|
||||||
}))
|
|
||||||
.pipe(jasmineBrowser.headless({
|
|
||||||
findOpenPort: true,
|
|
||||||
catch: true,
|
|
||||||
throwFailures: true,
|
|
||||||
}))
|
|
||||||
.on('error', function(err) {
|
|
||||||
done(err);
|
|
||||||
process.exit(1);
|
|
||||||
})
|
|
||||||
.pipe(exit());
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('serve', ['backends'], function(done) {
|
|
||||||
var JasminePlugin = require('gulp-jasmine-browser/webpack/jasmine-plugin');
|
|
||||||
var plugin = new JasminePlugin();
|
|
||||||
|
|
||||||
return gulp.src(specFiles)
|
|
||||||
.pipe(webpack({
|
|
||||||
output: {filename: 'spec.js'},
|
|
||||||
watch: true,
|
|
||||||
plugins: [plugin],
|
|
||||||
}))
|
|
||||||
.pipe(jasmineBrowser.specRunner({
|
|
||||||
sourceMappedStacktrace: true,
|
|
||||||
}))
|
|
||||||
.pipe(jasmineBrowser.server({
|
|
||||||
port: 8000,
|
|
||||||
whenReady: plugin.whenReady,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('default', ['test']);
|
|
22
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/index.html
generated
vendored
22
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/index.html
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script type="application/javascript" src="bower_components/swagger-js/browser/swagger-client.min.js"></script>
|
|
||||||
<script type="application/javascript">
|
|
||||||
window.client = new SwaggerClient({
|
|
||||||
url: "http://localhost:8080/swagger/echo_service.swagger.json",
|
|
||||||
success: function() {
|
|
||||||
client.EchoService.Echo(
|
|
||||||
{id: "foo"},
|
|
||||||
{responseContentType: "application/json"},
|
|
||||||
function(data) {
|
|
||||||
document.getElementById("echoBack").innerHTML = data.obj.id;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="echoBack"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
23
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/package.json
generated
vendored
23
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/browser/package.json
generated
vendored
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "grpc-gateway-example",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Example use of grpc-gateway from browser",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "SEE LICENSE IN LICENSE.txt",
|
|
||||||
"devDependencies": {
|
|
||||||
"bower": "^1.7.9",
|
|
||||||
"gulp": "^3.9.1",
|
|
||||||
"gulp-bower": "0.0.13",
|
|
||||||
"gulp-exit": "0.0.2",
|
|
||||||
"gulp-jasmine-browser": "^1.3.2",
|
|
||||||
"gulp-process": "^0.1.2",
|
|
||||||
"gulp-shell": "^0.5.2",
|
|
||||||
"jasmine": "^2.4.1",
|
|
||||||
"phantomjs": "^2.1.7",
|
|
||||||
"swagger-client": "^2.1.28",
|
|
||||||
"webpack-stream": "^3.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
162
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/client_test.go
generated
vendored
162
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/client_test.go
generated
vendored
@ -1,162 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestClientIntegration(t *testing.T) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEchoClient(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cl := echo.NewEchoServiceApiWithBasePath("http://localhost:8080")
|
|
||||||
resp, err := cl.Echo("foo")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(`cl.Echo("foo") failed with %v; want success`, err)
|
|
||||||
}
|
|
||||||
if got, want := resp.Id, "foo"; got != want {
|
|
||||||
t.Errorf("resp.Id = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEchoBodyClient(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cl := echo.NewEchoServiceApiWithBasePath("http://localhost:8080")
|
|
||||||
req := echo.ExamplepbSimpleMessage{Id: "foo"}
|
|
||||||
resp, err := cl.EchoBody(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("cl.EchoBody(%#v) failed with %v; want success", req, err)
|
|
||||||
}
|
|
||||||
if got, want := resp.Id, "foo"; got != want {
|
|
||||||
t.Errorf("resp.Id = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAbitOfEverythingClient(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cl := abe.NewABitOfEverythingServiceApiWithBasePath("http://localhost:8080")
|
|
||||||
testABEClientCreate(t, cl)
|
|
||||||
testABEClientCreateBody(t, cl)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
|
|
||||||
want := abe.ExamplepbABitOfEverything{
|
|
||||||
FloatValue: 1.5,
|
|
||||||
DoubleValue: 2.5,
|
|
||||||
Int64Value: "4294967296",
|
|
||||||
Uint64Value: "9223372036854775807",
|
|
||||||
Int32Value: -2147483648,
|
|
||||||
Fixed64Value: "9223372036854775807",
|
|
||||||
Fixed32Value: 4294967295,
|
|
||||||
BoolValue: true,
|
|
||||||
StringValue: "strprefix/foo",
|
|
||||||
Uint32Value: 4294967295,
|
|
||||||
Sfixed32Value: 2147483647,
|
|
||||||
Sfixed64Value: "-4611686018427387904",
|
|
||||||
Sint32Value: 2147483647,
|
|
||||||
Sint64Value: "4611686018427387903",
|
|
||||||
NonConventionalNameValue: "camelCase",
|
|
||||||
}
|
|
||||||
resp, err := cl.Create(
|
|
||||||
want.FloatValue,
|
|
||||||
want.DoubleValue,
|
|
||||||
want.Int64Value,
|
|
||||||
want.Uint64Value,
|
|
||||||
want.Int32Value,
|
|
||||||
want.Fixed64Value,
|
|
||||||
want.Fixed32Value,
|
|
||||||
want.BoolValue,
|
|
||||||
want.StringValue,
|
|
||||||
want.Uint32Value,
|
|
||||||
want.Sfixed32Value,
|
|
||||||
want.Sfixed64Value,
|
|
||||||
want.Sint32Value,
|
|
||||||
want.Sint64Value,
|
|
||||||
want.NonConventionalNameValue,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("cl.Create(%#v) failed with %v; want success", want, err)
|
|
||||||
}
|
|
||||||
if resp.Uuid == "" {
|
|
||||||
t.Errorf("resp.Uuid is empty; want not empty")
|
|
||||||
}
|
|
||||||
resp.Uuid = ""
|
|
||||||
if got := resp; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("resp = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEClientCreateBody(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
|
|
||||||
t.Log("TODO: support enum")
|
|
||||||
return
|
|
||||||
|
|
||||||
want := abe.ExamplepbABitOfEverything{
|
|
||||||
FloatValue: 1.5,
|
|
||||||
DoubleValue: 2.5,
|
|
||||||
Int64Value: "4294967296",
|
|
||||||
Uint64Value: "9223372036854775807",
|
|
||||||
Int32Value: -2147483648,
|
|
||||||
Fixed64Value: "9223372036854775807",
|
|
||||||
Fixed32Value: 4294967295,
|
|
||||||
BoolValue: true,
|
|
||||||
StringValue: "strprefix/foo",
|
|
||||||
Uint32Value: 4294967295,
|
|
||||||
Sfixed32Value: 2147483647,
|
|
||||||
Sfixed64Value: "-4611686018427387904",
|
|
||||||
Sint32Value: 2147483647,
|
|
||||||
Sint64Value: "4611686018427387903",
|
|
||||||
NonConventionalNameValue: "camelCase",
|
|
||||||
|
|
||||||
Nested: []abe.ABitOfEverythingNested{
|
|
||||||
{
|
|
||||||
Name: "bar",
|
|
||||||
Amount: 10,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "baz",
|
|
||||||
Amount: 20,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RepeatedStringValue: []string{"a", "b", "c"},
|
|
||||||
OneofString: "x",
|
|
||||||
MapValue: map[string]abe.ExamplepbNumericEnum{
|
|
||||||
// "a": abe.ExamplepbNumericEnum_ONE,
|
|
||||||
// "b": abe.ExamplepbNumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
MappedStringValue: map[string]string{
|
|
||||||
"a": "x",
|
|
||||||
"b": "y",
|
|
||||||
},
|
|
||||||
MappedNestedValue: map[string]abe.ABitOfEverythingNested{
|
|
||||||
"a": {Name: "x", Amount: 1},
|
|
||||||
"b": {Name: "y", Amount: 2},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
resp, err := cl.CreateBody(want)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("cl.CreateBody(%#v) failed with %v; want success", want, err)
|
|
||||||
}
|
|
||||||
if resp.Uuid == "" {
|
|
||||||
t.Errorf("resp.Uuid is empty; want not empty")
|
|
||||||
}
|
|
||||||
resp.Uuid = ""
|
|
||||||
if got := resp; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("resp = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type ABitOfEverythingNested struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
Amount int64 `json:"amount,omitempty"`
|
|
||||||
Ok NestedDeepEnum `json:"ok,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
@ -1,764 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"github.com/dghubble/sling"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ABitOfEverythingServiceApi struct {
|
|
||||||
basePath string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewABitOfEverythingServiceApi() *ABitOfEverythingServiceApi{
|
|
||||||
return &ABitOfEverythingServiceApi {
|
|
||||||
basePath: "http://localhost",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewABitOfEverythingServiceApiWithBasePath(basePath string) *ABitOfEverythingServiceApi{
|
|
||||||
return &ABitOfEverythingServiceApi {
|
|
||||||
basePath: basePath,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param floatValue
|
|
||||||
* @param doubleValue
|
|
||||||
* @param int64Value
|
|
||||||
* @param uint64Value
|
|
||||||
* @param int32Value
|
|
||||||
* @param fixed64Value
|
|
||||||
* @param fixed32Value
|
|
||||||
* @param boolValue
|
|
||||||
* @param stringValue
|
|
||||||
* @param uint32Value
|
|
||||||
* @param sfixed32Value
|
|
||||||
* @param sfixed64Value
|
|
||||||
* @param sint32Value
|
|
||||||
* @param sint64Value
|
|
||||||
* @param nonConventionalNameValue
|
|
||||||
* @return ExamplepbABitOfEverything
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Create (floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string) (ExamplepbABitOfEverything, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Create (floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string) (ExamplepbABitOfEverything, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}"
|
|
||||||
path = strings.Replace(path, "{" + "float_value" + "}", fmt.Sprintf("%v", floatValue), -1)
|
|
||||||
path = strings.Replace(path, "{" + "double_value" + "}", fmt.Sprintf("%v", doubleValue), -1)
|
|
||||||
path = strings.Replace(path, "{" + "int64_value" + "}", fmt.Sprintf("%v", int64Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "uint64_value" + "}", fmt.Sprintf("%v", uint64Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "int32_value" + "}", fmt.Sprintf("%v", int32Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "fixed64_value" + "}", fmt.Sprintf("%v", fixed64Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "fixed32_value" + "}", fmt.Sprintf("%v", fixed32Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "bool_value" + "}", fmt.Sprintf("%v", boolValue), -1)
|
|
||||||
path = strings.Replace(path, "{" + "string_value" + "}", fmt.Sprintf("%v", stringValue), -1)
|
|
||||||
path = strings.Replace(path, "{" + "uint32_value" + "}", fmt.Sprintf("%v", uint32Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "sfixed32_value" + "}", fmt.Sprintf("%v", sfixed32Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "sfixed64_value" + "}", fmt.Sprintf("%v", sfixed64Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "sint32_value" + "}", fmt.Sprintf("%v", sint32Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "sint64_value" + "}", fmt.Sprintf("%v", sint64Value), -1)
|
|
||||||
path = strings.Replace(path, "{" + "nonConventionalNameValue" + "}", fmt.Sprintf("%v", nonConventionalNameValue), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbABitOfEverything)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param body
|
|
||||||
* @return ExamplepbABitOfEverything
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) CreateBody (body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) CreateBody (body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// body params
|
|
||||||
_sling = _sling.BodyJSON(body)
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbABitOfEverything)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param singleNestedName
|
|
||||||
* @param body
|
|
||||||
* @return ExamplepbABitOfEverything
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) DeepPathEcho (singleNestedName string, body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) DeepPathEcho (singleNestedName string, body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/{single_nested.name}"
|
|
||||||
path = strings.Replace(path, "{" + "single_nested.name" + "}", fmt.Sprintf("%v", singleNestedName), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// body params
|
|
||||||
_sling = _sling.BodyJSON(body)
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbABitOfEverything)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param uuid
|
|
||||||
* @return ProtobufEmpty
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Delete (uuid string) (ProtobufEmpty, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Delete (uuid string) (ProtobufEmpty, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Delete(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ProtobufEmpty)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* @return SubStringMessage
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Echo (value string) (SubStringMessage, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Echo (value string) (SubStringMessage, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/echo/{value}"
|
|
||||||
path = strings.Replace(path, "{" + "value" + "}", fmt.Sprintf("%v", value), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(SubStringMessage)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* @return SubStringMessage
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Echo_1 (value string) (SubStringMessage, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Echo_1 (value string) (SubStringMessage, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/example/echo"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
type QueryParams struct {
|
|
||||||
value string `url:"value,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
||||||
_sling = _sling.QueryStruct(&QueryParams{ value: value })
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(SubStringMessage)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param body
|
|
||||||
* @return SubStringMessage
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/example/echo"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// body params
|
|
||||||
_sling = _sling.BodyJSON(body)
|
|
||||||
|
|
||||||
var successPayload = new(SubStringMessage)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param uuid
|
|
||||||
* @param singleNestedName name is nested field.
|
|
||||||
* @param singleNestedAmount
|
|
||||||
* @param singleNestedOk - FALSE: FALSE is false.\n - TRUE: TRUE is true.
|
|
||||||
* @param floatValue
|
|
||||||
* @param doubleValue
|
|
||||||
* @param int64Value
|
|
||||||
* @param uint64Value
|
|
||||||
* @param int32Value
|
|
||||||
* @param fixed64Value
|
|
||||||
* @param fixed32Value
|
|
||||||
* @param boolValue
|
|
||||||
* @param stringValue
|
|
||||||
* @param uint32Value TODO(yugui) add bytes_value.
|
|
||||||
* @param enumValue - ZERO: ZERO means 0\n - ONE: ONE means 1
|
|
||||||
* @param sfixed32Value
|
|
||||||
* @param sfixed64Value
|
|
||||||
* @param sint32Value
|
|
||||||
* @param sint64Value
|
|
||||||
* @param repeatedStringValue
|
|
||||||
* @param oneofString
|
|
||||||
* @param nonConventionalNameValue
|
|
||||||
* @param timestampValue
|
|
||||||
* @param repeatedEnumValue repeated enum value. it is comma-separated in query.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1
|
|
||||||
* @return ProtobufEmpty
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) GetQuery (uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, enumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (ProtobufEmpty, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) GetQuery (uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, enumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (ProtobufEmpty, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/query/{uuid}"
|
|
||||||
path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
type QueryParams struct {
|
|
||||||
singleNestedName string `url:"single_nested.name,omitempty"`
|
|
||||||
singleNestedAmount int64 `url:"single_nested.amount,omitempty"`
|
|
||||||
singleNestedOk string `url:"single_nested.ok,omitempty"`
|
|
||||||
floatValue float32 `url:"float_value,omitempty"`
|
|
||||||
doubleValue float64 `url:"double_value,omitempty"`
|
|
||||||
int64Value string `url:"int64_value,omitempty"`
|
|
||||||
uint64Value string `url:"uint64_value,omitempty"`
|
|
||||||
int32Value int32 `url:"int32_value,omitempty"`
|
|
||||||
fixed64Value string `url:"fixed64_value,omitempty"`
|
|
||||||
fixed32Value int64 `url:"fixed32_value,omitempty"`
|
|
||||||
boolValue bool `url:"bool_value,omitempty"`
|
|
||||||
stringValue string `url:"string_value,omitempty"`
|
|
||||||
uint32Value int64 `url:"uint32_value,omitempty"`
|
|
||||||
enumValue string `url:"enum_value,omitempty"`
|
|
||||||
sfixed32Value int32 `url:"sfixed32_value,omitempty"`
|
|
||||||
sfixed64Value string `url:"sfixed64_value,omitempty"`
|
|
||||||
sint32Value int32 `url:"sint32_value,omitempty"`
|
|
||||||
sint64Value string `url:"sint64_value,omitempty"`
|
|
||||||
repeatedStringValue []string `url:"repeated_string_value,omitempty"`
|
|
||||||
oneofString string `url:"oneof_string,omitempty"`
|
|
||||||
nonConventionalNameValue string `url:"nonConventionalNameValue,omitempty"`
|
|
||||||
timestampValue time.Time `url:"timestamp_value,omitempty"`
|
|
||||||
repeatedEnumValue []string `url:"repeated_enum_value,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
||||||
_sling = _sling.QueryStruct(&QueryParams{ singleNestedName: singleNestedName,singleNestedAmount: singleNestedAmount,singleNestedOk: singleNestedOk,floatValue: floatValue,doubleValue: doubleValue,int64Value: int64Value,uint64Value: uint64Value,int32Value: int32Value,fixed64Value: fixed64Value,fixed32Value: fixed32Value,boolValue: boolValue,stringValue: stringValue,uint32Value: uint32Value,enumValue: enumValue,sfixed32Value: sfixed32Value,sfixed64Value: sfixed64Value,sint32Value: sint32Value,sint64Value: sint64Value,repeatedStringValue: repeatedStringValue,oneofString: oneofString,nonConventionalNameValue: nonConventionalNameValue,timestampValue: timestampValue,repeatedEnumValue: repeatedEnumValue })
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ProtobufEmpty)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param uuid
|
|
||||||
* @return ExamplepbABitOfEverything
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Lookup (uuid string) (ExamplepbABitOfEverything, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Lookup (uuid string) (ExamplepbABitOfEverything, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbABitOfEverything)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return ProtobufEmpty
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Timeout () (ProtobufEmpty, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Timeout () (ProtobufEmpty, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/example/timeout"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ProtobufEmpty)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param uuid
|
|
||||||
* @param body
|
|
||||||
* @return ProtobufEmpty
|
|
||||||
*/
|
|
||||||
//func (a ABitOfEverythingServiceApi) Update (uuid string, body ExamplepbABitOfEverything) (ProtobufEmpty, error) {
|
|
||||||
func (a ABitOfEverythingServiceApi) Update (uuid string, body ExamplepbABitOfEverything) (ProtobufEmpty, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Put(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// body params
|
|
||||||
_sling = _sling.BodyJSON(body)
|
|
||||||
|
|
||||||
var successPayload = new(ProtobufEmpty)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ExamplepbABitOfEverything struct {
|
|
||||||
SingleNested ABitOfEverythingNested `json:"single_nested,omitempty"`
|
|
||||||
Uuid string `json:"uuid,omitempty"`
|
|
||||||
Nested []ABitOfEverythingNested `json:"nested,omitempty"`
|
|
||||||
FloatValue float32 `json:"float_value,omitempty"`
|
|
||||||
DoubleValue float64 `json:"double_value,omitempty"`
|
|
||||||
Int64Value string `json:"int64_value,omitempty"`
|
|
||||||
Uint64Value string `json:"uint64_value,omitempty"`
|
|
||||||
Int32Value int32 `json:"int32_value,omitempty"`
|
|
||||||
Fixed64Value string `json:"fixed64_value,omitempty"`
|
|
||||||
Fixed32Value int64 `json:"fixed32_value,omitempty"`
|
|
||||||
BoolValue bool `json:"bool_value,omitempty"`
|
|
||||||
StringValue string `json:"string_value,omitempty"`
|
|
||||||
Uint32Value int64 `json:"uint32_value,omitempty"`
|
|
||||||
EnumValue ExamplepbNumericEnum `json:"enum_value,omitempty"`
|
|
||||||
Sfixed32Value int32 `json:"sfixed32_value,omitempty"`
|
|
||||||
Sfixed64Value string `json:"sfixed64_value,omitempty"`
|
|
||||||
Sint32Value int32 `json:"sint32_value,omitempty"`
|
|
||||||
Sint64Value string `json:"sint64_value,omitempty"`
|
|
||||||
RepeatedStringValue []string `json:"repeated_string_value,omitempty"`
|
|
||||||
OneofEmpty ProtobufEmpty `json:"oneof_empty,omitempty"`
|
|
||||||
OneofString string `json:"oneof_string,omitempty"`
|
|
||||||
MapValue map[string]ExamplepbNumericEnum `json:"map_value,omitempty"`
|
|
||||||
MappedStringValue map[string]string `json:"mapped_string_value,omitempty"`
|
|
||||||
MappedNestedValue map[string]ABitOfEverythingNested `json:"mapped_nested_value,omitempty"`
|
|
||||||
NonConventionalNameValue string `json:"nonConventionalNameValue,omitempty"`
|
|
||||||
TimestampValue time.Time `json:"timestamp_value,omitempty"`
|
|
||||||
RepeatedEnumValue []ExamplepbNumericEnum `json:"repeated_enum_value,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type ExamplepbNumericEnum struct {
|
|
||||||
|
|
||||||
}
|
|
8
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/NestedDeepEnum.go
generated
vendored
8
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/NestedDeepEnum.go
generated
vendored
@ -1,8 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type NestedDeepEnum struct {
|
|
||||||
|
|
||||||
}
|
|
10
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/ProtobufDuration.go
generated
vendored
10
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/ProtobufDuration.go
generated
vendored
@ -1,10 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProtobufDuration struct {
|
|
||||||
Seconds string `json:"seconds,omitempty"`
|
|
||||||
Nanos int32 `json:"nanos,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
8
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/ProtobufEmpty.go
generated
vendored
8
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/ProtobufEmpty.go
generated
vendored
@ -1,8 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProtobufEmpty struct {
|
|
||||||
|
|
||||||
}
|
|
9
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/Sub2IdMessage.go
generated
vendored
9
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/Sub2IdMessage.go
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type Sub2IdMessage struct {
|
|
||||||
Uuid string `json:"uuid,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package abe
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type SubStringMessage struct {
|
|
||||||
Value string `json:"value,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
145
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/EchoServiceApi.go
generated
vendored
145
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/EchoServiceApi.go
generated
vendored
@ -1,145 +0,0 @@
|
|||||||
package echo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"github.com/dghubble/sling"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EchoServiceApi struct {
|
|
||||||
basePath string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEchoServiceApi() *EchoServiceApi{
|
|
||||||
return &EchoServiceApi {
|
|
||||||
basePath: "http://localhost",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEchoServiceApiWithBasePath(basePath string) *EchoServiceApi{
|
|
||||||
return &EchoServiceApi {
|
|
||||||
basePath: basePath,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Echo method receives a simple message and returns it.
|
|
||||||
* The message posted as the id parameter will also be\nreturned.
|
|
||||||
* @param id
|
|
||||||
* @return ExamplepbSimpleMessage
|
|
||||||
*/
|
|
||||||
//func (a EchoServiceApi) Echo (id string) (ExamplepbSimpleMessage, error) {
|
|
||||||
func (a EchoServiceApi) Echo (id string) (ExamplepbSimpleMessage, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/echo/{id}"
|
|
||||||
path = strings.Replace(path, "{" + "id" + "}", fmt.Sprintf("%v", id), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbSimpleMessage)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* EchoBody method receives a simple message and returns it.
|
|
||||||
*
|
|
||||||
* @param body
|
|
||||||
* @return ExamplepbSimpleMessage
|
|
||||||
*/
|
|
||||||
//func (a EchoServiceApi) EchoBody (body ExamplepbSimpleMessage) (ExamplepbSimpleMessage, error) {
|
|
||||||
func (a EchoServiceApi) EchoBody (body ExamplepbSimpleMessage) (ExamplepbSimpleMessage, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v1/example/echo_body"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// body params
|
|
||||||
_sling = _sling.BodyJSON(body)
|
|
||||||
|
|
||||||
var successPayload = new(ExamplepbSimpleMessage)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
|
||||||
if failurePayload != nil {
|
|
||||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
|
||||||
// returned (and a JSON payload error present)
|
|
||||||
var str []byte
|
|
||||||
str, err = json.Marshal(failurePayload)
|
|
||||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
|
||||||
// This will return the JSON error body as a string
|
|
||||||
err = errors.New(string(str))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// So, there was no network-type error, and nothing in the failure payload,
|
|
||||||
// but we should still check the status code
|
|
||||||
if httpResponse == nil {
|
|
||||||
// This should never happen...
|
|
||||||
err = errors.New("No HTTP Response received.")
|
|
||||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
|
||||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package echo
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type ExamplepbSimpleMessage struct {
|
|
||||||
Id string `json:"id,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
958
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go
generated
vendored
958
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go
generated
vendored
@ -1,958 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/examplepb/a_bit_of_everything.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
import google_protobuf1 "github.com/golang/protobuf/ptypes/empty"
|
|
||||||
import google_protobuf2 "github.com/golang/protobuf/ptypes/duration"
|
|
||||||
import grpc_gateway_examples_sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
import sub2 "github.com/grpc-ecosystem/grpc-gateway/examples/sub2"
|
|
||||||
import google_protobuf3 "github.com/golang/protobuf/ptypes/timestamp"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// NumericEnum is one or zero.
|
|
||||||
type NumericEnum int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
// ZERO means 0
|
|
||||||
NumericEnum_ZERO NumericEnum = 0
|
|
||||||
// ONE means 1
|
|
||||||
NumericEnum_ONE NumericEnum = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
var NumericEnum_name = map[int32]string{
|
|
||||||
0: "ZERO",
|
|
||||||
1: "ONE",
|
|
||||||
}
|
|
||||||
var NumericEnum_value = map[string]int32{
|
|
||||||
"ZERO": 0,
|
|
||||||
"ONE": 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x NumericEnum) String() string {
|
|
||||||
return proto.EnumName(NumericEnum_name, int32(x))
|
|
||||||
}
|
|
||||||
func (NumericEnum) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
|
||||||
|
|
||||||
// DeepEnum is one or zero.
|
|
||||||
type ABitOfEverything_Nested_DeepEnum int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
// FALSE is false.
|
|
||||||
ABitOfEverything_Nested_FALSE ABitOfEverything_Nested_DeepEnum = 0
|
|
||||||
// TRUE is true.
|
|
||||||
ABitOfEverything_Nested_TRUE ABitOfEverything_Nested_DeepEnum = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
var ABitOfEverything_Nested_DeepEnum_name = map[int32]string{
|
|
||||||
0: "FALSE",
|
|
||||||
1: "TRUE",
|
|
||||||
}
|
|
||||||
var ABitOfEverything_Nested_DeepEnum_value = map[string]int32{
|
|
||||||
"FALSE": 0,
|
|
||||||
"TRUE": 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x ABitOfEverything_Nested_DeepEnum) String() string {
|
|
||||||
return proto.EnumName(ABitOfEverything_Nested_DeepEnum_name, int32(x))
|
|
||||||
}
|
|
||||||
func (ABitOfEverything_Nested_DeepEnum) EnumDescriptor() ([]byte, []int) {
|
|
||||||
return fileDescriptor1, []int{0, 0, 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intentionaly complicated message type to cover much features of Protobuf.
|
|
||||||
// NEXT ID: 27
|
|
||||||
type ABitOfEverything struct {
|
|
||||||
SingleNested *ABitOfEverything_Nested `protobuf:"bytes,25,opt,name=single_nested,json=singleNested" json:"single_nested,omitempty"`
|
|
||||||
Uuid string `protobuf:"bytes,1,opt,name=uuid" json:"uuid,omitempty"`
|
|
||||||
Nested []*ABitOfEverything_Nested `protobuf:"bytes,2,rep,name=nested" json:"nested,omitempty"`
|
|
||||||
FloatValue float32 `protobuf:"fixed32,3,opt,name=float_value,json=floatValue" json:"float_value,omitempty"`
|
|
||||||
DoubleValue float64 `protobuf:"fixed64,4,opt,name=double_value,json=doubleValue" json:"double_value,omitempty"`
|
|
||||||
Int64Value int64 `protobuf:"varint,5,opt,name=int64_value,json=int64Value" json:"int64_value,omitempty"`
|
|
||||||
Uint64Value uint64 `protobuf:"varint,6,opt,name=uint64_value,json=uint64Value" json:"uint64_value,omitempty"`
|
|
||||||
Int32Value int32 `protobuf:"varint,7,opt,name=int32_value,json=int32Value" json:"int32_value,omitempty"`
|
|
||||||
Fixed64Value uint64 `protobuf:"fixed64,8,opt,name=fixed64_value,json=fixed64Value" json:"fixed64_value,omitempty"`
|
|
||||||
Fixed32Value uint32 `protobuf:"fixed32,9,opt,name=fixed32_value,json=fixed32Value" json:"fixed32_value,omitempty"`
|
|
||||||
BoolValue bool `protobuf:"varint,10,opt,name=bool_value,json=boolValue" json:"bool_value,omitempty"`
|
|
||||||
StringValue string `protobuf:"bytes,11,opt,name=string_value,json=stringValue" json:"string_value,omitempty"`
|
|
||||||
// TODO(yugui) add bytes_value
|
|
||||||
Uint32Value uint32 `protobuf:"varint,13,opt,name=uint32_value,json=uint32Value" json:"uint32_value,omitempty"`
|
|
||||||
EnumValue NumericEnum `protobuf:"varint,14,opt,name=enum_value,json=enumValue,enum=grpc.gateway.examples.examplepb.NumericEnum" json:"enum_value,omitempty"`
|
|
||||||
Sfixed32Value int32 `protobuf:"fixed32,15,opt,name=sfixed32_value,json=sfixed32Value" json:"sfixed32_value,omitempty"`
|
|
||||||
Sfixed64Value int64 `protobuf:"fixed64,16,opt,name=sfixed64_value,json=sfixed64Value" json:"sfixed64_value,omitempty"`
|
|
||||||
Sint32Value int32 `protobuf:"zigzag32,17,opt,name=sint32_value,json=sint32Value" json:"sint32_value,omitempty"`
|
|
||||||
Sint64Value int64 `protobuf:"zigzag64,18,opt,name=sint64_value,json=sint64Value" json:"sint64_value,omitempty"`
|
|
||||||
RepeatedStringValue []string `protobuf:"bytes,19,rep,name=repeated_string_value,json=repeatedStringValue" json:"repeated_string_value,omitempty"`
|
|
||||||
// Types that are valid to be assigned to OneofValue:
|
|
||||||
// *ABitOfEverything_OneofEmpty
|
|
||||||
// *ABitOfEverything_OneofString
|
|
||||||
OneofValue isABitOfEverything_OneofValue `protobuf_oneof:"oneof_value"`
|
|
||||||
MapValue map[string]NumericEnum `protobuf:"bytes,22,rep,name=map_value,json=mapValue" json:"map_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=grpc.gateway.examples.examplepb.NumericEnum"`
|
|
||||||
MappedStringValue map[string]string `protobuf:"bytes,23,rep,name=mapped_string_value,json=mappedStringValue" json:"mapped_string_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
|
||||||
MappedNestedValue map[string]*ABitOfEverything_Nested `protobuf:"bytes,24,rep,name=mapped_nested_value,json=mappedNestedValue" json:"mapped_nested_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
|
||||||
NonConventionalNameValue string `protobuf:"bytes,26,opt,name=nonConventionalNameValue" json:"nonConventionalNameValue,omitempty"`
|
|
||||||
TimestampValue *google_protobuf3.Timestamp `protobuf:"bytes,27,opt,name=timestamp_value,json=timestampValue" json:"timestamp_value,omitempty"`
|
|
||||||
// repeated enum value. it is comma-separated in query
|
|
||||||
RepeatedEnumValue []NumericEnum `protobuf:"varint,28,rep,packed,name=repeated_enum_value,json=repeatedEnumValue,enum=grpc.gateway.examples.examplepb.NumericEnum" json:"repeated_enum_value,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) Reset() { *m = ABitOfEverything{} }
|
|
||||||
func (m *ABitOfEverything) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*ABitOfEverything) ProtoMessage() {}
|
|
||||||
func (*ABitOfEverything) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
|
||||||
|
|
||||||
type isABitOfEverything_OneofValue interface {
|
|
||||||
isABitOfEverything_OneofValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
type ABitOfEverything_OneofEmpty struct {
|
|
||||||
OneofEmpty *google_protobuf1.Empty `protobuf:"bytes,20,opt,name=oneof_empty,json=oneofEmpty,oneof"`
|
|
||||||
}
|
|
||||||
type ABitOfEverything_OneofString struct {
|
|
||||||
OneofString string `protobuf:"bytes,21,opt,name=oneof_string,json=oneofString,oneof"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*ABitOfEverything_OneofEmpty) isABitOfEverything_OneofValue() {}
|
|
||||||
func (*ABitOfEverything_OneofString) isABitOfEverything_OneofValue() {}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetOneofValue() isABitOfEverything_OneofValue {
|
|
||||||
if m != nil {
|
|
||||||
return m.OneofValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetSingleNested() *ABitOfEverything_Nested {
|
|
||||||
if m != nil {
|
|
||||||
return m.SingleNested
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetUuid() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Uuid
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetNested() []*ABitOfEverything_Nested {
|
|
||||||
if m != nil {
|
|
||||||
return m.Nested
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetFloatValue() float32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.FloatValue
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetDoubleValue() float64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.DoubleValue
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetInt64Value() int64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Int64Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetUint64Value() uint64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Uint64Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetInt32Value() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Int32Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetFixed64Value() uint64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Fixed64Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetFixed32Value() uint32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Fixed32Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetBoolValue() bool {
|
|
||||||
if m != nil {
|
|
||||||
return m.BoolValue
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetStringValue() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.StringValue
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetUint32Value() uint32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Uint32Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetEnumValue() NumericEnum {
|
|
||||||
if m != nil {
|
|
||||||
return m.EnumValue
|
|
||||||
}
|
|
||||||
return NumericEnum_ZERO
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetSfixed32Value() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sfixed32Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetSfixed64Value() int64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sfixed64Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetSint32Value() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sint32Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetSint64Value() int64 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sint64Value
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetRepeatedStringValue() []string {
|
|
||||||
if m != nil {
|
|
||||||
return m.RepeatedStringValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetOneofEmpty() *google_protobuf1.Empty {
|
|
||||||
if x, ok := m.GetOneofValue().(*ABitOfEverything_OneofEmpty); ok {
|
|
||||||
return x.OneofEmpty
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetOneofString() string {
|
|
||||||
if x, ok := m.GetOneofValue().(*ABitOfEverything_OneofString); ok {
|
|
||||||
return x.OneofString
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetMapValue() map[string]NumericEnum {
|
|
||||||
if m != nil {
|
|
||||||
return m.MapValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetMappedStringValue() map[string]string {
|
|
||||||
if m != nil {
|
|
||||||
return m.MappedStringValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetMappedNestedValue() map[string]*ABitOfEverything_Nested {
|
|
||||||
if m != nil {
|
|
||||||
return m.MappedNestedValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetNonConventionalNameValue() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.NonConventionalNameValue
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetTimestampValue() *google_protobuf3.Timestamp {
|
|
||||||
if m != nil {
|
|
||||||
return m.TimestampValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything) GetRepeatedEnumValue() []NumericEnum {
|
|
||||||
if m != nil {
|
|
||||||
return m.RepeatedEnumValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
|
||||||
func (*ABitOfEverything) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
|
||||||
return _ABitOfEverything_OneofMarshaler, _ABitOfEverything_OneofUnmarshaler, _ABitOfEverything_OneofSizer, []interface{}{
|
|
||||||
(*ABitOfEverything_OneofEmpty)(nil),
|
|
||||||
(*ABitOfEverything_OneofString)(nil),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverything_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
|
||||||
m := msg.(*ABitOfEverything)
|
|
||||||
// oneof_value
|
|
||||||
switch x := m.OneofValue.(type) {
|
|
||||||
case *ABitOfEverything_OneofEmpty:
|
|
||||||
b.EncodeVarint(20<<3 | proto.WireBytes)
|
|
||||||
if err := b.EncodeMessage(x.OneofEmpty); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case *ABitOfEverything_OneofString:
|
|
||||||
b.EncodeVarint(21<<3 | proto.WireBytes)
|
|
||||||
b.EncodeStringBytes(x.OneofString)
|
|
||||||
case nil:
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("ABitOfEverything.OneofValue has unexpected type %T", x)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverything_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
|
||||||
m := msg.(*ABitOfEverything)
|
|
||||||
switch tag {
|
|
||||||
case 20: // oneof_value.oneof_empty
|
|
||||||
if wire != proto.WireBytes {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
msg := new(google_protobuf1.Empty)
|
|
||||||
err := b.DecodeMessage(msg)
|
|
||||||
m.OneofValue = &ABitOfEverything_OneofEmpty{msg}
|
|
||||||
return true, err
|
|
||||||
case 21: // oneof_value.oneof_string
|
|
||||||
if wire != proto.WireBytes {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
x, err := b.DecodeStringBytes()
|
|
||||||
m.OneofValue = &ABitOfEverything_OneofString{x}
|
|
||||||
return true, err
|
|
||||||
default:
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverything_OneofSizer(msg proto.Message) (n int) {
|
|
||||||
m := msg.(*ABitOfEverything)
|
|
||||||
// oneof_value
|
|
||||||
switch x := m.OneofValue.(type) {
|
|
||||||
case *ABitOfEverything_OneofEmpty:
|
|
||||||
s := proto.Size(x.OneofEmpty)
|
|
||||||
n += proto.SizeVarint(20<<3 | proto.WireBytes)
|
|
||||||
n += proto.SizeVarint(uint64(s))
|
|
||||||
n += s
|
|
||||||
case *ABitOfEverything_OneofString:
|
|
||||||
n += proto.SizeVarint(21<<3 | proto.WireBytes)
|
|
||||||
n += proto.SizeVarint(uint64(len(x.OneofString)))
|
|
||||||
n += len(x.OneofString)
|
|
||||||
case nil:
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nested is nested type.
|
|
||||||
type ABitOfEverything_Nested struct {
|
|
||||||
// name is nested field.
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
|
||||||
Amount uint32 `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
|
|
||||||
Ok ABitOfEverything_Nested_DeepEnum `protobuf:"varint,3,opt,name=ok,enum=grpc.gateway.examples.examplepb.ABitOfEverything_Nested_DeepEnum" json:"ok,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything_Nested) Reset() { *m = ABitOfEverything_Nested{} }
|
|
||||||
func (m *ABitOfEverything_Nested) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*ABitOfEverything_Nested) ProtoMessage() {}
|
|
||||||
func (*ABitOfEverything_Nested) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0, 0} }
|
|
||||||
|
|
||||||
func (m *ABitOfEverything_Nested) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything_Nested) GetAmount() uint32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.Amount
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ABitOfEverything_Nested) GetOk() ABitOfEverything_Nested_DeepEnum {
|
|
||||||
if m != nil {
|
|
||||||
return m.Ok
|
|
||||||
}
|
|
||||||
return ABitOfEverything_Nested_FALSE
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*ABitOfEverything)(nil), "grpc.gateway.examples.examplepb.ABitOfEverything")
|
|
||||||
proto.RegisterType((*ABitOfEverything_Nested)(nil), "grpc.gateway.examples.examplepb.ABitOfEverything.Nested")
|
|
||||||
proto.RegisterEnum("grpc.gateway.examples.examplepb.NumericEnum", NumericEnum_name, NumericEnum_value)
|
|
||||||
proto.RegisterEnum("grpc.gateway.examples.examplepb.ABitOfEverything_Nested_DeepEnum", ABitOfEverything_Nested_DeepEnum_name, ABitOfEverything_Nested_DeepEnum_value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for ABitOfEverythingService service
|
|
||||||
|
|
||||||
type ABitOfEverythingServiceClient interface {
|
|
||||||
Create(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error)
|
|
||||||
CreateBody(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error)
|
|
||||||
Lookup(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*ABitOfEverything, error)
|
|
||||||
Update(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
Delete(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
GetQuery(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
Echo(ctx context.Context, in *grpc_gateway_examples_sub.StringMessage, opts ...grpc.CallOption) (*grpc_gateway_examples_sub.StringMessage, error)
|
|
||||||
DeepPathEcho(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error)
|
|
||||||
NoBindings(ctx context.Context, in *google_protobuf2.Duration, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
Timeout(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type aBitOfEverythingServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewABitOfEverythingServiceClient(cc *grpc.ClientConn) ABitOfEverythingServiceClient {
|
|
||||||
return &aBitOfEverythingServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Create(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) {
|
|
||||||
out := new(ABitOfEverything)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Create", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) CreateBody(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) {
|
|
||||||
out := new(ABitOfEverything)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/CreateBody", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Lookup(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*ABitOfEverything, error) {
|
|
||||||
out := new(ABitOfEverything)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Lookup", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Update(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Update", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Delete(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Delete", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) GetQuery(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/GetQuery", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Echo(ctx context.Context, in *grpc_gateway_examples_sub.StringMessage, opts ...grpc.CallOption) (*grpc_gateway_examples_sub.StringMessage, error) {
|
|
||||||
out := new(grpc_gateway_examples_sub.StringMessage)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Echo", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) DeepPathEcho(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) {
|
|
||||||
out := new(ABitOfEverything)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/DeepPathEcho", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) NoBindings(ctx context.Context, in *google_protobuf2.Duration, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/NoBindings", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aBitOfEverythingServiceClient) Timeout(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Timeout", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for ABitOfEverythingService service
|
|
||||||
|
|
||||||
type ABitOfEverythingServiceServer interface {
|
|
||||||
Create(context.Context, *ABitOfEverything) (*ABitOfEverything, error)
|
|
||||||
CreateBody(context.Context, *ABitOfEverything) (*ABitOfEverything, error)
|
|
||||||
Lookup(context.Context, *sub2.IdMessage) (*ABitOfEverything, error)
|
|
||||||
Update(context.Context, *ABitOfEverything) (*google_protobuf1.Empty, error)
|
|
||||||
Delete(context.Context, *sub2.IdMessage) (*google_protobuf1.Empty, error)
|
|
||||||
GetQuery(context.Context, *ABitOfEverything) (*google_protobuf1.Empty, error)
|
|
||||||
Echo(context.Context, *grpc_gateway_examples_sub.StringMessage) (*grpc_gateway_examples_sub.StringMessage, error)
|
|
||||||
DeepPathEcho(context.Context, *ABitOfEverything) (*ABitOfEverything, error)
|
|
||||||
NoBindings(context.Context, *google_protobuf2.Duration) (*google_protobuf1.Empty, error)
|
|
||||||
Timeout(context.Context, *google_protobuf1.Empty) (*google_protobuf1.Empty, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterABitOfEverythingServiceServer(s *grpc.Server, srv ABitOfEverythingServiceServer) {
|
|
||||||
s.RegisterService(&_ABitOfEverythingService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(ABitOfEverything)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Create(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Create",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Create(ctx, req.(*ABitOfEverything))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(ABitOfEverything)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/CreateBody",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, req.(*ABitOfEverything))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(sub2.IdMessage)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Lookup(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Lookup",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Lookup(ctx, req.(*sub2.IdMessage))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(ABitOfEverything)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Update(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Update",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Update(ctx, req.(*ABitOfEverything))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(sub2.IdMessage)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Delete(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Delete",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Delete(ctx, req.(*sub2.IdMessage))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_GetQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(ABitOfEverything)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).GetQuery(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/GetQuery",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).GetQuery(ctx, req.(*ABitOfEverything))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(grpc_gateway_examples_sub.StringMessage)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Echo(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Echo",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Echo(ctx, req.(*grpc_gateway_examples_sub.StringMessage))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_DeepPathEcho_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(ABitOfEverything)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).DeepPathEcho(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/DeepPathEcho",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).DeepPathEcho(ctx, req.(*ABitOfEverything))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_NoBindings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(google_protobuf2.Duration)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).NoBindings(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/NoBindings",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).NoBindings(ctx, req.(*google_protobuf2.Duration))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ABitOfEverythingService_Timeout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(google_protobuf1.Empty)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Timeout(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.ABitOfEverythingService/Timeout",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ABitOfEverythingServiceServer).Timeout(ctx, req.(*google_protobuf1.Empty))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "grpc.gateway.examples.examplepb.ABitOfEverythingService",
|
|
||||||
HandlerType: (*ABitOfEverythingServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Create",
|
|
||||||
Handler: _ABitOfEverythingService_Create_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "CreateBody",
|
|
||||||
Handler: _ABitOfEverythingService_CreateBody_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Lookup",
|
|
||||||
Handler: _ABitOfEverythingService_Lookup_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Update",
|
|
||||||
Handler: _ABitOfEverythingService_Update_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Delete",
|
|
||||||
Handler: _ABitOfEverythingService_Delete_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "GetQuery",
|
|
||||||
Handler: _ABitOfEverythingService_GetQuery_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Echo",
|
|
||||||
Handler: _ABitOfEverythingService_Echo_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "DeepPathEcho",
|
|
||||||
Handler: _ABitOfEverythingService_DeepPathEcho_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "NoBindings",
|
|
||||||
Handler: _ABitOfEverythingService_NoBindings_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Timeout",
|
|
||||||
Handler: _ABitOfEverythingService_Timeout_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "examples/examplepb/a_bit_of_everything.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Client API for AnotherServiceWithNoBindings service
|
|
||||||
|
|
||||||
type AnotherServiceWithNoBindingsClient interface {
|
|
||||||
NoBindings(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*google_protobuf1.Empty, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type anotherServiceWithNoBindingsClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAnotherServiceWithNoBindingsClient(cc *grpc.ClientConn) AnotherServiceWithNoBindingsClient {
|
|
||||||
return &anotherServiceWithNoBindingsClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *anotherServiceWithNoBindingsClient) NoBindings(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) {
|
|
||||||
out := new(google_protobuf1.Empty)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.AnotherServiceWithNoBindings/NoBindings", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for AnotherServiceWithNoBindings service
|
|
||||||
|
|
||||||
type AnotherServiceWithNoBindingsServer interface {
|
|
||||||
NoBindings(context.Context, *google_protobuf1.Empty) (*google_protobuf1.Empty, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterAnotherServiceWithNoBindingsServer(s *grpc.Server, srv AnotherServiceWithNoBindingsServer) {
|
|
||||||
s.RegisterService(&_AnotherServiceWithNoBindings_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _AnotherServiceWithNoBindings_NoBindings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(google_protobuf1.Empty)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(AnotherServiceWithNoBindingsServer).NoBindings(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.AnotherServiceWithNoBindings/NoBindings",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(AnotherServiceWithNoBindingsServer).NoBindings(ctx, req.(*google_protobuf1.Empty))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _AnotherServiceWithNoBindings_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "grpc.gateway.examples.examplepb.AnotherServiceWithNoBindings",
|
|
||||||
HandlerType: (*AnotherServiceWithNoBindingsServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "NoBindings",
|
|
||||||
Handler: _AnotherServiceWithNoBindings_NoBindings_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "examples/examplepb/a_bit_of_everything.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/examplepb/a_bit_of_everything.proto", fileDescriptor1) }
|
|
||||||
|
|
||||||
var fileDescriptor1 = []byte{
|
|
||||||
// 1297 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0x4f, 0x6f, 0x1b, 0x45,
|
|
||||||
0x14, 0xcf, 0xd8, 0x89, 0x13, 0x3f, 0xc7, 0x89, 0x33, 0x69, 0x53, 0xd7, 0x2d, 0x64, 0x71, 0x01,
|
|
||||||
0xad, 0x42, 0xb5, 0xab, 0xba, 0x15, 0x6a, 0x23, 0x41, 0x95, 0x34, 0x86, 0x22, 0xda, 0xb4, 0xdd,
|
|
||||||
0xfe, 0x41, 0x8a, 0x5a, 0xac, 0xb5, 0x3d, 0xb6, 0x57, 0xf1, 0xee, 0x2c, 0xbb, 0xb3, 0x26, 0x96,
|
|
||||||
0x31, 0x07, 0x0e, 0x5c, 0x38, 0x72, 0xef, 0x05, 0x09, 0x71, 0xe1, 0xc8, 0x19, 0xbe, 0x03, 0x5f,
|
|
||||||
0x81, 0x03, 0x1f, 0x03, 0xed, 0xcc, 0xec, 0x76, 0xd7, 0x89, 0xe5, 0x26, 0x45, 0xbd, 0xed, 0xcc,
|
|
||||||
0x7b, 0xef, 0xf7, 0x7b, 0x7f, 0xe6, 0xbd, 0x99, 0x85, 0xab, 0xe4, 0xc8, 0xb4, 0xdd, 0x3e, 0xf1,
|
|
||||||
0x75, 0xf9, 0xe1, 0x36, 0x75, 0xb3, 0xd1, 0xb4, 0x58, 0x83, 0x76, 0x1a, 0x64, 0x40, 0xbc, 0x21,
|
|
||||||
0xeb, 0x59, 0x4e, 0x57, 0x73, 0x3d, 0xca, 0x28, 0xde, 0xec, 0x7a, 0x6e, 0x4b, 0xeb, 0x9a, 0x8c,
|
|
||||||
0x7c, 0x6b, 0x0e, 0xb5, 0xc8, 0x54, 0x8b, 0x4d, 0x2b, 0x97, 0xbb, 0x94, 0x76, 0xfb, 0x44, 0x37,
|
|
||||||
0x5d, 0x4b, 0x37, 0x1d, 0x87, 0x32, 0x93, 0x59, 0xd4, 0xf1, 0x85, 0x79, 0xe5, 0x92, 0x94, 0xf2,
|
|
||||||
0x55, 0x33, 0xe8, 0xe8, 0xc4, 0x76, 0xd9, 0x50, 0x0a, 0xdf, 0x9d, 0x14, 0xb6, 0x03, 0x8f, 0x5b,
|
|
||||||
0x4b, 0x79, 0x25, 0xf6, 0xd4, 0x0f, 0x9a, 0xba, 0x4d, 0x7c, 0xdf, 0xec, 0x92, 0x08, 0x38, 0x29,
|
|
||||||
0xab, 0x4d, 0x08, 0x37, 0x27, 0x81, 0x99, 0x65, 0x13, 0x9f, 0x99, 0xb6, 0x2b, 0x14, 0xaa, 0x7f,
|
|
||||||
0xad, 0x42, 0x69, 0x67, 0xd7, 0x62, 0x0f, 0x3a, 0xf5, 0x38, 0x60, 0xfc, 0x02, 0x8a, 0xbe, 0xe5,
|
|
||||||
0x74, 0xfb, 0xa4, 0xe1, 0x10, 0x9f, 0x91, 0x76, 0xf9, 0xa2, 0x82, 0xd4, 0x42, 0xed, 0xa6, 0x36,
|
|
||||||
0x23, 0x05, 0xda, 0x24, 0x92, 0xb6, 0xcf, 0xed, 0x8d, 0x65, 0x01, 0x27, 0x56, 0x18, 0xc3, 0x7c,
|
|
||||||
0x10, 0x58, 0xed, 0x32, 0x52, 0x90, 0x9a, 0x37, 0xf8, 0x37, 0x7e, 0x08, 0x39, 0xc9, 0x95, 0x51,
|
|
||||||
0xb2, 0x6f, 0xc4, 0x25, 0x71, 0xf0, 0x26, 0x14, 0x3a, 0x7d, 0x6a, 0xb2, 0xc6, 0xc0, 0xec, 0x07,
|
|
||||||
0xa4, 0x9c, 0x55, 0x90, 0x9a, 0x31, 0x80, 0x6f, 0x3d, 0x0b, 0x77, 0xf0, 0x7b, 0xb0, 0xdc, 0xa6,
|
|
||||||
0x41, 0xb3, 0x4f, 0xa4, 0xc6, 0xbc, 0x82, 0x54, 0x64, 0x14, 0xc4, 0x9e, 0x50, 0xd9, 0x84, 0x82,
|
|
||||||
0xe5, 0xb0, 0x8f, 0x6f, 0x48, 0x8d, 0x05, 0x05, 0xa9, 0x59, 0x03, 0xf8, 0x56, 0x8c, 0x11, 0x24,
|
|
||||||
0x35, 0x72, 0x0a, 0x52, 0xe7, 0x8d, 0x42, 0x90, 0x50, 0x11, 0x18, 0xd7, 0x6b, 0x52, 0x63, 0x51,
|
|
||||||
0x41, 0xea, 0x02, 0xc7, 0xb8, 0x5e, 0x13, 0x0a, 0x57, 0xa0, 0xd8, 0xb1, 0x8e, 0x48, 0x3b, 0x06,
|
|
||||||
0x59, 0x52, 0x90, 0x9a, 0x33, 0x96, 0xe5, 0x66, 0x5a, 0x29, 0xc6, 0xc9, 0x2b, 0x48, 0x5d, 0x94,
|
|
||||||
0x4a, 0x11, 0xd2, 0x3b, 0x00, 0x4d, 0x4a, 0xfb, 0x52, 0x03, 0x14, 0xa4, 0x2e, 0x19, 0xf9, 0x70,
|
|
||||||
0x27, 0x76, 0xd6, 0x67, 0x9e, 0xe5, 0x74, 0xa5, 0x42, 0x81, 0xe7, 0xbf, 0x20, 0xf6, 0x52, 0xf1,
|
|
||||||
0xc4, 0x2c, 0x45, 0x05, 0xa9, 0x45, 0x11, 0x4f, 0x44, 0xf2, 0x25, 0x00, 0x71, 0x02, 0x5b, 0x2a,
|
|
||||||
0xac, 0x28, 0x48, 0x5d, 0xa9, 0x5d, 0x9d, 0x59, 0xad, 0xfd, 0xc0, 0x26, 0x9e, 0xd5, 0xaa, 0x3b,
|
|
||||||
0x81, 0x6d, 0xe4, 0x43, 0x7b, 0x01, 0xf6, 0x01, 0xac, 0xf8, 0xe9, 0xb8, 0x56, 0x15, 0xa4, 0xae,
|
|
||||||
0x1a, 0x45, 0x3f, 0x15, 0x58, 0xac, 0x16, 0xe7, 0xa8, 0xa4, 0x20, 0xb5, 0x14, 0xa9, 0x25, 0xaa,
|
|
||||||
0xe1, 0x27, 0xbd, 0x5f, 0x53, 0x90, 0xba, 0x66, 0x14, 0xfc, 0x84, 0xf7, 0x52, 0x25, 0xc6, 0xc1,
|
|
||||||
0x0a, 0x52, 0xb1, 0x50, 0x89, 0x50, 0x6a, 0x70, 0xde, 0x23, 0x2e, 0x31, 0x19, 0x69, 0x37, 0x52,
|
|
||||||
0xf9, 0x5a, 0x57, 0xb2, 0x6a, 0xde, 0x58, 0x8f, 0x84, 0x8f, 0x13, 0x79, 0xbb, 0x05, 0x05, 0xea,
|
|
||||||
0x90, 0x70, 0x6c, 0x84, 0x5d, 0x5d, 0x3e, 0xc7, 0xfb, 0x65, 0x43, 0x13, 0xdd, 0xa7, 0x45, 0xdd,
|
|
||||||
0xa7, 0xd5, 0x43, 0xe9, 0xdd, 0x39, 0x03, 0xb8, 0x32, 0x5f, 0xe1, 0x2b, 0xb0, 0x2c, 0x4c, 0x05,
|
|
||||||
0x57, 0xf9, 0x7c, 0x58, 0x95, 0xbb, 0x73, 0x86, 0x00, 0x14, 0x24, 0xf8, 0x39, 0xe4, 0x6d, 0xd3,
|
|
||||||
0x95, 0x7e, 0x6c, 0xf0, 0x0e, 0xb9, 0x7d, 0xfa, 0x0e, 0xb9, 0x6f, 0xba, 0xdc, 0xdd, 0xba, 0xc3,
|
|
||||||
0xbc, 0xa1, 0xb1, 0x64, 0xcb, 0x25, 0x3e, 0x82, 0x75, 0xdb, 0x74, 0xdd, 0xc9, 0x78, 0x2f, 0x70,
|
|
||||||
0x9e, 0xbb, 0x67, 0xe2, 0x71, 0x53, 0xf9, 0x11, 0x84, 0x6b, 0xf6, 0xe4, 0x7e, 0x82, 0x59, 0x74,
|
|
||||||
0xad, 0x64, 0x2e, 0xbf, 0x19, 0xb3, 0x98, 0x04, 0xc7, 0x99, 0x13, 0xfb, 0x78, 0x1b, 0xca, 0x0e,
|
|
||||||
0x75, 0xee, 0x50, 0x67, 0x40, 0x9c, 0x70, 0xd2, 0x9a, 0xfd, 0x7d, 0xd3, 0x16, 0x6d, 0x5f, 0xae,
|
|
||||||
0xf0, 0xc6, 0x98, 0x2a, 0xc7, 0x77, 0x60, 0x35, 0x9e, 0xa3, 0xd2, 0xe3, 0x4b, 0xbc, 0xe2, 0x95,
|
|
||||||
0x63, 0x15, 0x7f, 0x12, 0xe9, 0x19, 0x2b, 0xb1, 0x89, 0x00, 0x79, 0x0e, 0xf1, 0x49, 0x6a, 0x24,
|
|
||||||
0x1a, 0xea, 0xb2, 0x92, 0x3d, 0x75, 0x43, 0xad, 0x45, 0x40, 0xf5, 0xa8, 0xb1, 0x2a, 0xbf, 0x21,
|
|
||||||
0xc8, 0xbd, 0x1a, 0xb7, 0x8e, 0x69, 0x93, 0x68, 0xdc, 0x86, 0xdf, 0x78, 0x03, 0x72, 0xa6, 0x4d,
|
|
||||||
0x03, 0x87, 0x95, 0x33, 0xbc, 0xc3, 0xe5, 0x0a, 0x3f, 0x82, 0x0c, 0x3d, 0xe4, 0xb3, 0x72, 0xa5,
|
|
||||||
0xb6, 0x73, 0xd6, 0x11, 0xac, 0xed, 0x11, 0xe2, 0x72, 0xc7, 0x32, 0xf4, 0xb0, 0xba, 0x09, 0x4b,
|
|
||||||
0xd1, 0x1a, 0xe7, 0x61, 0xe1, 0xb3, 0x9d, 0x7b, 0x8f, 0xeb, 0xa5, 0x39, 0xbc, 0x04, 0xf3, 0x4f,
|
|
||||||
0x8c, 0xa7, 0xf5, 0x12, 0xaa, 0x58, 0x50, 0x4c, 0x1d, 0x4c, 0x5c, 0x82, 0xec, 0x21, 0x19, 0x4a,
|
|
||||||
0x7f, 0xc3, 0x4f, 0xbc, 0x0b, 0x0b, 0x22, 0x3b, 0x99, 0x33, 0x8c, 0x1b, 0x61, 0xba, 0x9d, 0xb9,
|
|
||||||
0x89, 0x2a, 0x7b, 0xb0, 0x71, 0xf2, 0xd9, 0x3c, 0x81, 0xf3, 0x5c, 0x92, 0x33, 0x9f, 0x44, 0xf9,
|
|
||||||
0x3e, 0x42, 0x99, 0x3c, 0x67, 0x27, 0xa0, 0xec, 0x27, 0x51, 0xde, 0xe4, 0x5a, 0x7b, 0xc5, 0xbf,
|
|
||||||
0x5b, 0x8c, 0x86, 0x0d, 0xdf, 0xda, 0x52, 0xa0, 0x90, 0x08, 0x37, 0x4c, 0xec, 0x41, 0xdd, 0x78,
|
|
||||||
0x50, 0x9a, 0xc3, 0x8b, 0x90, 0x7d, 0xb0, 0x5f, 0x2f, 0xa1, 0xda, 0xbf, 0xcb, 0x70, 0x61, 0x12,
|
|
||||||
0xf7, 0x31, 0xf1, 0x06, 0x56, 0x8b, 0xe0, 0x97, 0x59, 0xc8, 0xdd, 0xf1, 0xc2, 0xd3, 0x83, 0xaf,
|
|
||||||
0x9d, 0xda, 0xb9, 0xca, 0xe9, 0x4d, 0xaa, 0xbf, 0x67, 0x7e, 0xf8, 0xfb, 0x9f, 0x9f, 0x33, 0xbf,
|
|
||||||
0x66, 0xaa, 0xbf, 0x64, 0xf4, 0xc1, 0xb5, 0xe8, 0xed, 0x75, 0xd2, 0xcb, 0x4b, 0x1f, 0x25, 0x6e,
|
|
||||||
0xf0, 0xb1, 0x3e, 0x4a, 0x5e, 0xd7, 0x63, 0x7d, 0x94, 0x98, 0xe3, 0x63, 0xdd, 0x27, 0xae, 0xe9,
|
|
||||||
0x99, 0x8c, 0x7a, 0xfa, 0x28, 0x48, 0x09, 0x46, 0x89, 0x1b, 0x61, 0xac, 0x8f, 0x52, 0xd7, 0x48,
|
|
||||||
0xb4, 0x4e, 0xc8, 0x5f, 0x5d, 0xa0, 0x63, 0x7d, 0x94, 0x1c, 0x87, 0x9f, 0xf8, 0xcc, 0x73, 0x3d,
|
|
||||||
0xd2, 0xb1, 0x8e, 0xf4, 0xad, 0xb1, 0x20, 0x49, 0x98, 0xf9, 0x93, 0x38, 0xfe, 0x24, 0x91, 0x3f,
|
|
||||||
0x61, 0x90, 0x76, 0x72, 0xda, 0xac, 0x19, 0xe3, 0x97, 0x08, 0x40, 0x14, 0x68, 0x97, 0xb6, 0x87,
|
|
||||||
0x6f, 0xa9, 0x48, 0x5b, 0xbc, 0x46, 0xef, 0x57, 0x37, 0x67, 0x54, 0x68, 0x1b, 0x6d, 0xe1, 0xef,
|
|
||||||
0x20, 0x77, 0x8f, 0xd2, 0xc3, 0xc0, 0xc5, 0xab, 0x5a, 0xf8, 0x04, 0xd5, 0xbe, 0x68, 0xdf, 0x17,
|
|
||||||
0x8f, 0xd0, 0xb3, 0x30, 0x6b, 0x9c, 0x59, 0xc5, 0x1f, 0xce, 0x3c, 0x1b, 0xe1, 0xbb, 0x71, 0x8c,
|
|
||||||
0x7f, 0x44, 0x90, 0x7b, 0xea, 0xb6, 0xcf, 0x78, 0x7e, 0xa7, 0x5c, 0xd1, 0xd5, 0x6b, 0xdc, 0x8b,
|
|
||||||
0x8f, 0x2a, 0xaf, 0xe9, 0x45, 0x98, 0x06, 0x13, 0x72, 0x7b, 0xa4, 0x4f, 0x18, 0x39, 0x9e, 0x86,
|
|
||||||
0x69, 0x2c, 0x32, 0xd6, 0xad, 0xd7, 0x8d, 0xf5, 0x27, 0x04, 0x4b, 0x9f, 0x13, 0xf6, 0x28, 0x20,
|
|
||||||
0xde, 0xf0, 0xff, 0x8c, 0xf6, 0x06, 0xf7, 0x43, 0xc3, 0x57, 0x67, 0xf9, 0xf1, 0x4d, 0xc8, 0x1c,
|
|
||||||
0x79, 0xf3, 0x27, 0x82, 0xf9, 0x7a, 0xab, 0x47, 0xb1, 0x3a, 0xc5, 0x13, 0x3f, 0x68, 0x6a, 0x62,
|
|
||||||
0xd0, 0x46, 0x89, 0x78, 0x6d, 0xcd, 0x6a, 0x8b, 0xbb, 0xf4, 0x62, 0xb6, 0x4b, 0xa4, 0xd5, 0xa3,
|
|
||||||
0xfa, 0x48, 0xb4, 0xd1, 0xc1, 0xc5, 0x6a, 0x49, 0x1f, 0xd4, 0x62, 0xfd, 0x50, 0xb6, 0x2d, 0x06,
|
|
||||||
0xe7, 0x01, 0xc6, 0xc7, 0x44, 0xf8, 0x0f, 0x04, 0xcb, 0xe1, 0xdd, 0xf4, 0xd0, 0x64, 0x3d, 0x1e,
|
|
||||||
0xc9, 0xdb, 0x69, 0xae, 0xdb, 0x3c, 0xb6, 0x5b, 0xd5, 0x1b, 0x33, 0xcb, 0x9e, 0xfa, 0x0b, 0xd3,
|
|
||||||
0xc2, 0x9b, 0x9b, 0x1f, 0xb5, 0x1d, 0x80, 0x7d, 0xba, 0x6b, 0x39, 0x6d, 0xcb, 0xe9, 0xfa, 0xf8,
|
|
||||||
0xe2, 0xb1, 0xaa, 0xee, 0xc9, 0xbf, 0xc7, 0xa9, 0x05, 0x9f, 0xc3, 0xcf, 0x60, 0x31, 0x7c, 0x9a,
|
|
||||||
0xd0, 0x80, 0xe1, 0x29, 0x4a, 0x53, 0x8d, 0x2f, 0x71, 0xf7, 0xcf, 0xe3, 0xf5, 0x64, 0x3e, 0x99,
|
|
||||||
0x00, 0xab, 0x7d, 0x0d, 0x97, 0x77, 0x1c, 0xca, 0x7a, 0xc4, 0x93, 0x17, 0xcc, 0x57, 0x16, 0xeb,
|
|
||||||
0x25, 0x9c, 0xfd, 0x34, 0xe5, 0xfa, 0x69, 0xa9, 0xe7, 0x76, 0x0b, 0x07, 0xf9, 0x38, 0xb3, 0xcd,
|
|
||||||
0x1c, 0x17, 0x5f, 0xff, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xab, 0xe5, 0x92, 0x0d, 0xc9, 0x0f, 0x00,
|
|
||||||
0x00,
|
|
||||||
}
|
|
@ -1,839 +0,0 @@
|
|||||||
// Code generated by protoc-gen-grpc-gateway
|
|
||||||
// source: examples/examplepb/a_bit_of_everything.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package examplepb is a reverse proxy.
|
|
||||||
|
|
||||||
It translates gRPC into RESTful JSON APIs.
|
|
||||||
*/
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/sub2"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ codes.Code
|
|
||||||
var _ io.Reader
|
|
||||||
var _ = runtime.String
|
|
||||||
var _ = utilities.NewDoubleArray
|
|
||||||
|
|
||||||
var (
|
|
||||||
filter_ABitOfEverythingService_Create_0 = &utilities.DoubleArray{Encoding: map[string]int{"float_value": 0, "double_value": 1, "int64_value": 2, "uint64_value": 3, "int32_value": 4, "fixed64_value": 5, "fixed32_value": 6, "bool_value": 7, "string_value": 8, "uint32_value": 9, "sfixed32_value": 10, "sfixed64_value": 11, "sint32_value": 12, "sint64_value": 13, "nonConventionalNameValue": 14}, Base: []int{1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Check: []int{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}}
|
|
||||||
)
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Create_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["float_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "float_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.FloatValue, err = runtime.Float32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["double_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "double_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.DoubleValue, err = runtime.Float64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["int64_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "int64_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Int64Value, err = runtime.Int64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["uint64_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uint64_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uint64Value, err = runtime.Uint64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["int32_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "int32_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Int32Value, err = runtime.Int32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["fixed64_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "fixed64_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Fixed64Value, err = runtime.Uint64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["fixed32_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "fixed32_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Fixed32Value, err = runtime.Uint32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["bool_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "bool_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.BoolValue, err = runtime.Bool(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["string_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "string_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.StringValue, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["uint32_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uint32_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uint32Value, err = runtime.Uint32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["sfixed32_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sfixed32_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Sfixed32Value, err = runtime.Int32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["sfixed64_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sfixed64_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Sfixed64Value, err = runtime.Int64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["sint32_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sint32_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Sint32Value, err = runtime.Int32(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["sint64_value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sint64_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Sint64Value, err = runtime.Int64(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok = pathParams["nonConventionalNameValue"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "nonConventionalNameValue")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.NonConventionalNameValue, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ABitOfEverythingService_Create_0); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_CreateBody_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.CreateBody(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Lookup_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq sub2.IdMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uuid, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Lookup(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Update_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uuid, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq sub2.IdMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uuid, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Delete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
filter_ABitOfEverythingService_GetQuery_0 = &utilities.DoubleArray{Encoding: map[string]int{"uuid": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
|
||||||
)
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_GetQuery_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["uuid"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Uuid, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ABitOfEverythingService_GetQuery_0); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.GetQuery(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq sub.StringMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["value"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "value")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Value, err = runtime.StringP(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Echo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Echo_1(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq sub.StringMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Value); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Echo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
filter_ABitOfEverythingService_Echo_2 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
|
||||||
)
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Echo_2(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq sub.StringMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ABitOfEverythingService_Echo_2); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Echo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_DeepPathEcho_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["single_nested.name"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "single_nested.name")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = runtime.PopulateFieldFromPath(&protoReq, "single_nested.name", val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.DeepPathEcho(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_ABitOfEverythingService_Timeout_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq empty.Empty
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
msg, err := client.Timeout(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterABitOfEverythingServiceHandlerFromEndpoint is same as RegisterABitOfEverythingServiceHandler but
|
|
||||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
|
||||||
func RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
|
||||||
conn, err := grpc.Dial(endpoint, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return RegisterABitOfEverythingServiceHandler(ctx, mux, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterABitOfEverythingServiceHandler registers the http handlers for service ABitOfEverythingService to "mux".
|
|
||||||
// The handlers forward requests to the grpc endpoint over "conn".
|
|
||||||
func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
|
||||||
client := NewABitOfEverythingServiceClient(conn)
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_ABitOfEverythingService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Create_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Create_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_ABitOfEverythingService_CreateBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_CreateBody_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_CreateBody_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_ABitOfEverythingService_Lookup_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Lookup_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Lookup_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("PUT", pattern_ABitOfEverythingService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Update_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Update_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("DELETE", pattern_ABitOfEverythingService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Delete_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Delete_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_ABitOfEverythingService_GetQuery_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_GetQuery_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_GetQuery_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_ABitOfEverythingService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Echo_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_ABitOfEverythingService_Echo_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Echo_1(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_1(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_ABitOfEverythingService_Echo_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Echo_2(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_2(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_ABitOfEverythingService_DeepPathEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_DeepPathEcho_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_DeepPathEcho_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_ABitOfEverythingService_Timeout_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_ABitOfEverythingService_Timeout_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Timeout_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
pattern_ABitOfEverythingService_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7, 1, 0, 4, 1, 5, 8, 1, 0, 4, 1, 5, 9, 1, 0, 4, 1, 5, 10, 1, 0, 4, 1, 5, 11, 2, 12, 1, 0, 4, 2, 5, 13, 1, 0, 4, 1, 5, 14, 1, 0, 4, 1, 5, 15, 1, 0, 4, 1, 5, 16, 1, 0, 4, 1, 5, 17, 1, 0, 4, 1, 5, 18, 1, 0, 4, 1, 5, 19}, []string{"v1", "example", "a_bit_of_everything", "float_value", "double_value", "int64_value", "separator", "uint64_value", "int32_value", "fixed64_value", "fixed32_value", "bool_value", "strprefix", "string_value", "uint32_value", "sfixed32_value", "sfixed64_value", "sint32_value", "sint64_value", "nonConventionalNameValue"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_CreateBody_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "example", "a_bit_of_everything"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Lookup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "a_bit_of_everything", "uuid"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Update_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "a_bit_of_everything", "uuid"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "a_bit_of_everything", "uuid"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_GetQuery_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "example", "a_bit_of_everything", "query", "uuid"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "example", "a_bit_of_everything", "echo", "value"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Echo_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "example", "echo"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Echo_2 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "example", "echo"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_DeepPathEcho_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "a_bit_of_everything", "single_nested.name"}, ""))
|
|
||||||
|
|
||||||
pattern_ABitOfEverythingService_Timeout_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "example", "timeout"}, ""))
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
forward_ABitOfEverythingService_Create_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_CreateBody_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Lookup_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Update_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Delete_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_GetQuery_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_1 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Echo_2 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_DeepPathEcho_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_ABitOfEverythingService_Timeout_0 = runtime.ForwardResponseMessage
|
|
||||||
)
|
|
137
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto
generated
vendored
137
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto
generated
vendored
@ -1,137 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option go_package = "examplepb";
|
|
||||||
package grpc.gateway.examples.examplepb;
|
|
||||||
|
|
||||||
import "google/api/annotations.proto";
|
|
||||||
import "google/protobuf/empty.proto";
|
|
||||||
import "google/protobuf/duration.proto";
|
|
||||||
import "examples/sub/message.proto";
|
|
||||||
import "examples/sub2/message.proto";
|
|
||||||
import "google/protobuf/timestamp.proto";
|
|
||||||
|
|
||||||
// Intentionaly complicated message type to cover much features of Protobuf.
|
|
||||||
// NEXT ID: 27
|
|
||||||
message ABitOfEverything {
|
|
||||||
// Nested is nested type.
|
|
||||||
message Nested {
|
|
||||||
// name is nested field.
|
|
||||||
string name = 1;
|
|
||||||
uint32 amount = 2;
|
|
||||||
// DeepEnum is one or zero.
|
|
||||||
enum DeepEnum {
|
|
||||||
// FALSE is false.
|
|
||||||
FALSE = 0;
|
|
||||||
// TRUE is true.
|
|
||||||
TRUE = 1;
|
|
||||||
}
|
|
||||||
DeepEnum ok = 3;
|
|
||||||
}
|
|
||||||
Nested single_nested = 25;
|
|
||||||
|
|
||||||
string uuid = 1;
|
|
||||||
repeated Nested nested = 2;
|
|
||||||
float float_value = 3;
|
|
||||||
double double_value = 4;
|
|
||||||
int64 int64_value = 5;
|
|
||||||
uint64 uint64_value = 6;
|
|
||||||
int32 int32_value = 7;
|
|
||||||
fixed64 fixed64_value = 8;
|
|
||||||
fixed32 fixed32_value = 9;
|
|
||||||
bool bool_value = 10;
|
|
||||||
string string_value = 11;
|
|
||||||
// TODO(yugui) add bytes_value
|
|
||||||
uint32 uint32_value = 13;
|
|
||||||
NumericEnum enum_value = 14;
|
|
||||||
sfixed32 sfixed32_value = 15;
|
|
||||||
sfixed64 sfixed64_value = 16;
|
|
||||||
sint32 sint32_value = 17;
|
|
||||||
sint64 sint64_value = 18;
|
|
||||||
repeated string repeated_string_value = 19;
|
|
||||||
oneof oneof_value {
|
|
||||||
google.protobuf.Empty oneof_empty = 20;
|
|
||||||
string oneof_string = 21;
|
|
||||||
}
|
|
||||||
|
|
||||||
map<string, NumericEnum> map_value = 22;
|
|
||||||
map<string, string> mapped_string_value = 23;
|
|
||||||
map<string, Nested> mapped_nested_value = 24;
|
|
||||||
|
|
||||||
string nonConventionalNameValue = 26;
|
|
||||||
|
|
||||||
google.protobuf.Timestamp timestamp_value = 27;
|
|
||||||
|
|
||||||
// repeated enum value. it is comma-separated in query
|
|
||||||
repeated NumericEnum repeated_enum_value = 28;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NumericEnum is one or zero.
|
|
||||||
enum NumericEnum {
|
|
||||||
// ZERO means 0
|
|
||||||
ZERO = 0;
|
|
||||||
// ONE means 1
|
|
||||||
ONE = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
service ABitOfEverythingService {
|
|
||||||
rpc Create(ABitOfEverything) returns (ABitOfEverything) {
|
|
||||||
// TODO add enum_value
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value=strprefix/*}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc CreateBody(ABitOfEverything) returns (ABitOfEverything) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/a_bit_of_everything"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc Lookup(sub2.IdMessage) returns (ABitOfEverything) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
get: "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc Update(ABitOfEverything) returns (google.protobuf.Empty) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
put: "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc Delete(sub2.IdMessage) returns (google.protobuf.Empty) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
delete: "/v1/example/a_bit_of_everything/{uuid}"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc GetQuery(ABitOfEverything) returns (google.protobuf.Empty) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
get: "/v1/example/a_bit_of_everything/query/{uuid}"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc Echo(grpc.gateway.examples.sub.StringMessage) returns (grpc.gateway.examples.sub.StringMessage) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
get: "/v1/example/a_bit_of_everything/echo/{value}"
|
|
||||||
additional_bindings {
|
|
||||||
post: "/v2/example/echo"
|
|
||||||
body: "value"
|
|
||||||
}
|
|
||||||
additional_bindings {
|
|
||||||
get: "/v2/example/echo"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/a_bit_of_everything/{single_nested.name}"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc NoBindings(google.protobuf.Duration) returns (google.protobuf.Empty) {}
|
|
||||||
rpc Timeout(google.protobuf.Empty) returns (google.protobuf.Empty) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
get: "/v2/example/timeout",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
service AnotherServiceWithNoBindings {
|
|
||||||
rpc NoBindings(google.protobuf.Empty) returns (google.protobuf.Empty) {}
|
|
||||||
}
|
|
@ -1,759 +0,0 @@
|
|||||||
{
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"title": "examples/examplepb/a_bit_of_everything.proto",
|
|
||||||
"version": "version not set"
|
|
||||||
},
|
|
||||||
"schemes": [
|
|
||||||
"http",
|
|
||||||
"https"
|
|
||||||
],
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
"/v1/example/a_bit_of_everything": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "CreateBody",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "body",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/a_bit_of_everything/echo/{value}": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "Echo",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/subStringMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/a_bit_of_everything/query/{uuid}": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "GetQuery",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/protobufEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "uuid",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "single_nested.name",
|
|
||||||
"description": "name is nested field.",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "single_nested.amount",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "single_nested.ok",
|
|
||||||
"description": " - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"FALSE",
|
|
||||||
"TRUE"
|
|
||||||
],
|
|
||||||
"default": "FALSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "float_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "number",
|
|
||||||
"format": "float"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "double_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "int64_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "uint64_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "int32_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fixed64_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fixed32_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bool_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "boolean",
|
|
||||||
"format": "boolean"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "string_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "uint32_value",
|
|
||||||
"description": "TODO(yugui) add bytes_value.",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "enum_value",
|
|
||||||
"description": " - ZERO: ZERO means 0\n - ONE: ONE means 1",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"ZERO",
|
|
||||||
"ONE"
|
|
||||||
],
|
|
||||||
"default": "ZERO"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sfixed32_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sfixed64_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sint32_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sint64_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "repeated_string_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "oneof_string",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "nonConventionalNameValue",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "timestamp_value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "repeated_enum_value",
|
|
||||||
"description": "repeated enum value. it is comma-separated in query.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"ZERO",
|
|
||||||
"ONE"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "Create",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "float_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "number",
|
|
||||||
"format": "float"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "double_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "int64_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "uint64_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "int32_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fixed64_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fixed32_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bool_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "boolean",
|
|
||||||
"format": "boolean"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "string_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "uint32_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sfixed32_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sfixed64_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sint32_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sint64_value",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "nonConventionalNameValue",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/a_bit_of_everything/{single_nested.name}": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "DeepPathEcho",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "single_nested.name",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "body",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/a_bit_of_everything/{uuid}": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "Lookup",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "uuid",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"delete": {
|
|
||||||
"operationId": "Delete",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/protobufEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "uuid",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"put": {
|
|
||||||
"operationId": "Update",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/protobufEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "uuid",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "body",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbABitOfEverything"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v2/example/echo": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "Echo",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/subStringMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"post": {
|
|
||||||
"operationId": "Echo",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/subStringMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "body",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v2/example/timeout": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "Timeout",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/protobufEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"ABitOfEverythingService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"definitions": {
|
|
||||||
"ABitOfEverythingNested": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"name": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "name is nested field."
|
|
||||||
},
|
|
||||||
"amount": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
"ok": {
|
|
||||||
"$ref": "#/definitions/NestedDeepEnum"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "Nested is nested type."
|
|
||||||
},
|
|
||||||
"NestedDeepEnum": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"FALSE",
|
|
||||||
"TRUE"
|
|
||||||
],
|
|
||||||
"default": "FALSE",
|
|
||||||
"description": "DeepEnum is one or zero.\n\n - FALSE: FALSE is false.\n - TRUE: TRUE is true."
|
|
||||||
},
|
|
||||||
"examplepbABitOfEverything": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"single_nested": {
|
|
||||||
"$ref": "#/definitions/ABitOfEverythingNested"
|
|
||||||
},
|
|
||||||
"uuid": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"nested": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/ABitOfEverythingNested"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"float_value": {
|
|
||||||
"type": "number",
|
|
||||||
"format": "float"
|
|
||||||
},
|
|
||||||
"double_value": {
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
"int64_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
"uint64_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
"int32_value": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
"fixed64_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "uint64"
|
|
||||||
},
|
|
||||||
"fixed32_value": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
"bool_value": {
|
|
||||||
"type": "boolean",
|
|
||||||
"format": "boolean"
|
|
||||||
},
|
|
||||||
"string_value": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"uint32_value": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64",
|
|
||||||
"title": "TODO(yugui) add bytes_value"
|
|
||||||
},
|
|
||||||
"enum_value": {
|
|
||||||
"$ref": "#/definitions/examplepbNumericEnum"
|
|
||||||
},
|
|
||||||
"sfixed32_value": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
"sfixed64_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
"sint32_value": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32"
|
|
||||||
},
|
|
||||||
"sint64_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64"
|
|
||||||
},
|
|
||||||
"repeated_string_value": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"oneof_empty": {
|
|
||||||
"$ref": "#/definitions/protobufEmpty"
|
|
||||||
},
|
|
||||||
"oneof_string": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"map_value": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"$ref": "#/definitions/examplepbNumericEnum"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mapped_string_value": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mapped_nested_value": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"$ref": "#/definitions/ABitOfEverythingNested"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nonConventionalNameValue": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"timestamp_value": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time"
|
|
||||||
},
|
|
||||||
"repeated_enum_value": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/examplepbNumericEnum"
|
|
||||||
},
|
|
||||||
"title": "repeated enum value. it is comma-separated in query"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"title": "Intentionaly complicated message type to cover much features of Protobuf.\nNEXT ID: 27"
|
|
||||||
},
|
|
||||||
"examplepbNumericEnum": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"ZERO",
|
|
||||||
"ONE"
|
|
||||||
],
|
|
||||||
"default": "ZERO",
|
|
||||||
"description": "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1"
|
|
||||||
},
|
|
||||||
"protobufDuration": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"seconds": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "int64",
|
|
||||||
"description": "Signed seconds of the span of time. Must be from -315,576,000,000\nto +315,576,000,000 inclusive."
|
|
||||||
},
|
|
||||||
"nanos": {
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int32",
|
|
||||||
"description": "Signed fractions of a second at nanosecond resolution of the span\nof time. Durations less than one second are represented with a 0\n`seconds` field and a positive or negative `nanos` field. For durations\nof one second or more, a non-zero value for the `nanos` field must be\nof the same sign as the `seconds` field. Must be from -999,999,999\nto +999,999,999 inclusive."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "A Duration represents a signed, fixed-length span of time represented\nas a count of seconds and fractions of seconds at nanosecond\nresolution. It is independent of any calendar and concepts like \"day\"\nor \"month\". It is related to Timestamp in that the difference between\ntwo Timestamp values is a Duration and it can be added or subtracted\nfrom a Timestamp. Range is approximately +-10,000 years.\n\nExample 1: Compute Duration from two Timestamps in pseudo code.\n\n Timestamp start = ...;\n Timestamp end = ...;\n Duration duration = ...;\n\n duration.seconds = end.seconds - start.seconds;\n duration.nanos = end.nanos - start.nanos;\n\n if (duration.seconds \u003c 0 \u0026\u0026 duration.nanos \u003e 0) {\n duration.seconds += 1;\n duration.nanos -= 1000000000;\n } else if (durations.seconds \u003e 0 \u0026\u0026 duration.nanos \u003c 0) {\n duration.seconds -= 1;\n duration.nanos += 1000000000;\n }\n\nExample 2: Compute Timestamp from Timestamp + Duration in pseudo code.\n\n Timestamp start = ...;\n Duration duration = ...;\n Timestamp end = ...;\n\n end.seconds = start.seconds + duration.seconds;\n end.nanos = start.nanos + duration.nanos;\n\n if (end.nanos \u003c 0) {\n end.seconds -= 1;\n end.nanos += 1000000000;\n } else if (end.nanos \u003e= 1000000000) {\n end.seconds += 1;\n end.nanos -= 1000000000;\n }\n\nExample 3: Compute Duration from datetime.timedelta in Python.\n\n td = datetime.timedelta(days=3, minutes=10)\n duration = Duration()\n duration.FromTimedelta(td)"
|
|
||||||
},
|
|
||||||
"protobufEmpty": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
|
|
||||||
"title": "A generic empty message that you can re-use to avoid defining duplicated\nempty messages in your APIs. A typical example is to use it as the request\nor the response type of an API method. For instance:"
|
|
||||||
},
|
|
||||||
"sub2IdMessage": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"uuid": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"subStringMessage": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"value": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
207
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.go
generated
vendored
207
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.go
generated
vendored
@ -1,207 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/examplepb/echo_service.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package examplepb is a generated protocol buffer package.
|
|
||||||
|
|
||||||
Echo Service
|
|
||||||
|
|
||||||
Echo Service API consists of a single service which returns
|
|
||||||
a message.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
examples/examplepb/echo_service.proto
|
|
||||||
examples/examplepb/a_bit_of_everything.proto
|
|
||||||
examples/examplepb/stream.proto
|
|
||||||
examples/examplepb/flow_combination.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
SimpleMessage
|
|
||||||
ABitOfEverything
|
|
||||||
EmptyProto
|
|
||||||
NonEmptyProto
|
|
||||||
UnaryProto
|
|
||||||
NestedProto
|
|
||||||
SingleNestedProto
|
|
||||||
*/
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
// SimpleMessage represents a simple message sent to the Echo service.
|
|
||||||
type SimpleMessage struct {
|
|
||||||
// Id represents the message identifier.
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SimpleMessage) Reset() { *m = SimpleMessage{} }
|
|
||||||
func (m *SimpleMessage) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*SimpleMessage) ProtoMessage() {}
|
|
||||||
func (*SimpleMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *SimpleMessage) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*SimpleMessage)(nil), "grpc.gateway.examples.examplepb.SimpleMessage")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for EchoService service
|
|
||||||
|
|
||||||
type EchoServiceClient interface {
|
|
||||||
// Echo method receives a simple message and returns it.
|
|
||||||
//
|
|
||||||
// The message posted as the id parameter will also be
|
|
||||||
// returned.
|
|
||||||
Echo(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error)
|
|
||||||
// EchoBody method receives a simple message and returns it.
|
|
||||||
EchoBody(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type echoServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEchoServiceClient(cc *grpc.ClientConn) EchoServiceClient {
|
|
||||||
return &echoServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *echoServiceClient) Echo(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error) {
|
|
||||||
out := new(SimpleMessage)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.EchoService/Echo", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *echoServiceClient) EchoBody(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error) {
|
|
||||||
out := new(SimpleMessage)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.EchoService/EchoBody", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for EchoService service
|
|
||||||
|
|
||||||
type EchoServiceServer interface {
|
|
||||||
// Echo method receives a simple message and returns it.
|
|
||||||
//
|
|
||||||
// The message posted as the id parameter will also be
|
|
||||||
// returned.
|
|
||||||
Echo(context.Context, *SimpleMessage) (*SimpleMessage, error)
|
|
||||||
// EchoBody method receives a simple message and returns it.
|
|
||||||
EchoBody(context.Context, *SimpleMessage) (*SimpleMessage, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterEchoServiceServer(s *grpc.Server, srv EchoServiceServer) {
|
|
||||||
s.RegisterService(&_EchoService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(SimpleMessage)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(EchoServiceServer).Echo(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.EchoService/Echo",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(EchoServiceServer).Echo(ctx, req.(*SimpleMessage))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(SimpleMessage)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(EchoServiceServer).EchoBody(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.EchoService/EchoBody",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(EchoServiceServer).EchoBody(ctx, req.(*SimpleMessage))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _EchoService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "grpc.gateway.examples.examplepb.EchoService",
|
|
||||||
HandlerType: (*EchoServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Echo",
|
|
||||||
Handler: _EchoService_Echo_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "EchoBody",
|
|
||||||
Handler: _EchoService_EchoBody_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "examples/examplepb/echo_service.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/examplepb/echo_service.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 229 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0xad, 0x48, 0xcc,
|
|
||||||
0x2d, 0xc8, 0x49, 0x2d, 0xd6, 0x87, 0x32, 0x0a, 0x92, 0xf4, 0x53, 0x93, 0x33, 0xf2, 0xe3, 0x8b,
|
|
||||||
0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xe4, 0xd3, 0x8b,
|
|
||||||
0x0a, 0x92, 0xf5, 0xd2, 0x13, 0x4b, 0x52, 0xcb, 0x13, 0x2b, 0xf5, 0x60, 0x7a, 0xf4, 0xe0, 0x7a,
|
|
||||||
0xa4, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, 0xf3, 0xf2,
|
|
||||||
0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xda, 0x95, 0xe4, 0xb9, 0x78, 0x83, 0x33,
|
|
||||||
0x41, 0x2a, 0x7d, 0x53, 0x8b, 0x8b, 0x13, 0xd3, 0x53, 0x85, 0xf8, 0xb8, 0x98, 0x32, 0x53, 0x24,
|
|
||||||
0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x98, 0x32, 0x53, 0x8c, 0x96, 0x30, 0x71, 0x71, 0xbb, 0x26,
|
|
||||||
0x67, 0xe4, 0x07, 0x43, 0x6c, 0x15, 0x6a, 0x65, 0xe4, 0x62, 0x01, 0xf1, 0x85, 0xf4, 0xf4, 0x08,
|
|
||||||
0xd8, 0xac, 0x87, 0x62, 0xb0, 0x14, 0x89, 0xea, 0x95, 0x64, 0x9b, 0x2e, 0x3f, 0x99, 0xcc, 0x24,
|
|
||||||
0xae, 0x24, 0xaa, 0x5f, 0x66, 0x08, 0x0b, 0x02, 0x70, 0x00, 0xe8, 0x57, 0x67, 0xa6, 0xd4, 0x0a,
|
|
||||||
0xf5, 0x30, 0x72, 0x71, 0x80, 0xdc, 0xe1, 0x94, 0x9f, 0x52, 0x49, 0x73, 0xb7, 0x28, 0x80, 0xdd,
|
|
||||||
0x22, 0x85, 0xe9, 0x96, 0xf8, 0xa4, 0xfc, 0x94, 0x4a, 0x2b, 0x46, 0x2d, 0x27, 0xee, 0x28, 0x4e,
|
|
||||||
0xb8, 0xe6, 0x24, 0x36, 0x70, 0xd8, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x26, 0x96, 0x37,
|
|
||||||
0xac, 0xc3, 0x01, 0x00, 0x00,
|
|
||||||
}
|
|
169
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go
generated
vendored
169
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go
generated
vendored
@ -1,169 +0,0 @@
|
|||||||
// Code generated by protoc-gen-grpc-gateway
|
|
||||||
// source: examples/examplepb/echo_service.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package examplepb is a reverse proxy.
|
|
||||||
|
|
||||||
It translates gRPC into RESTful JSON APIs.
|
|
||||||
*/
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ codes.Code
|
|
||||||
var _ io.Reader
|
|
||||||
var _ = runtime.String
|
|
||||||
var _ = utilities.NewDoubleArray
|
|
||||||
|
|
||||||
func request_EchoService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq SimpleMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
|
|
||||||
val, ok = pathParams["id"]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
|
||||||
}
|
|
||||||
|
|
||||||
protoReq.Id, err = runtime.String(val)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.Echo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_EchoService_EchoBody_0(ctx context.Context, marshaler runtime.Marshaler, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq SimpleMessage
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := client.EchoBody(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterEchoServiceHandlerFromEndpoint is same as RegisterEchoServiceHandler but
|
|
||||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
|
||||||
func RegisterEchoServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
|
||||||
conn, err := grpc.Dial(endpoint, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return RegisterEchoServiceHandler(ctx, mux, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterEchoServiceHandler registers the http handlers for service EchoService to "mux".
|
|
||||||
// The handlers forward requests to the grpc endpoint over "conn".
|
|
||||||
func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
|
||||||
client := NewEchoServiceClient(conn)
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_EchoService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_EchoService_Echo_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_EchoService_Echo_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_EchoService_EchoBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_EchoService_EchoBody_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_EchoService_EchoBody_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
pattern_EchoService_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "echo", "id"}, ""))
|
|
||||||
|
|
||||||
pattern_EchoService_EchoBody_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "example", "echo_body"}, ""))
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
forward_EchoService_Echo_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_EchoService_EchoBody_0 = runtime.ForwardResponseMessage
|
|
||||||
)
|
|
36
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.proto
generated
vendored
36
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.proto
generated
vendored
@ -1,36 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option go_package = "examplepb";
|
|
||||||
|
|
||||||
// Echo Service
|
|
||||||
//
|
|
||||||
// Echo Service API consists of a single service which returns
|
|
||||||
// a message.
|
|
||||||
package grpc.gateway.examples.examplepb;
|
|
||||||
|
|
||||||
import "google/api/annotations.proto";
|
|
||||||
|
|
||||||
// SimpleMessage represents a simple message sent to the Echo service.
|
|
||||||
message SimpleMessage {
|
|
||||||
// Id represents the message identifier.
|
|
||||||
string id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Echo service responds to incoming echo requests.
|
|
||||||
service EchoService {
|
|
||||||
// Echo method receives a simple message and returns it.
|
|
||||||
//
|
|
||||||
// The message posted as the id parameter will also be
|
|
||||||
// returned.
|
|
||||||
rpc Echo(SimpleMessage) returns (SimpleMessage) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/echo/{id}"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// EchoBody method receives a simple message and returns it.
|
|
||||||
rpc EchoBody(SimpleMessage) returns (SimpleMessage) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/echo_body"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
{
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"title": "Echo Service",
|
|
||||||
"description": "Echo Service API consists of a single service which returns\na message.",
|
|
||||||
"version": "version not set"
|
|
||||||
},
|
|
||||||
"schemes": [
|
|
||||||
"http",
|
|
||||||
"https"
|
|
||||||
],
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
"/v1/example/echo/{id}": {
|
|
||||||
"post": {
|
|
||||||
"summary": "Echo method receives a simple message and returns it.",
|
|
||||||
"description": "The message posted as the id parameter will also be\nreturned.",
|
|
||||||
"operationId": "Echo",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbSimpleMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"EchoService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/example/echo_body": {
|
|
||||||
"post": {
|
|
||||||
"summary": "EchoBody method receives a simple message and returns it.",
|
|
||||||
"operationId": "EchoBody",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbSimpleMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "body",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/examplepbSimpleMessage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"EchoService"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"definitions": {
|
|
||||||
"examplepbSimpleMessage": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Id represents the message identifier."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "SimpleMessage represents a simple message sent to the Echo service."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
723
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.go
generated
vendored
723
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.go
generated
vendored
@ -1,723 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/examplepb/flow_combination.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
type EmptyProto struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *EmptyProto) Reset() { *m = EmptyProto{} }
|
|
||||||
func (m *EmptyProto) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*EmptyProto) ProtoMessage() {}
|
|
||||||
func (*EmptyProto) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{0} }
|
|
||||||
|
|
||||||
type NonEmptyProto struct {
|
|
||||||
A string `protobuf:"bytes,1,opt,name=a" json:"a,omitempty"`
|
|
||||||
B string `protobuf:"bytes,2,opt,name=b" json:"b,omitempty"`
|
|
||||||
C string `protobuf:"bytes,3,opt,name=c" json:"c,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NonEmptyProto) Reset() { *m = NonEmptyProto{} }
|
|
||||||
func (m *NonEmptyProto) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*NonEmptyProto) ProtoMessage() {}
|
|
||||||
func (*NonEmptyProto) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{1} }
|
|
||||||
|
|
||||||
func (m *NonEmptyProto) GetA() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.A
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NonEmptyProto) GetB() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.B
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NonEmptyProto) GetC() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.C
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type UnaryProto struct {
|
|
||||||
Str string `protobuf:"bytes,1,opt,name=str" json:"str,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *UnaryProto) Reset() { *m = UnaryProto{} }
|
|
||||||
func (m *UnaryProto) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*UnaryProto) ProtoMessage() {}
|
|
||||||
func (*UnaryProto) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{2} }
|
|
||||||
|
|
||||||
func (m *UnaryProto) GetStr() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Str
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type NestedProto struct {
|
|
||||||
A *UnaryProto `protobuf:"bytes,1,opt,name=a" json:"a,omitempty"`
|
|
||||||
B string `protobuf:"bytes,2,opt,name=b" json:"b,omitempty"`
|
|
||||||
C string `protobuf:"bytes,3,opt,name=c" json:"c,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NestedProto) Reset() { *m = NestedProto{} }
|
|
||||||
func (m *NestedProto) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*NestedProto) ProtoMessage() {}
|
|
||||||
func (*NestedProto) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{3} }
|
|
||||||
|
|
||||||
func (m *NestedProto) GetA() *UnaryProto {
|
|
||||||
if m != nil {
|
|
||||||
return m.A
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NestedProto) GetB() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.B
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *NestedProto) GetC() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.C
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type SingleNestedProto struct {
|
|
||||||
A *UnaryProto `protobuf:"bytes,1,opt,name=a" json:"a,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SingleNestedProto) Reset() { *m = SingleNestedProto{} }
|
|
||||||
func (m *SingleNestedProto) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*SingleNestedProto) ProtoMessage() {}
|
|
||||||
func (*SingleNestedProto) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{4} }
|
|
||||||
|
|
||||||
func (m *SingleNestedProto) GetA() *UnaryProto {
|
|
||||||
if m != nil {
|
|
||||||
return m.A
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*EmptyProto)(nil), "grpc.gateway.examples.examplepb.EmptyProto")
|
|
||||||
proto.RegisterType((*NonEmptyProto)(nil), "grpc.gateway.examples.examplepb.NonEmptyProto")
|
|
||||||
proto.RegisterType((*UnaryProto)(nil), "grpc.gateway.examples.examplepb.UnaryProto")
|
|
||||||
proto.RegisterType((*NestedProto)(nil), "grpc.gateway.examples.examplepb.NestedProto")
|
|
||||||
proto.RegisterType((*SingleNestedProto)(nil), "grpc.gateway.examples.examplepb.SingleNestedProto")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for FlowCombination service
|
|
||||||
|
|
||||||
type FlowCombinationClient interface {
|
|
||||||
RpcEmptyRpc(ctx context.Context, in *EmptyProto, opts ...grpc.CallOption) (*EmptyProto, error)
|
|
||||||
RpcEmptyStream(ctx context.Context, in *EmptyProto, opts ...grpc.CallOption) (FlowCombination_RpcEmptyStreamClient, error)
|
|
||||||
StreamEmptyRpc(ctx context.Context, opts ...grpc.CallOption) (FlowCombination_StreamEmptyRpcClient, error)
|
|
||||||
StreamEmptyStream(ctx context.Context, opts ...grpc.CallOption) (FlowCombination_StreamEmptyStreamClient, error)
|
|
||||||
RpcBodyRpc(ctx context.Context, in *NonEmptyProto, opts ...grpc.CallOption) (*EmptyProto, error)
|
|
||||||
RpcPathSingleNestedRpc(ctx context.Context, in *SingleNestedProto, opts ...grpc.CallOption) (*EmptyProto, error)
|
|
||||||
RpcPathNestedRpc(ctx context.Context, in *NestedProto, opts ...grpc.CallOption) (*EmptyProto, error)
|
|
||||||
RpcBodyStream(ctx context.Context, in *NonEmptyProto, opts ...grpc.CallOption) (FlowCombination_RpcBodyStreamClient, error)
|
|
||||||
RpcPathSingleNestedStream(ctx context.Context, in *SingleNestedProto, opts ...grpc.CallOption) (FlowCombination_RpcPathSingleNestedStreamClient, error)
|
|
||||||
RpcPathNestedStream(ctx context.Context, in *NestedProto, opts ...grpc.CallOption) (FlowCombination_RpcPathNestedStreamClient, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFlowCombinationClient(cc *grpc.ClientConn) FlowCombinationClient {
|
|
||||||
return &flowCombinationClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcEmptyRpc(ctx context.Context, in *EmptyProto, opts ...grpc.CallOption) (*EmptyProto, error) {
|
|
||||||
out := new(EmptyProto)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.FlowCombination/RpcEmptyRpc", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcEmptyStream(ctx context.Context, in *EmptyProto, opts ...grpc.CallOption) (FlowCombination_RpcEmptyStreamClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[0], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/RpcEmptyStream", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationRpcEmptyStreamClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcEmptyStreamClient interface {
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcEmptyStreamClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcEmptyStreamClient) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) StreamEmptyRpc(ctx context.Context, opts ...grpc.CallOption) (FlowCombination_StreamEmptyRpcClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[1], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/StreamEmptyRpc", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationStreamEmptyRpcClient{stream}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_StreamEmptyRpcClient interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
CloseAndRecv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationStreamEmptyRpcClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyRpcClient) Send(m *EmptyProto) error {
|
|
||||||
return x.ClientStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyRpcClient) CloseAndRecv() (*EmptyProto, error) {
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) StreamEmptyStream(ctx context.Context, opts ...grpc.CallOption) (FlowCombination_StreamEmptyStreamClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[2], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/StreamEmptyStream", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationStreamEmptyStreamClient{stream}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_StreamEmptyStreamClient interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationStreamEmptyStreamClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyStreamClient) Send(m *EmptyProto) error {
|
|
||||||
return x.ClientStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyStreamClient) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcBodyRpc(ctx context.Context, in *NonEmptyProto, opts ...grpc.CallOption) (*EmptyProto, error) {
|
|
||||||
out := new(EmptyProto)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.FlowCombination/RpcBodyRpc", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcPathSingleNestedRpc(ctx context.Context, in *SingleNestedProto, opts ...grpc.CallOption) (*EmptyProto, error) {
|
|
||||||
out := new(EmptyProto)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathSingleNestedRpc", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcPathNestedRpc(ctx context.Context, in *NestedProto, opts ...grpc.CallOption) (*EmptyProto, error) {
|
|
||||||
out := new(EmptyProto)
|
|
||||||
err := grpc.Invoke(ctx, "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathNestedRpc", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcBodyStream(ctx context.Context, in *NonEmptyProto, opts ...grpc.CallOption) (FlowCombination_RpcBodyStreamClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[3], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/RpcBodyStream", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationRpcBodyStreamClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcBodyStreamClient interface {
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcBodyStreamClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcBodyStreamClient) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcPathSingleNestedStream(ctx context.Context, in *SingleNestedProto, opts ...grpc.CallOption) (FlowCombination_RpcPathSingleNestedStreamClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[4], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathSingleNestedStream", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationRpcPathSingleNestedStreamClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcPathSingleNestedStreamClient interface {
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcPathSingleNestedStreamClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcPathSingleNestedStreamClient) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *flowCombinationClient) RpcPathNestedStream(ctx context.Context, in *NestedProto, opts ...grpc.CallOption) (FlowCombination_RpcPathNestedStreamClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_FlowCombination_serviceDesc.Streams[5], c.cc, "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathNestedStream", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &flowCombinationRpcPathNestedStreamClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcPathNestedStreamClient interface {
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcPathNestedStreamClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcPathNestedStreamClient) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for FlowCombination service
|
|
||||||
|
|
||||||
type FlowCombinationServer interface {
|
|
||||||
RpcEmptyRpc(context.Context, *EmptyProto) (*EmptyProto, error)
|
|
||||||
RpcEmptyStream(*EmptyProto, FlowCombination_RpcEmptyStreamServer) error
|
|
||||||
StreamEmptyRpc(FlowCombination_StreamEmptyRpcServer) error
|
|
||||||
StreamEmptyStream(FlowCombination_StreamEmptyStreamServer) error
|
|
||||||
RpcBodyRpc(context.Context, *NonEmptyProto) (*EmptyProto, error)
|
|
||||||
RpcPathSingleNestedRpc(context.Context, *SingleNestedProto) (*EmptyProto, error)
|
|
||||||
RpcPathNestedRpc(context.Context, *NestedProto) (*EmptyProto, error)
|
|
||||||
RpcBodyStream(*NonEmptyProto, FlowCombination_RpcBodyStreamServer) error
|
|
||||||
RpcPathSingleNestedStream(*SingleNestedProto, FlowCombination_RpcPathSingleNestedStreamServer) error
|
|
||||||
RpcPathNestedStream(*NestedProto, FlowCombination_RpcPathNestedStreamServer) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterFlowCombinationServer(s *grpc.Server, srv FlowCombinationServer) {
|
|
||||||
s.RegisterService(&_FlowCombination_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcEmptyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(EmptyProto)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.FlowCombination/RpcEmptyRpc",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, req.(*EmptyProto))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcEmptyStream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(FlowCombinationServer).RpcEmptyStream(m, &flowCombinationRpcEmptyStreamServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcEmptyStreamServer interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcEmptyStreamServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcEmptyStreamServer) Send(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_StreamEmptyRpc_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
return srv.(FlowCombinationServer).StreamEmptyRpc(&flowCombinationStreamEmptyRpcServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_StreamEmptyRpcServer interface {
|
|
||||||
SendAndClose(*EmptyProto) error
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationStreamEmptyRpcServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyRpcServer) SendAndClose(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyRpcServer) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_StreamEmptyStream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
return srv.(FlowCombinationServer).StreamEmptyStream(&flowCombinationStreamEmptyStreamServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_StreamEmptyStreamServer interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
Recv() (*EmptyProto, error)
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationStreamEmptyStreamServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyStreamServer) Send(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationStreamEmptyStreamServer) Recv() (*EmptyProto, error) {
|
|
||||||
m := new(EmptyProto)
|
|
||||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcBodyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(NonEmptyProto)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(FlowCombinationServer).RpcBodyRpc(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.FlowCombination/RpcBodyRpc",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(FlowCombinationServer).RpcBodyRpc(ctx, req.(*NonEmptyProto))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcPathSingleNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(SingleNestedProto)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathSingleNestedRpc",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, req.(*SingleNestedProto))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcPathNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(NestedProto)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/grpc.gateway.examples.examplepb.FlowCombination/RpcPathNestedRpc",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, req.(*NestedProto))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcBodyStream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(NonEmptyProto)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(FlowCombinationServer).RpcBodyStream(m, &flowCombinationRpcBodyStreamServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcBodyStreamServer interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcBodyStreamServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcBodyStreamServer) Send(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcPathSingleNestedStream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(SingleNestedProto)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(FlowCombinationServer).RpcPathSingleNestedStream(m, &flowCombinationRpcPathSingleNestedStreamServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcPathSingleNestedStreamServer interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcPathSingleNestedStreamServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcPathSingleNestedStreamServer) Send(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _FlowCombination_RpcPathNestedStream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(NestedProto)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(FlowCombinationServer).RpcPathNestedStream(m, &flowCombinationRpcPathNestedStreamServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlowCombination_RpcPathNestedStreamServer interface {
|
|
||||||
Send(*EmptyProto) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type flowCombinationRpcPathNestedStreamServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *flowCombinationRpcPathNestedStreamServer) Send(m *EmptyProto) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _FlowCombination_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "grpc.gateway.examples.examplepb.FlowCombination",
|
|
||||||
HandlerType: (*FlowCombinationServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "RpcEmptyRpc",
|
|
||||||
Handler: _FlowCombination_RpcEmptyRpc_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "RpcBodyRpc",
|
|
||||||
Handler: _FlowCombination_RpcBodyRpc_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "RpcPathSingleNestedRpc",
|
|
||||||
Handler: _FlowCombination_RpcPathSingleNestedRpc_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "RpcPathNestedRpc",
|
|
||||||
Handler: _FlowCombination_RpcPathNestedRpc_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{
|
|
||||||
{
|
|
||||||
StreamName: "RpcEmptyStream",
|
|
||||||
Handler: _FlowCombination_RpcEmptyStream_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "StreamEmptyRpc",
|
|
||||||
Handler: _FlowCombination_StreamEmptyRpc_Handler,
|
|
||||||
ClientStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "StreamEmptyStream",
|
|
||||||
Handler: _FlowCombination_StreamEmptyStream_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
ClientStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "RpcBodyStream",
|
|
||||||
Handler: _FlowCombination_RpcBodyStream_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "RpcPathSingleNestedStream",
|
|
||||||
Handler: _FlowCombination_RpcPathSingleNestedStream_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "RpcPathNestedStream",
|
|
||||||
Handler: _FlowCombination_RpcPathNestedStream_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Metadata: "examples/examplepb/flow_combination.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/examplepb/flow_combination.proto", fileDescriptor3) }
|
|
||||||
|
|
||||||
var fileDescriptor3 = []byte{
|
|
||||||
// 656 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x96, 0x3f, 0x8f, 0x12, 0x4f,
|
|
||||||
0x18, 0xc7, 0xf3, 0x70, 0xc9, 0x2f, 0xb9, 0xe1, 0xfe, 0x70, 0xcb, 0x2f, 0x08, 0x1c, 0x1e, 0x77,
|
|
||||||
0xe3, 0x25, 0xe2, 0xbf, 0x5d, 0x82, 0xd5, 0x51, 0x9e, 0xd1, 0x92, 0x5c, 0xb8, 0xd8, 0x6c, 0x63,
|
|
||||||
0x66, 0x87, 0x15, 0x48, 0x60, 0x67, 0x6e, 0x77, 0x0d, 0x5e, 0x08, 0x31, 0xb1, 0xb1, 0xb4, 0xf0,
|
|
||||||
0x05, 0x58, 0x5a, 0xf9, 0x06, 0xec, 0xac, 0x6c, 0x4c, 0x2c, 0x4c, 0xec, 0xec, 0xec, 0x7c, 0x13,
|
|
||||||
0x66, 0x67, 0x66, 0x77, 0x58, 0x05, 0x37, 0x18, 0xb1, 0xdb, 0x99, 0x79, 0x9e, 0x67, 0x3e, 0xf3,
|
|
||||||
0x7d, 0xbe, 0x0f, 0x01, 0xdd, 0x70, 0x9f, 0x92, 0x31, 0x1f, 0xb9, 0x81, 0xa5, 0x3e, 0xb8, 0x63,
|
|
||||||
0x3d, 0x1e, 0xb1, 0xc9, 0x23, 0xca, 0xc6, 0xce, 0xd0, 0x23, 0xe1, 0x90, 0x79, 0x26, 0xf7, 0x59,
|
|
||||||
0xc8, 0x8c, 0x7a, 0xdf, 0xe7, 0xd4, 0xec, 0x93, 0xd0, 0x9d, 0x90, 0x4b, 0x33, 0xce, 0x33, 0x93,
|
|
||||||
0xbc, 0x6a, 0xad, 0xcf, 0x58, 0x7f, 0xe4, 0x5a, 0x84, 0x0f, 0x2d, 0xe2, 0x79, 0x2c, 0x14, 0xd9,
|
|
||||||
0x81, 0x4c, 0xc7, 0x5b, 0x08, 0xdd, 0x1f, 0xf3, 0xf0, 0xf2, 0x4c, 0xac, 0x4e, 0xd0, 0x76, 0x87,
|
|
||||||
0x79, 0x7a, 0xc3, 0xd8, 0x42, 0x40, 0xca, 0x70, 0x08, 0x8d, 0xcd, 0x2e, 0x90, 0x68, 0xe5, 0x94,
|
|
||||||
0x73, 0x72, 0xe5, 0x44, 0x2b, 0x5a, 0xde, 0x90, 0x2b, 0x8a, 0x0f, 0x10, 0x7a, 0xe8, 0x11, 0x5f,
|
|
||||||
0xe5, 0x15, 0xd0, 0x46, 0x10, 0xfa, 0x2a, 0x33, 0xfa, 0xc4, 0x3d, 0x94, 0xef, 0xb8, 0x41, 0xe8,
|
|
||||||
0xf6, 0x64, 0xc0, 0x49, 0x5c, 0x38, 0xdf, 0xba, 0x65, 0x66, 0x3c, 0xc1, 0xd4, 0x85, 0xb3, 0x28,
|
|
||||||
0x3a, 0x68, 0xef, 0x7c, 0xe8, 0xf5, 0x47, 0xee, 0xdf, 0xb9, 0xab, 0xf5, 0x71, 0x17, 0xed, 0x3e,
|
|
||||||
0x18, 0xb1, 0xc9, 0x3d, 0xad, 0xbb, 0xf1, 0x0c, 0xe5, 0xbb, 0x9c, 0x0a, 0x91, 0xba, 0x9c, 0x1a,
|
|
||||||
0xd9, 0x25, 0xb5, 0x9e, 0xd5, 0x55, 0x82, 0x71, 0xe9, 0xf9, 0xe7, 0x6f, 0xaf, 0x72, 0x05, 0xbc,
|
|
||||||
0x63, 0xf9, 0x9c, 0x5a, 0x6e, 0x74, 0x10, 0x7d, 0x19, 0x2f, 0x00, 0xed, 0xc4, 0x04, 0xe7, 0xa1,
|
|
||||||
0xef, 0x92, 0xf1, 0x1a, 0x21, 0x2a, 0x02, 0xa2, 0x88, 0xf7, 0xe6, 0x20, 0x02, 0x71, 0x69, 0x13,
|
|
||||||
0x04, 0x89, 0x24, 0xf8, 0x07, 0x72, 0x68, 0x12, 0x79, 0xbf, 0x56, 0xa4, 0x01, 0xc6, 0x4b, 0x40,
|
|
||||||
0x7b, 0x73, 0x24, 0x6b, 0x97, 0xa5, 0x26, 0x60, 0x4a, 0xf8, 0xff, 0x34, 0x8c, 0x5c, 0x34, 0xa0,
|
|
||||||
0x09, 0xc6, 0xdb, 0x1c, 0x42, 0x5d, 0x4e, 0x4f, 0x59, 0x4f, 0xe8, 0x62, 0x66, 0x56, 0x4f, 0x4d,
|
|
||||||
0xde, 0x6a, 0x34, 0xef, 0x41, 0xe0, 0xbc, 0x03, 0xbc, 0x2d, 0xda, 0xe4, 0xb0, 0x9e, 0x10, 0xa6,
|
|
||||||
0x0d, 0x37, 0xed, 0x7d, 0x5c, 0x11, 0x7b, 0x9c, 0x84, 0x03, 0x6b, 0x4a, 0x66, 0xd6, 0xd4, 0x99,
|
|
||||||
0x59, 0x53, 0x3a, 0x8b, 0x36, 0xed, 0xd8, 0x5c, 0x17, 0x4f, 0x5c, 0x5f, 0x64, 0xd8, 0x75, 0x5c,
|
|
||||||
0xd5, 0x25, 0x52, 0x39, 0xa2, 0x1e, 0xb5, 0xcb, 0xb8, 0xa8, 0x03, 0x92, 0xbc, 0xe8, 0xe4, 0x08,
|
|
||||||
0xd7, 0x16, 0xa4, 0xa6, 0x42, 0x2a, 0xf8, 0x4a, 0x1a, 0x26, 0x39, 0x35, 0x5e, 0x03, 0x2a, 0x75,
|
|
||||||
0x39, 0x3d, 0x23, 0xe1, 0x60, 0x7e, 0x84, 0x23, 0xed, 0x5a, 0x99, 0x5a, 0xfc, 0x32, 0xf4, 0xab,
|
|
||||||
0xe9, 0x77, 0x2c, 0xe4, 0x3b, 0x50, 0xfc, 0x11, 0xdc, 0x1d, 0x4f, 0xd4, 0xb2, 0xa6, 0xc4, 0x0c,
|
|
||||||
0x42, 0x5f, 0x3c, 0xde, 0xf8, 0x0a, 0xa8, 0xa0, 0x08, 0x35, 0xdb, 0xed, 0xec, 0xbe, 0xfe, 0x29,
|
|
||||||
0x95, 0x27, 0xa8, 0x06, 0xf8, 0x70, 0x29, 0xd5, 0x5c, 0x5b, 0x32, 0xe0, 0x93, 0xe6, 0x2c, 0x39,
|
|
||||||
0x6f, 0x03, 0x35, 0x3e, 0xe4, 0xd0, 0xb6, 0x72, 0xac, 0x9a, 0x9f, 0xb5, 0x9a, 0xf6, 0x8b, 0x34,
|
|
||||||
0xed, 0x27, 0xc0, 0x05, 0x6d, 0x1b, 0x39, 0x40, 0x91, 0x6f, 0xe7, 0x1f, 0x94, 0xf2, 0xad, 0x0c,
|
|
||||||
0xb1, 0xe3, 0x9f, 0x24, 0xe9, 0x20, 0xb5, 0x89, 0xf1, 0xd5, 0x25, 0xee, 0x8d, 0x0b, 0x53, 0x7b,
|
|
||||||
0x1f, 0x97, 0x7e, 0x36, 0xb0, 0x3e, 0x3c, 0xc6, 0xf5, 0xa5, 0x1e, 0xd6, 0x51, 0x35, 0x35, 0x24,
|
|
||||||
0x0b, 0x03, 0x9a, 0x60, 0xbc, 0x01, 0x54, 0x59, 0xe0, 0x65, 0xa5, 0xea, 0xda, 0xed, 0x7c, 0x5d,
|
|
||||||
0x08, 0x7b, 0xa4, 0x9e, 0xb2, 0xa8, 0xe3, 0x09, 0xe9, 0x77, 0x40, 0xc5, 0x94, 0xa7, 0x15, 0xe3,
|
|
||||||
0x1a, 0x6d, 0x3d, 0x11, 0x74, 0x17, 0xf8, 0xda, 0x6f, 0x6d, 0xad, 0xc5, 0xce, 0x7e, 0x47, 0xd2,
|
|
||||||
0xb5, 0xe5, 0x21, 0x6d, 0xa0, 0x4d, 0x38, 0xcd, 0xdb, 0x9b, 0x09, 0x92, 0xf3, 0x9f, 0xf8, 0x07,
|
|
||||||
0x74, 0xf7, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0xaf, 0x85, 0xaf, 0x3c, 0x6d, 0x09, 0x00, 0x00,
|
|
||||||
}
|
|
1854
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go
generated
vendored
1854
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go
generated
vendored
File diff suppressed because it is too large
Load Diff
168
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.proto
generated
vendored
168
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.proto
generated
vendored
@ -1,168 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option go_package = "examplepb";
|
|
||||||
package grpc.gateway.examples.examplepb;
|
|
||||||
|
|
||||||
import "google/api/annotations.proto";
|
|
||||||
|
|
||||||
message EmptyProto {}
|
|
||||||
|
|
||||||
message NonEmptyProto {
|
|
||||||
string a = 1;
|
|
||||||
string b = 2;
|
|
||||||
string c = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UnaryProto {
|
|
||||||
string str = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message NestedProto {
|
|
||||||
UnaryProto a = 1;
|
|
||||||
string b = 2;
|
|
||||||
string c = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SingleNestedProto {
|
|
||||||
UnaryProto a = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
service FlowCombination {
|
|
||||||
rpc RpcEmptyRpc(EmptyProto) returns (EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/rpc/empty/rpc"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc RpcEmptyStream(EmptyProto) returns (stream EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/rpc/empty/stream"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc StreamEmptyRpc(stream EmptyProto) returns (EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/stream/empty/rpc"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc StreamEmptyStream(stream EmptyProto) returns (stream EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/stream/empty/stream"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc RpcBodyRpc(NonEmptyProto) returns (EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/ body; w/o path; w/o query
|
|
||||||
post: "/rpc/body/rpc"
|
|
||||||
body: "*"
|
|
||||||
|
|
||||||
// w/o body; w/ path; w/o query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path/{a}/{b}/{c}/rpc"
|
|
||||||
}
|
|
||||||
// w/o body; w/o path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/query/rpc"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path; w/o query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/path/{a}/{b}/rpc"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/ body; w/o path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/query/rpc"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/path/{a}/query/rpc"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/o body; w/ path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path/{a}/query/rpc"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc RpcPathSingleNestedRpc(SingleNestedProto) returns (EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/o body; w/ path (IsNestedProto3); w/o query
|
|
||||||
post: "/rpc/path-nested/{a.str}/rpc"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc RpcPathNestedRpc(NestedProto) returns (EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/ body; w/ path (IsNestedProto3); w/o query
|
|
||||||
post: "/rpc/path-nested/{a.str}/{b}/rpc"
|
|
||||||
body: "c"
|
|
||||||
|
|
||||||
// w/o body; w/ path (IsNestedProto3); w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path-nested/{a.str}/rpc"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path (IsNestedProto3); w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path-nested/{a.str}/rpc"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc RpcBodyStream(NonEmptyProto) returns (stream EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/ body; w/o path; w/o query
|
|
||||||
post: "/rpc/body/stream"
|
|
||||||
body: "*"
|
|
||||||
|
|
||||||
// w/o body; w/ path; w/o query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path/{a}/{b}/{c}/stream"
|
|
||||||
}
|
|
||||||
// w/o body; w/o path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/query/stream"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path; w/o query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/path/{a}/{b}/stream"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/ body; w/o path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/query/stream"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/body/path/{a}/query/stream"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
// w/o body; w/ path; w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path/{a}/query/stream"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc RpcPathSingleNestedStream(SingleNestedProto) returns (stream EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/o body; w/ path (IsNestedProto3); w/o query
|
|
||||||
post: "/rpc/path-nested/{a.str}/stream"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc RpcPathNestedStream(NestedProto) returns (stream EmptyProto) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
// w/ body; w/ path (IsNestedProto3); w/o query
|
|
||||||
post: "/rpc/path-nested/{a.str}/{b}/stream"
|
|
||||||
body: "c"
|
|
||||||
|
|
||||||
// w/o body; w/ path (IsNestedProto3); w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path-nested/{a.str}/stream"
|
|
||||||
}
|
|
||||||
// w/ body; w/ path (IsNestedProto3); w/ query
|
|
||||||
additional_bindings {
|
|
||||||
post: "/rpc/path-nested/{a.str}/stream"
|
|
||||||
body: "c"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
279
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.go
generated
vendored
279
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.go
generated
vendored
@ -1,279 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/examplepb/stream.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
import google_protobuf1 "github.com/golang/protobuf/ptypes/empty"
|
|
||||||
import grpc_gateway_examples_sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for StreamService service
|
|
||||||
|
|
||||||
type StreamServiceClient interface {
|
|
||||||
BulkCreate(ctx context.Context, opts ...grpc.CallOption) (StreamService_BulkCreateClient, error)
|
|
||||||
List(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (StreamService_ListClient, error)
|
|
||||||
BulkEcho(ctx context.Context, opts ...grpc.CallOption) (StreamService_BulkEchoClient, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewStreamServiceClient(cc *grpc.ClientConn) StreamServiceClient {
|
|
||||||
return &streamServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *streamServiceClient) BulkCreate(ctx context.Context, opts ...grpc.CallOption) (StreamService_BulkCreateClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_StreamService_serviceDesc.Streams[0], c.cc, "/grpc.gateway.examples.examplepb.StreamService/BulkCreate", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &streamServiceBulkCreateClient{stream}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_BulkCreateClient interface {
|
|
||||||
Send(*ABitOfEverything) error
|
|
||||||
CloseAndRecv() (*google_protobuf1.Empty, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceBulkCreateClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkCreateClient) Send(m *ABitOfEverything) error {
|
|
||||||
return x.ClientStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkCreateClient) CloseAndRecv() (*google_protobuf1.Empty, error) {
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
m := new(google_protobuf1.Empty)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *streamServiceClient) List(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (StreamService_ListClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_StreamService_serviceDesc.Streams[1], c.cc, "/grpc.gateway.examples.examplepb.StreamService/List", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &streamServiceListClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_ListClient interface {
|
|
||||||
Recv() (*ABitOfEverything, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceListClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceListClient) Recv() (*ABitOfEverything, error) {
|
|
||||||
m := new(ABitOfEverything)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *streamServiceClient) BulkEcho(ctx context.Context, opts ...grpc.CallOption) (StreamService_BulkEchoClient, error) {
|
|
||||||
stream, err := grpc.NewClientStream(ctx, &_StreamService_serviceDesc.Streams[2], c.cc, "/grpc.gateway.examples.examplepb.StreamService/BulkEcho", opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &streamServiceBulkEchoClient{stream}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_BulkEchoClient interface {
|
|
||||||
Send(*grpc_gateway_examples_sub.StringMessage) error
|
|
||||||
Recv() (*grpc_gateway_examples_sub.StringMessage, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceBulkEchoClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkEchoClient) Send(m *grpc_gateway_examples_sub.StringMessage) error {
|
|
||||||
return x.ClientStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkEchoClient) Recv() (*grpc_gateway_examples_sub.StringMessage, error) {
|
|
||||||
m := new(grpc_gateway_examples_sub.StringMessage)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for StreamService service
|
|
||||||
|
|
||||||
type StreamServiceServer interface {
|
|
||||||
BulkCreate(StreamService_BulkCreateServer) error
|
|
||||||
List(*google_protobuf1.Empty, StreamService_ListServer) error
|
|
||||||
BulkEcho(StreamService_BulkEchoServer) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterStreamServiceServer(s *grpc.Server, srv StreamServiceServer) {
|
|
||||||
s.RegisterService(&_StreamService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _StreamService_BulkCreate_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
return srv.(StreamServiceServer).BulkCreate(&streamServiceBulkCreateServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_BulkCreateServer interface {
|
|
||||||
SendAndClose(*google_protobuf1.Empty) error
|
|
||||||
Recv() (*ABitOfEverything, error)
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceBulkCreateServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkCreateServer) SendAndClose(m *google_protobuf1.Empty) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkCreateServer) Recv() (*ABitOfEverything, error) {
|
|
||||||
m := new(ABitOfEverything)
|
|
||||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _StreamService_List_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(google_protobuf1.Empty)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(StreamServiceServer).List(m, &streamServiceListServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_ListServer interface {
|
|
||||||
Send(*ABitOfEverything) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceListServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceListServer) Send(m *ABitOfEverything) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _StreamService_BulkEcho_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
return srv.(StreamServiceServer).BulkEcho(&streamServiceBulkEchoServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamService_BulkEchoServer interface {
|
|
||||||
Send(*grpc_gateway_examples_sub.StringMessage) error
|
|
||||||
Recv() (*grpc_gateway_examples_sub.StringMessage, error)
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamServiceBulkEchoServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkEchoServer) Send(m *grpc_gateway_examples_sub.StringMessage) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *streamServiceBulkEchoServer) Recv() (*grpc_gateway_examples_sub.StringMessage, error) {
|
|
||||||
m := new(grpc_gateway_examples_sub.StringMessage)
|
|
||||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var _StreamService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "grpc.gateway.examples.examplepb.StreamService",
|
|
||||||
HandlerType: (*StreamServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{},
|
|
||||||
Streams: []grpc.StreamDesc{
|
|
||||||
{
|
|
||||||
StreamName: "BulkCreate",
|
|
||||||
Handler: _StreamService_BulkCreate_Handler,
|
|
||||||
ClientStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "List",
|
|
||||||
Handler: _StreamService_List_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "BulkEcho",
|
|
||||||
Handler: _StreamService_BulkEcho_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
ClientStreams: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Metadata: "examples/examplepb/stream.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/examplepb/stream.proto", fileDescriptor2) }
|
|
||||||
|
|
||||||
var fileDescriptor2 = []byte{
|
|
||||||
// 314 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x90, 0xbf, 0x4a, 0x43, 0x31,
|
|
||||||
0x14, 0xc6, 0xb9, 0x2a, 0xa2, 0x11, 0x97, 0x0c, 0x0e, 0x51, 0x28, 0x16, 0xc1, 0x2a, 0x92, 0xb4,
|
|
||||||
0xba, 0xb9, 0x59, 0xe9, 0xa6, 0x38, 0x74, 0x73, 0x29, 0xc9, 0xe5, 0x34, 0x0d, 0xbd, 0xf7, 0x26,
|
|
||||||
0x24, 0xe7, 0x56, 0x0b, 0x4e, 0x8e, 0xae, 0x7d, 0x11, 0xdf, 0xc5, 0x57, 0xf0, 0x41, 0xa4, 0xf7,
|
|
||||||
0xdf, 0xd4, 0xd2, 0xba, 0x25, 0x9c, 0x2f, 0xf9, 0x7e, 0xe7, 0x47, 0x5a, 0xf0, 0x2e, 0x53, 0x97,
|
|
||||||
0x40, 0x10, 0xd5, 0xc1, 0x29, 0x11, 0xd0, 0x83, 0x4c, 0xb9, 0xf3, 0x16, 0x2d, 0x6d, 0x69, 0xef,
|
|
||||||
0x62, 0xae, 0x25, 0xc2, 0x9b, 0x9c, 0xf3, 0x3a, 0xcd, 0x9b, 0x34, 0x3b, 0xd3, 0xd6, 0xea, 0x04,
|
|
||||||
0x84, 0x74, 0x46, 0xc8, 0x2c, 0xb3, 0x28, 0xd1, 0xd8, 0x2c, 0x94, 0xcf, 0xd9, 0x69, 0x35, 0x2d,
|
|
||||||
0x6e, 0x2a, 0x1f, 0x0b, 0x48, 0x1d, 0xce, 0xab, 0xe1, 0xcd, 0x8a, 0x72, 0x39, 0x52, 0x06, 0x47,
|
|
||||||
0x76, 0x3c, 0x82, 0x19, 0xf8, 0x39, 0x4e, 0x4c, 0xa6, 0xab, 0x34, 0x6b, 0xd2, 0x21, 0x57, 0x22,
|
|
||||||
0x85, 0x10, 0xa4, 0x86, 0x72, 0x76, 0xfb, 0xbd, 0x4b, 0x8e, 0x87, 0x05, 0xf6, 0x10, 0xfc, 0xcc,
|
|
||||||
0xc4, 0x40, 0xbf, 0x22, 0x42, 0xfa, 0x79, 0x32, 0x7d, 0xf4, 0x20, 0x11, 0x68, 0x8f, 0x6f, 0xd8,
|
|
||||||
0x83, 0x3f, 0xf4, 0x0d, 0xbe, 0x8c, 0x07, 0x4d, 0x2b, 0x3b, 0xe1, 0x25, 0x3b, 0xaf, 0xd9, 0xf9,
|
|
||||||
0x60, 0xc9, 0xde, 0x16, 0x9f, 0x3f, 0xbf, 0x8b, 0x9d, 0xab, 0xf6, 0x85, 0x98, 0xf5, 0x6a, 0xf0,
|
|
||||||
0x55, 0xd8, 0x42, 0xe5, 0xc9, 0xf4, 0x3e, 0xba, 0xee, 0x44, 0xf4, 0x83, 0xec, 0x3d, 0x99, 0x80,
|
|
||||||
0x74, 0xcd, 0x97, 0xec, 0xff, 0x74, 0xed, 0xcb, 0x82, 0xe2, 0x9c, 0xb6, 0x36, 0x50, 0x74, 0x23,
|
|
||||||
0xba, 0x88, 0xc8, 0xc1, 0x52, 0xc5, 0x20, 0x9e, 0x58, 0xda, 0x59, 0x53, 0x15, 0x72, 0xc5, 0x87,
|
|
||||||
0xe8, 0x4d, 0xa6, 0x9f, 0x4b, 0xb3, 0x6c, 0xeb, 0xe4, 0xf6, 0x46, 0x20, 0x9e, 0xd8, 0xc2, 0x48,
|
|
||||||
0x37, 0xea, 0x1f, 0xbd, 0x1e, 0x36, 0xeb, 0xa9, 0xfd, 0x42, 0xc8, 0xdd, 0x5f, 0x00, 0x00, 0x00,
|
|
||||||
0xff, 0xff, 0xbc, 0x52, 0x49, 0x85, 0x8f, 0x02, 0x00, 0x00,
|
|
||||||
}
|
|
273
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go
generated
vendored
273
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go
generated
vendored
@ -1,273 +0,0 @@
|
|||||||
// Code generated by protoc-gen-grpc-gateway
|
|
||||||
// source: examples/examplepb/stream.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package examplepb is a reverse proxy.
|
|
||||||
|
|
||||||
It translates gRPC into RESTful JSON APIs.
|
|
||||||
*/
|
|
||||||
package examplepb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ codes.Code
|
|
||||||
var _ io.Reader
|
|
||||||
var _ = runtime.String
|
|
||||||
var _ = utilities.NewDoubleArray
|
|
||||||
|
|
||||||
func request_StreamService_BulkCreate_0(ctx context.Context, marshaler runtime.Marshaler, client StreamServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
stream, err := client.BulkCreate(ctx)
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to start streaming: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
dec := marshaler.NewDecoder(req.Body)
|
|
||||||
for {
|
|
||||||
var protoReq ABitOfEverything
|
|
||||||
err = dec.Decode(&protoReq)
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to decode request: %v", err)
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
if err = stream.Send(&protoReq); err != nil {
|
|
||||||
grpclog.Printf("Failed to send request: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := stream.CloseSend(); err != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to get header from client: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
|
|
||||||
msg, err := stream.CloseAndRecv()
|
|
||||||
metadata.TrailerMD = stream.Trailer()
|
|
||||||
return msg, metadata, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_StreamService_List_0(ctx context.Context, marshaler runtime.Marshaler, client StreamServiceClient, req *http.Request, pathParams map[string]string) (StreamService_ListClient, runtime.ServerMetadata, error) {
|
|
||||||
var protoReq empty.Empty
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
|
|
||||||
stream, err := client.List(ctx, &protoReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
return stream, metadata, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func request_StreamService_BulkEcho_0(ctx context.Context, marshaler runtime.Marshaler, client StreamServiceClient, req *http.Request, pathParams map[string]string) (StreamService_BulkEchoClient, runtime.ServerMetadata, error) {
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
stream, err := client.BulkEcho(ctx)
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to start streaming: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
dec := marshaler.NewDecoder(req.Body)
|
|
||||||
handleSend := func() error {
|
|
||||||
var protoReq sub.StringMessage
|
|
||||||
err = dec.Decode(&protoReq)
|
|
||||||
if err == io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to decode request: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err = stream.Send(&protoReq); err != nil {
|
|
||||||
grpclog.Printf("Failed to send request: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := handleSend(); err != nil {
|
|
||||||
if cerr := stream.CloseSend(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", cerr)
|
|
||||||
}
|
|
||||||
if err == io.EOF {
|
|
||||||
return stream, metadata, nil
|
|
||||||
}
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
if err := handleSend(); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := stream.CloseSend(); err != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to get header from client: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
return stream, metadata, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterStreamServiceHandlerFromEndpoint is same as RegisterStreamServiceHandler but
|
|
||||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
|
||||||
func RegisterStreamServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
|
||||||
conn, err := grpc.Dial(endpoint, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return RegisterStreamServiceHandler(ctx, mux, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterStreamServiceHandler registers the http handlers for service StreamService to "mux".
|
|
||||||
// The handlers forward requests to the grpc endpoint over "conn".
|
|
||||||
func RegisterStreamServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
|
||||||
client := NewStreamServiceClient(conn)
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_StreamService_BulkCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_StreamService_BulkCreate_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_StreamService_BulkCreate_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("GET", pattern_StreamService_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_StreamService_List_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_StreamService_List_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.Handle("POST", pattern_StreamService_BulkEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_StreamService_BulkEcho_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_StreamService_BulkEcho_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
pattern_StreamService_BulkCreate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "a_bit_of_everything", "bulk"}, ""))
|
|
||||||
|
|
||||||
pattern_StreamService_List_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "example", "a_bit_of_everything"}, ""))
|
|
||||||
|
|
||||||
pattern_StreamService_BulkEcho_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "a_bit_of_everything", "echo"}, ""))
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
forward_StreamService_BulkCreate_0 = runtime.ForwardResponseMessage
|
|
||||||
|
|
||||||
forward_StreamService_List_0 = runtime.ForwardResponseStream
|
|
||||||
|
|
||||||
forward_StreamService_BulkEcho_0 = runtime.ForwardResponseStream
|
|
||||||
)
|
|
29
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.proto
generated
vendored
29
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.proto
generated
vendored
@ -1,29 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option go_package = "examplepb";
|
|
||||||
package grpc.gateway.examples.examplepb;
|
|
||||||
|
|
||||||
import "google/api/annotations.proto";
|
|
||||||
import "google/protobuf/empty.proto";
|
|
||||||
import "examples/examplepb/a_bit_of_everything.proto";
|
|
||||||
import "examples/sub/message.proto";
|
|
||||||
|
|
||||||
// Defines some more operations to be added to ABitOfEverythingService
|
|
||||||
service StreamService {
|
|
||||||
rpc BulkCreate(stream ABitOfEverything) returns (google.protobuf.Empty) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/a_bit_of_everything/bulk"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc List(google.protobuf.Empty) returns (stream ABitOfEverything) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
get: "/v1/example/a_bit_of_everything"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rpc BulkEcho(stream grpc.gateway.examples.sub.StringMessage) returns (stream grpc.gateway.examples.sub.StringMessage) {
|
|
||||||
option (google.api.http) = {
|
|
||||||
post: "/v1/example/a_bit_of_everything/echo"
|
|
||||||
body: "*"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
719
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/integration_test.go
generated
vendored
719
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/integration_test.go
generated
vendored
@ -1,719 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/jsonpb"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
gw "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
)
|
|
||||||
|
|
||||||
type errorBody struct {
|
|
||||||
Error string `json:"error"`
|
|
||||||
Code int `json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEcho(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
testEcho(t, 8080, "application/json")
|
|
||||||
testEchoBody(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestForwardResponseOption(t *testing.T) {
|
|
||||||
go func() {
|
|
||||||
if err := Run(
|
|
||||||
":8081",
|
|
||||||
runtime.WithForwardResponseOption(
|
|
||||||
func(_ context.Context, w http.ResponseWriter, _ proto.Message) error {
|
|
||||||
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1.1+json")
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
),
|
|
||||||
); err != nil {
|
|
||||||
t.Errorf("gw.Run() failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
testEcho(t, 8081, "application/vnd.docker.plugins.v1.1+json")
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEcho(t *testing.T, port int, contentType string) {
|
|
||||||
url := fmt.Sprintf("http://localhost:%d/v1/example/echo/myid", port)
|
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader("{}"))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg gw.SimpleMessage
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.Id, "myid"; got != want {
|
|
||||||
t.Errorf("msg.Id = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if value := resp.Header.Get("Content-Type"); value != contentType {
|
|
||||||
t.Errorf("Content-Type was %s, wanted %s", value, contentType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEchoBody(t *testing.T) {
|
|
||||||
sent := gw.SimpleMessage{Id: "example"}
|
|
||||||
var m jsonpb.Marshaler
|
|
||||||
payload, err := m.MarshalToString(&sent)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("m.MarshalToString(%#v) failed with %v; want success", payload, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "http://localhost:8080/v1/example/echo_body"
|
|
||||||
resp, err := http.Post(url, "", strings.NewReader(payload))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var received gw.SimpleMessage
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &received); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := received, sent; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("msg.Id = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Header.Get("Grpc-Metadata-Foo"), "foo1"; got != want {
|
|
||||||
t.Errorf("Grpc-Metadata-Foo was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := resp.Header.Get("Grpc-Metadata-Bar"), "bar1"; got != want {
|
|
||||||
t.Errorf("Grpc-Metadata-Bar was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestABE(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
testABECreate(t)
|
|
||||||
testABECreateBody(t)
|
|
||||||
testABEBulkCreate(t)
|
|
||||||
testABELookup(t)
|
|
||||||
testABELookupNotFound(t)
|
|
||||||
testABEList(t)
|
|
||||||
testABEBulkEcho(t)
|
|
||||||
testABEBulkEchoZeroLength(t)
|
|
||||||
testAdditionalBindings(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABECreate(t *testing.T) {
|
|
||||||
want := gw.ABitOfEverything{
|
|
||||||
FloatValue: 1.5,
|
|
||||||
DoubleValue: 2.5,
|
|
||||||
Int64Value: 4294967296,
|
|
||||||
Uint64Value: 9223372036854775807,
|
|
||||||
Int32Value: -2147483648,
|
|
||||||
Fixed64Value: 9223372036854775807,
|
|
||||||
Fixed32Value: 4294967295,
|
|
||||||
BoolValue: true,
|
|
||||||
StringValue: "strprefix/foo",
|
|
||||||
Uint32Value: 4294967295,
|
|
||||||
Sfixed32Value: 2147483647,
|
|
||||||
Sfixed64Value: -4611686018427387904,
|
|
||||||
Sint32Value: 2147483647,
|
|
||||||
Sint64Value: 4611686018427387903,
|
|
||||||
NonConventionalNameValue: "camelCase",
|
|
||||||
}
|
|
||||||
url := fmt.Sprintf("http://localhost:8080/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s", want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue)
|
|
||||||
|
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader("{}"))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg gw.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if msg.Uuid == "" {
|
|
||||||
t.Error("msg.Uuid is empty; want not empty")
|
|
||||||
}
|
|
||||||
msg.Uuid = ""
|
|
||||||
if got := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("msg= %v; want %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABECreateBody(t *testing.T) {
|
|
||||||
want := gw.ABitOfEverything{
|
|
||||||
FloatValue: 1.5,
|
|
||||||
DoubleValue: 2.5,
|
|
||||||
Int64Value: 4294967296,
|
|
||||||
Uint64Value: 9223372036854775807,
|
|
||||||
Int32Value: -2147483648,
|
|
||||||
Fixed64Value: 9223372036854775807,
|
|
||||||
Fixed32Value: 4294967295,
|
|
||||||
BoolValue: true,
|
|
||||||
StringValue: "strprefix/foo",
|
|
||||||
Uint32Value: 4294967295,
|
|
||||||
Sfixed32Value: 2147483647,
|
|
||||||
Sfixed64Value: -4611686018427387904,
|
|
||||||
Sint32Value: 2147483647,
|
|
||||||
Sint64Value: 4611686018427387903,
|
|
||||||
NonConventionalNameValue: "camelCase",
|
|
||||||
|
|
||||||
Nested: []*gw.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "bar",
|
|
||||||
Amount: 10,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "baz",
|
|
||||||
Amount: 20,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RepeatedStringValue: []string{"a", "b", "c"},
|
|
||||||
OneofValue: &gw.ABitOfEverything_OneofString{
|
|
||||||
OneofString: "x",
|
|
||||||
},
|
|
||||||
MapValue: map[string]gw.NumericEnum{
|
|
||||||
"a": gw.NumericEnum_ONE,
|
|
||||||
"b": gw.NumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
MappedStringValue: map[string]string{
|
|
||||||
"a": "x",
|
|
||||||
"b": "y",
|
|
||||||
},
|
|
||||||
MappedNestedValue: map[string]*gw.ABitOfEverything_Nested{
|
|
||||||
"a": {Name: "x", Amount: 1},
|
|
||||||
"b": {Name: "y", Amount: 2},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything"
|
|
||||||
var m jsonpb.Marshaler
|
|
||||||
payload, err := m.MarshalToString(&want)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("m.MarshalToString(%#v) failed with %v; want success", want, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader(payload))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg gw.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if msg.Uuid == "" {
|
|
||||||
t.Error("msg.Uuid is empty; want not empty")
|
|
||||||
}
|
|
||||||
msg.Uuid = ""
|
|
||||||
if got := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("msg= %v; want %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEBulkCreate(t *testing.T) {
|
|
||||||
count := 0
|
|
||||||
r, w := io.Pipe()
|
|
||||||
go func(w io.WriteCloser) {
|
|
||||||
defer func() {
|
|
||||||
if cerr := w.Close(); cerr != nil {
|
|
||||||
t.Errorf("w.Close() failed with %v; want success", cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for _, val := range []string{
|
|
||||||
"foo", "bar", "baz", "qux", "quux",
|
|
||||||
} {
|
|
||||||
want := gw.ABitOfEverything{
|
|
||||||
FloatValue: 1.5,
|
|
||||||
DoubleValue: 2.5,
|
|
||||||
Int64Value: 4294967296,
|
|
||||||
Uint64Value: 9223372036854775807,
|
|
||||||
Int32Value: -2147483648,
|
|
||||||
Fixed64Value: 9223372036854775807,
|
|
||||||
Fixed32Value: 4294967295,
|
|
||||||
BoolValue: true,
|
|
||||||
StringValue: fmt.Sprintf("strprefix/%s", val),
|
|
||||||
Uint32Value: 4294967295,
|
|
||||||
Sfixed32Value: 2147483647,
|
|
||||||
Sfixed64Value: -4611686018427387904,
|
|
||||||
Sint32Value: 2147483647,
|
|
||||||
Sint64Value: 4611686018427387903,
|
|
||||||
NonConventionalNameValue: "camelCase",
|
|
||||||
|
|
||||||
Nested: []*gw.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "hoge",
|
|
||||||
Amount: 10,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "fuga",
|
|
||||||
Amount: 20,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
var m jsonpb.Marshaler
|
|
||||||
if err := m.Marshal(w, &want); err != nil {
|
|
||||||
t.Fatalf("m.Marshal(%#v, w) failed with %v; want success", want, err)
|
|
||||||
}
|
|
||||||
if _, err := io.WriteString(w, "\n"); err != nil {
|
|
||||||
t.Errorf("w.Write(%q) failed with %v; want success", "\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}(w)
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything/bulk"
|
|
||||||
resp, err := http.Post(url, "application/json", r)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg empty.Empty
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Header.Get("Grpc-Metadata-Count"), fmt.Sprintf("%d", count); got != want {
|
|
||||||
t.Errorf("Grpc-Metadata-Count was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABELookup(t *testing.T) {
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything"
|
|
||||||
cresp, err := http.Post(url, "application/json", strings.NewReader(`
|
|
||||||
{"bool_value": true, "string_value": "strprefix/example"}
|
|
||||||
`))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer cresp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(cresp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(cresp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := cresp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var want gw.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &want); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &want) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
url = fmt.Sprintf("%s/%s", url, want.Uuid)
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Get(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
buf, err = ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg gw.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("msg= %v; want %v", &got, &want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Header.Get("Grpc-Metadata-Uuid"), want.Uuid; got != want {
|
|
||||||
t.Errorf("Grpc-Metadata-Uuid was %s, wanted %s", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABELookupNotFound(t *testing.T) {
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything"
|
|
||||||
uuid := "not_exist"
|
|
||||||
url = fmt.Sprintf("%s/%s", url, uuid)
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Get(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusNotFound; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg errorBody
|
|
||||||
if err := json.Unmarshal(buf, &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := msg.Code, int(codes.NotFound); got != want {
|
|
||||||
t.Errorf("msg.Code = %d; want %d", got, want)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := resp.Header.Get("Grpc-Metadata-Uuid"), uuid; got != want {
|
|
||||||
t.Errorf("Grpc-Metadata-Uuid was %s, wanted %s", got, want)
|
|
||||||
}
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {
|
|
||||||
t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEList(t *testing.T) {
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything"
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Get(%q) failed with %v; want success", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
|
||||||
var i int
|
|
||||||
for i = 0; ; i++ {
|
|
||||||
var item struct {
|
|
||||||
Result json.RawMessage `json:"result"`
|
|
||||||
Error map[string]interface{} `json:"error"`
|
|
||||||
}
|
|
||||||
err := dec.Decode(&item)
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("dec.Decode(&item) failed with %v; want success; i = %d", err, i)
|
|
||||||
}
|
|
||||||
if len(item.Error) != 0 {
|
|
||||||
t.Errorf("item.Error = %#v; want empty; i = %d", item.Error, i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var msg gw.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(item.Result), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", item.Result, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if i <= 0 {
|
|
||||||
t.Errorf("i == %d; want > 0", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
value := resp.Header.Get("Grpc-Metadata-Count")
|
|
||||||
if value == "" {
|
|
||||||
t.Errorf("Grpc-Metadata-Count should not be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err := strconv.Atoi(value)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("failed to Atoi %q: %v", value, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if count <= 0 {
|
|
||||||
t.Errorf("count == %d; want > 0", count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEBulkEcho(t *testing.T) {
|
|
||||||
reqr, reqw := io.Pipe()
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
var want []*sub.StringMessage
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
defer reqw.Close()
|
|
||||||
var m jsonpb.Marshaler
|
|
||||||
for i := 0; i < 1000; i++ {
|
|
||||||
msg := sub.StringMessage{Value: proto.String(fmt.Sprintf("message %d", i))}
|
|
||||||
buf, err := m.MarshalToString(&msg)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%v) failed with %v; want success", &msg, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := fmt.Fprintln(reqw, buf); err != nil {
|
|
||||||
t.Errorf("fmt.Fprintln(reqw, %q) failed with %v; want success", buf, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
want = append(want, &msg)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything/echo"
|
|
||||||
req, err := http.NewRequest("POST", url, reqr)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.NewRequest(%q, %q, reqr) failed with %v; want success", "POST", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("Transfer-Encoding", "chunked")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q, %q, req) failed with %v; want success", url, "application/json", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
var got []*sub.StringMessage
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
var item struct {
|
|
||||||
Result json.RawMessage `json:"result"`
|
|
||||||
Error map[string]interface{} `json:"error"`
|
|
||||||
}
|
|
||||||
err := dec.Decode(&item)
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("dec.Decode(&item) failed with %v; want success; i = %d", err, i)
|
|
||||||
}
|
|
||||||
if len(item.Error) != 0 {
|
|
||||||
t.Errorf("item.Error = %#v; want empty; i = %d", item.Error, i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var msg sub.StringMessage
|
|
||||||
if err := jsonpb.UnmarshalString(string(item.Result), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%q, &msg) failed with %v; want success", item.Result, err)
|
|
||||||
}
|
|
||||||
got = append(got, &msg)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want %v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testABEBulkEchoZeroLength(t *testing.T) {
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything/echo"
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewReader(nil))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.NewRequest(%q, %q, bytes.NewReader(nil)) failed with %v; want success", "POST", url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("Transfer-Encoding", "chunked")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q, %q, req) failed with %v; want success", url, "application/json", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
|
||||||
var item struct {
|
|
||||||
Result json.RawMessage `json:"result"`
|
|
||||||
Error map[string]interface{} `json:"error"`
|
|
||||||
}
|
|
||||||
if err := dec.Decode(&item); err == nil {
|
|
||||||
t.Errorf("dec.Decode(&item) succeeded; want io.EOF; item = %#v", item)
|
|
||||||
} else if err != io.EOF {
|
|
||||||
t.Errorf("dec.Decode(&item) failed with %v; want success", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAdditionalBindings(t *testing.T) {
|
|
||||||
for i, f := range []func() *http.Response{
|
|
||||||
func() *http.Response {
|
|
||||||
url := "http://localhost:8080/v1/example/a_bit_of_everything/echo/hello"
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Get(%q) failed with %v; want success", url, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return resp
|
|
||||||
},
|
|
||||||
func() *http.Response {
|
|
||||||
url := "http://localhost:8080/v2/example/echo"
|
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader(`"hello"`))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Post(%q, %q, %q) failed with %v; want success", url, "application/json", `"hello"`, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return resp
|
|
||||||
},
|
|
||||||
func() *http.Response {
|
|
||||||
url := "http://localhost:8080/v2/example/echo?value=hello"
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.Get(%q) failed with %v; want success", url, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return resp
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
resp := f()
|
|
||||||
if resp == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
defer resp.Body.Close()
|
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success; i=%d", err, i)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := resp.StatusCode, http.StatusOK; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d; i=%d", got, want, i)
|
|
||||||
t.Logf("%s", buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg sub.StringMessage
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success; %d", buf, err, i)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.GetValue(), "hello"; got != want {
|
|
||||||
t.Errorf("msg.GetValue() = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTimeout(t *testing.T) {
|
|
||||||
url := "http://localhost:8080/v2/example/timeout"
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(`http.NewRequest("GET", %q, nil) failed with %v; want success`, url, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
req.Header.Set("Grpc-Timeout", "10m")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("http.DefaultClient.Do(%#v) failed with %v; want success", req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if got, want := resp.StatusCode, http.StatusRequestTimeout; got != want {
|
|
||||||
t.Errorf("resp.StatusCode = %d; want %d", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
109
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/main.go
generated
vendored
109
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/main.go
generated
vendored
@ -1,109 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"net/http"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of EchoService")
|
|
||||||
abeEndpoint = flag.String("more_endpoint", "localhost:9090", "endpoint of ABitOfEverythingService")
|
|
||||||
flowEndpoint = flag.String("flow_endpoint", "localhost:9090", "endpoint of FlowCombination")
|
|
||||||
|
|
||||||
swaggerDir = flag.String("swagger_dir", "examples/examplepb", "path to the directory which contains swagger definitions")
|
|
||||||
)
|
|
||||||
|
|
||||||
// newGateway returns a new gateway server which translates HTTP into gRPC.
|
|
||||||
func newGateway(ctx context.Context, opts ...runtime.ServeMuxOption) (http.Handler, error) {
|
|
||||||
mux := runtime.NewServeMux(opts...)
|
|
||||||
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
|
|
||||||
err := examplepb.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, dialOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = examplepb.RegisterStreamServiceHandlerFromEndpoint(ctx, mux, *abeEndpoint, dialOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = examplepb.RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx, mux, *abeEndpoint, dialOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = examplepb.RegisterFlowCombinationHandlerFromEndpoint(ctx, mux, *flowEndpoint, dialOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return mux, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func serveSwagger(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if !strings.HasSuffix(r.URL.Path, ".swagger.json") {
|
|
||||||
glog.Errorf("Not Found: %s", r.URL.Path)
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.Infof("Serving %s", r.URL.Path)
|
|
||||||
p := strings.TrimPrefix(r.URL.Path, "/swagger/")
|
|
||||||
p = path.Join(*swaggerDir, p)
|
|
||||||
http.ServeFile(w, r, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// allowCORS allows Cross Origin Resoruce Sharing from any origin.
|
|
||||||
// Don't do this without consideration in production systems.
|
|
||||||
func allowCORS(h http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if origin := r.Header.Get("Origin"); origin != "" {
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
|
||||||
if r.Method == "OPTIONS" && r.Header.Get("Access-Control-Request-Method") != "" {
|
|
||||||
preflightHandler(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func preflightHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
headers := []string{"Content-Type", "Accept"}
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", strings.Join(headers, ","))
|
|
||||||
methods := []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
|
|
||||||
w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ","))
|
|
||||||
glog.Infof("preflight request for %s", r.URL.Path)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run starts a HTTP server and blocks forever if successful.
|
|
||||||
func Run(address string, opts ...runtime.ServeMuxOption) error {
|
|
||||||
ctx := context.Background()
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
mux.HandleFunc("/swagger/", serveSwagger)
|
|
||||||
|
|
||||||
gw, err := newGateway(ctx, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
mux.Handle("/", gw)
|
|
||||||
|
|
||||||
return http.ListenAndServe(address, allowCORS(mux))
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
if err := Run(":8080"); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
45
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/main_test.go
generated
vendored
45
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/main_test.go
generated
vendored
@ -1,45 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
server "github.com/grpc-ecosystem/grpc-gateway/examples/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
func runServers() <-chan error {
|
|
||||||
ch := make(chan error, 2)
|
|
||||||
go func() {
|
|
||||||
if err := server.Run(); err != nil {
|
|
||||||
ch <- fmt.Errorf("cannot run grpc service: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
if err := Run(":8080"); err != nil {
|
|
||||||
ch <- fmt.Errorf("cannot run gateway service: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return ch
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
flag.Parse()
|
|
||||||
errCh := runServers()
|
|
||||||
|
|
||||||
ch := make(chan int, 1)
|
|
||||||
go func() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
ch <- m.Run()
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case err := <-errCh:
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
os.Exit(1)
|
|
||||||
case status := <-ch:
|
|
||||||
os.Exit(status)
|
|
||||||
}
|
|
||||||
}
|
|
247
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/a_bit_of_everything.go
generated
vendored
247
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/a_bit_of_everything.go
generated
vendored
@ -1,247 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/ptypes/duration"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
examples "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub"
|
|
||||||
sub2 "github.com/grpc-ecosystem/grpc-gateway/examples/sub2"
|
|
||||||
"github.com/rogpeppe/fastuuid"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Implements of ABitOfEverythingServiceServer
|
|
||||||
|
|
||||||
var uuidgen = fastuuid.MustNewGenerator()
|
|
||||||
|
|
||||||
type _ABitOfEverythingServer struct {
|
|
||||||
v map[string]*examples.ABitOfEverything
|
|
||||||
m sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
type ABitOfEverythingServer interface {
|
|
||||||
examples.ABitOfEverythingServiceServer
|
|
||||||
examples.StreamServiceServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func newABitOfEverythingServer() ABitOfEverythingServer {
|
|
||||||
return &_ABitOfEverythingServer{
|
|
||||||
v: make(map[string]*examples.ABitOfEverything),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Create(ctx context.Context, msg *examples.ABitOfEverything) (*examples.ABitOfEverything, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
var uuid string
|
|
||||||
for {
|
|
||||||
uuid = fmt.Sprintf("%x", uuidgen.Next())
|
|
||||||
if _, ok := s.v[uuid]; !ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.v[uuid] = msg
|
|
||||||
s.v[uuid].Uuid = uuid
|
|
||||||
glog.Infof("%v", s.v[uuid])
|
|
||||||
return s.v[uuid], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) CreateBody(ctx context.Context, msg *examples.ABitOfEverything) (*examples.ABitOfEverything, error) {
|
|
||||||
return s.Create(ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) BulkCreate(stream examples.StreamService_BulkCreateServer) error {
|
|
||||||
count := 0
|
|
||||||
ctx := stream.Context()
|
|
||||||
for {
|
|
||||||
msg, err := stream.Recv()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
count++
|
|
||||||
glog.Error(msg)
|
|
||||||
if _, err = s.Create(ctx, msg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := stream.SendHeader(metadata.New(map[string]string{
|
|
||||||
"count": fmt.Sprintf("%d", count),
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.SetTrailer(metadata.New(map[string]string{
|
|
||||||
"foo": "foo2",
|
|
||||||
"bar": "bar2",
|
|
||||||
}))
|
|
||||||
return stream.SendAndClose(new(empty.Empty))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Lookup(ctx context.Context, msg *sub2.IdMessage) (*examples.ABitOfEverything, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
glog.Info(msg)
|
|
||||||
|
|
||||||
err := grpc.SendHeader(ctx, metadata.New(map[string]string{
|
|
||||||
"uuid": msg.Uuid,
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if a, ok := s.v[msg.Uuid]; ok {
|
|
||||||
return a, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
grpc.SetTrailer(ctx, metadata.New(map[string]string{
|
|
||||||
"foo": "foo2",
|
|
||||||
"bar": "bar2",
|
|
||||||
}))
|
|
||||||
return nil, grpc.Errorf(codes.NotFound, "not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) List(_ *empty.Empty, stream examples.StreamService_ListServer) error {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
err := stream.SendHeader(metadata.New(map[string]string{
|
|
||||||
"count": fmt.Sprintf("%d", len(s.v)),
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, msg := range s.v {
|
|
||||||
if err := stream.Send(msg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return error when metadata includes error header
|
|
||||||
if header, ok := metadata.FromContext(stream.Context()); ok {
|
|
||||||
if v, ok := header["error"]; ok {
|
|
||||||
stream.SetTrailer(metadata.New(map[string]string{
|
|
||||||
"foo": "foo2",
|
|
||||||
"bar": "bar2",
|
|
||||||
}))
|
|
||||||
return grpc.Errorf(codes.InvalidArgument, "error metadata: %v", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABitOfEverything) (*empty.Empty, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
if _, ok := s.v[msg.Uuid]; ok {
|
|
||||||
s.v[msg.Uuid] = msg
|
|
||||||
} else {
|
|
||||||
return nil, grpc.Errorf(codes.NotFound, "not found")
|
|
||||||
}
|
|
||||||
return new(empty.Empty), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessage) (*empty.Empty, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
if _, ok := s.v[msg.Uuid]; ok {
|
|
||||||
delete(s.v, msg.Uuid)
|
|
||||||
} else {
|
|
||||||
return nil, grpc.Errorf(codes.NotFound, "not found")
|
|
||||||
}
|
|
||||||
return new(empty.Empty), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) GetQuery(ctx context.Context, msg *examples.ABitOfEverything) (*empty.Empty, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
if _, ok := s.v[msg.Uuid]; ok {
|
|
||||||
s.v[msg.Uuid] = msg
|
|
||||||
} else {
|
|
||||||
return nil, grpc.Errorf(codes.NotFound, "not found")
|
|
||||||
}
|
|
||||||
return new(empty.Empty), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Echo(ctx context.Context, msg *sub.StringMessage) (*sub.StringMessage, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
return msg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) BulkEcho(stream examples.StreamService_BulkEchoServer) error {
|
|
||||||
var msgs []*sub.StringMessage
|
|
||||||
for {
|
|
||||||
msg, err := stream.Recv()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
msgs = append(msgs, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
hmd := metadata.New(map[string]string{
|
|
||||||
"foo": "foo1",
|
|
||||||
"bar": "bar1",
|
|
||||||
})
|
|
||||||
if err := stream.SendHeader(hmd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, msg := range msgs {
|
|
||||||
glog.Info(msg)
|
|
||||||
if err := stream.Send(msg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.SetTrailer(metadata.New(map[string]string{
|
|
||||||
"foo": "foo2",
|
|
||||||
"bar": "bar2",
|
|
||||||
}))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) DeepPathEcho(ctx context.Context, msg *examples.ABitOfEverything) (*examples.ABitOfEverything, error) {
|
|
||||||
s.m.Lock()
|
|
||||||
defer s.m.Unlock()
|
|
||||||
|
|
||||||
glog.Info(msg)
|
|
||||||
return msg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) NoBindings(ctx context.Context, msg *duration.Duration) (*empty.Empty, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *_ABitOfEverythingServer) Timeout(ctx context.Context, msg *empty.Empty) (*empty.Empty, error) {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil, ctx.Err()
|
|
||||||
}
|
|
||||||
}
|
|
17
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/cmd/example-server/main.go
generated
vendored
17
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/cmd/example-server/main.go
generated
vendored
@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
if err := server.Run(); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
35
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/echo.go
generated
vendored
35
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/echo.go
generated
vendored
@ -1,35 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/golang/glog"
|
|
||||||
examples "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Implements of EchoServiceServer
|
|
||||||
|
|
||||||
type echoServer struct{}
|
|
||||||
|
|
||||||
func newEchoServer() examples.EchoServiceServer {
|
|
||||||
return new(echoServer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *echoServer) Echo(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
|
|
||||||
glog.Info(msg)
|
|
||||||
return msg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *echoServer) EchoBody(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
|
|
||||||
glog.Info(msg)
|
|
||||||
grpc.SendHeader(ctx, metadata.New(map[string]string{
|
|
||||||
"foo": "foo1",
|
|
||||||
"bar": "bar1",
|
|
||||||
}))
|
|
||||||
grpc.SetTrailer(ctx, metadata.New(map[string]string{
|
|
||||||
"foo": "foo2",
|
|
||||||
"bar": "bar2",
|
|
||||||
}))
|
|
||||||
return msg, nil
|
|
||||||
}
|
|
72
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/flow_combination.go
generated
vendored
72
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/flow_combination.go
generated
vendored
@ -1,72 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
examples "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
type flowCombinationServer struct{}
|
|
||||||
|
|
||||||
func newFlowCombinationServer() examples.FlowCombinationServer {
|
|
||||||
return &flowCombinationServer{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcEmptyRpc(ctx context.Context, req *examples.EmptyProto) (*examples.EmptyProto, error) {
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcEmptyStream(req *examples.EmptyProto, stream examples.FlowCombination_RpcEmptyStreamServer) error {
|
|
||||||
return stream.Send(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) StreamEmptyRpc(stream examples.FlowCombination_StreamEmptyRpcServer) error {
|
|
||||||
for {
|
|
||||||
_, err := stream.Recv()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stream.SendAndClose(new(examples.EmptyProto))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) StreamEmptyStream(stream examples.FlowCombination_StreamEmptyStreamServer) error {
|
|
||||||
for {
|
|
||||||
_, err := stream.Recv()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stream.Send(new(examples.EmptyProto))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcBodyRpc(ctx context.Context, req *examples.NonEmptyProto) (*examples.EmptyProto, error) {
|
|
||||||
return new(examples.EmptyProto), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcPathSingleNestedRpc(ctx context.Context, req *examples.SingleNestedProto) (*examples.EmptyProto, error) {
|
|
||||||
return new(examples.EmptyProto), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcPathNestedRpc(ctx context.Context, req *examples.NestedProto) (*examples.EmptyProto, error) {
|
|
||||||
return new(examples.EmptyProto), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcBodyStream(req *examples.NonEmptyProto, stream examples.FlowCombination_RpcBodyStreamServer) error {
|
|
||||||
return stream.Send(new(examples.EmptyProto))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcPathSingleNestedStream(req *examples.SingleNestedProto, stream examples.FlowCombination_RpcPathSingleNestedStreamServer) error {
|
|
||||||
return stream.Send(new(examples.EmptyProto))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s flowCombinationServer) RpcPathNestedStream(req *examples.NestedProto, stream examples.FlowCombination_RpcPathNestedStreamServer) error {
|
|
||||||
return stream.Send(new(examples.EmptyProto))
|
|
||||||
}
|
|
25
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/main.go
generated
vendored
25
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/server/main.go
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
|
|
||||||
examples "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Run() error {
|
|
||||||
l, err := net.Listen("tcp", ":9090")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s := grpc.NewServer()
|
|
||||||
examples.RegisterEchoServiceServer(s, newEchoServer())
|
|
||||||
examples.RegisterFlowCombinationServer(s, newFlowCombinationServer())
|
|
||||||
|
|
||||||
abe := newABitOfEverythingServer()
|
|
||||||
examples.RegisterABitOfEverythingServiceServer(s, abe)
|
|
||||||
examples.RegisterStreamServiceServer(s, abe)
|
|
||||||
|
|
||||||
s.Serve(l)
|
|
||||||
return nil
|
|
||||||
}
|
|
63
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub/message.pb.go
generated
vendored
63
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub/message.pb.go
generated
vendored
@ -1,63 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/sub/message.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package sub is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
examples/sub/message.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
StringMessage
|
|
||||||
*/
|
|
||||||
package sub
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type StringMessage struct {
|
|
||||||
Value *string `protobuf:"bytes,1,req,name=value" json:"value,omitempty"`
|
|
||||||
XXX_unrecognized []byte `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *StringMessage) Reset() { *m = StringMessage{} }
|
|
||||||
func (m *StringMessage) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*StringMessage) ProtoMessage() {}
|
|
||||||
func (*StringMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *StringMessage) GetValue() string {
|
|
||||||
if m != nil && m.Value != nil {
|
|
||||||
return *m.Value
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*StringMessage)(nil), "grpc.gateway.examples.sub.StringMessage")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/sub/message.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 111 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4a, 0xad, 0x48, 0xcc,
|
|
||||||
0x2d, 0xc8, 0x49, 0x2d, 0xd6, 0x2f, 0x2e, 0x4d, 0xd2, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f,
|
|
||||||
0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4c, 0x2f, 0x2a, 0x48, 0xd6, 0x4b, 0x4f, 0x2c,
|
|
||||||
0x49, 0x2d, 0x4f, 0xac, 0xd4, 0x83, 0x29, 0xd4, 0x2b, 0x2e, 0x4d, 0x52, 0x52, 0xe5, 0xe2, 0x0d,
|
|
||||||
0x2e, 0x29, 0xca, 0xcc, 0x4b, 0xf7, 0x85, 0xe8, 0x10, 0x12, 0xe1, 0x62, 0x2d, 0x4b, 0xcc, 0x29,
|
|
||||||
0x4d, 0x95, 0x60, 0x54, 0x60, 0xd2, 0xe0, 0x0c, 0x82, 0x70, 0x9c, 0x58, 0xa3, 0x98, 0x8b, 0x4b,
|
|
||||||
0x93, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x10, 0x60, 0xa9, 0x65, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
7
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub/message.proto
generated
vendored
7
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub/message.proto
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
syntax = "proto2";
|
|
||||||
option go_package = "sub";
|
|
||||||
package grpc.gateway.examples.sub;
|
|
||||||
|
|
||||||
message StringMessage {
|
|
||||||
required string value = 1;
|
|
||||||
}
|
|
63
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub2/message.pb.go
generated
vendored
63
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub2/message.pb.go
generated
vendored
@ -1,63 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: examples/sub2/message.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package sub2 is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
examples/sub2/message.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
IdMessage
|
|
||||||
*/
|
|
||||||
package sub2
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type IdMessage struct {
|
|
||||||
Uuid string `protobuf:"bytes,1,opt,name=uuid" json:"uuid,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *IdMessage) Reset() { *m = IdMessage{} }
|
|
||||||
func (m *IdMessage) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*IdMessage) ProtoMessage() {}
|
|
||||||
func (*IdMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *IdMessage) GetUuid() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Uuid
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*IdMessage)(nil), "sub2.IdMessage")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("examples/sub2/message.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 128 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0xad, 0x48, 0xcc,
|
|
||||||
0x2d, 0xc8, 0x49, 0x2d, 0xd6, 0x2f, 0x2e, 0x4d, 0x32, 0xd2, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c,
|
|
||||||
0x4f, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x01, 0x89, 0x29, 0xc9, 0x73, 0x71, 0x7a,
|
|
||||||
0xa6, 0xf8, 0x42, 0x24, 0x84, 0x84, 0xb8, 0x58, 0x4a, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18,
|
|
||||||
0x35, 0x38, 0x83, 0xc0, 0x6c, 0x27, 0xb3, 0x28, 0x93, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd,
|
|
||||||
0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xa2, 0x82, 0x64, 0xdd, 0xd4, 0xe4, 0xfc, 0xe2, 0xca, 0xe2, 0x92,
|
|
||||||
0x54, 0x28, 0x37, 0x3d, 0xb1, 0x24, 0xb5, 0x3c, 0xb1, 0x52, 0x1f, 0xc5, 0xb2, 0x24, 0x36, 0xb0,
|
|
||||||
0x2d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x53, 0x75, 0xef, 0xe0, 0x84, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
7
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub2/message.proto
generated
vendored
7
vendor/github.com/grpc-ecosystem/grpc-gateway/examples/sub2/message.proto
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option go_package = "github.com/grpc-ecosystem/grpc-gateway/examples/sub2";
|
|
||||||
package sub2;
|
|
||||||
|
|
||||||
message IdMessage {
|
|
||||||
string uuid = 1;
|
|
||||||
}
|
|
27
vendor/github.com/grpc-ecosystem/grpc-gateway/options/options.proto
generated
vendored
27
vendor/github.com/grpc-ecosystem/grpc-gateway/options/options.proto
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
syntax = "proto2";
|
|
||||||
option go_package = "options";
|
|
||||||
|
|
||||||
package gengo.grpc.gateway;
|
|
||||||
import "google/protobuf/descriptor.proto";
|
|
||||||
|
|
||||||
message ApiMethodOptions {
|
|
||||||
// Use HttpRule instead.
|
|
||||||
option deprecated = true;
|
|
||||||
|
|
||||||
extend google.protobuf.MethodOptions {
|
|
||||||
// Describes how the gRPC method should be exported as a RESTful API.
|
|
||||||
//
|
|
||||||
// The id is a globally unique id for this option, assigned by
|
|
||||||
// protobuf-global-extension-registry@google.com.
|
|
||||||
optional ApiMethodOptions api_options = 1022;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Path of the RESTful API method.
|
|
||||||
// Path components which start with colon is mapped to the corresponding fields in the request message.
|
|
||||||
required string path = 1;
|
|
||||||
// HTTP method of the RESTful API method
|
|
||||||
required string method = 2;
|
|
||||||
// Human-readable description of the method.
|
|
||||||
optional string description = 3;
|
|
||||||
}
|
|
||||||
|
|
299
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go
generated
vendored
299
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go
generated
vendored
@ -1,299 +0,0 @@
|
|||||||
package descriptor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Registry is a registry of information extracted from plugin.CodeGeneratorRequest.
|
|
||||||
type Registry struct {
|
|
||||||
// msgs is a mapping from fully-qualified message name to descriptor
|
|
||||||
msgs map[string]*Message
|
|
||||||
|
|
||||||
// enums is a mapping from fully-qualified enum name to descriptor
|
|
||||||
enums map[string]*Enum
|
|
||||||
|
|
||||||
// files is a mapping from file path to descriptor
|
|
||||||
files map[string]*File
|
|
||||||
|
|
||||||
// prefix is a prefix to be inserted to golang package paths generated from proto package names.
|
|
||||||
prefix string
|
|
||||||
|
|
||||||
// pkgMap is a user-specified mapping from file path to proto package.
|
|
||||||
pkgMap map[string]string
|
|
||||||
|
|
||||||
// pkgAliases is a mapping from package aliases to package paths in go which are already taken.
|
|
||||||
pkgAliases map[string]string
|
|
||||||
|
|
||||||
// allowDeleteBody permits http delete methods to have a body
|
|
||||||
allowDeleteBody bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRegistry returns a new Registry.
|
|
||||||
func NewRegistry() *Registry {
|
|
||||||
return &Registry{
|
|
||||||
msgs: make(map[string]*Message),
|
|
||||||
enums: make(map[string]*Enum),
|
|
||||||
files: make(map[string]*File),
|
|
||||||
pkgMap: make(map[string]string),
|
|
||||||
pkgAliases: make(map[string]string),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load loads definitions of services, methods, messages, enumerations and fields from "req".
|
|
||||||
func (r *Registry) Load(req *plugin.CodeGeneratorRequest) error {
|
|
||||||
for _, file := range req.GetProtoFile() {
|
|
||||||
r.loadFile(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
var targetPkg string
|
|
||||||
for _, name := range req.FileToGenerate {
|
|
||||||
target := r.files[name]
|
|
||||||
if target == nil {
|
|
||||||
return fmt.Errorf("no such file: %s", name)
|
|
||||||
}
|
|
||||||
name := packageIdentityName(target.FileDescriptorProto)
|
|
||||||
if targetPkg == "" {
|
|
||||||
targetPkg = name
|
|
||||||
} else {
|
|
||||||
if targetPkg != name {
|
|
||||||
return fmt.Errorf("inconsistent package names: %s %s", targetPkg, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.loadServices(target); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadFile loads messages, enumerations and fields from "file".
|
|
||||||
// It does not loads services and methods in "file". You need to call
|
|
||||||
// loadServices after loadFiles is called for all files to load services and methods.
|
|
||||||
func (r *Registry) loadFile(file *descriptor.FileDescriptorProto) {
|
|
||||||
pkg := GoPackage{
|
|
||||||
Path: r.goPackagePath(file),
|
|
||||||
Name: defaultGoPackageName(file),
|
|
||||||
}
|
|
||||||
if err := r.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
alias := fmt.Sprintf("%s_%d", pkg.Name, i)
|
|
||||||
if err := r.ReserveGoPackageAlias(alias, pkg.Path); err == nil {
|
|
||||||
pkg.Alias = alias
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f := &File{
|
|
||||||
FileDescriptorProto: file,
|
|
||||||
GoPkg: pkg,
|
|
||||||
}
|
|
||||||
|
|
||||||
r.files[file.GetName()] = f
|
|
||||||
r.registerMsg(f, nil, file.GetMessageType())
|
|
||||||
r.registerEnum(f, nil, file.GetEnumType())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Registry) registerMsg(file *File, outerPath []string, msgs []*descriptor.DescriptorProto) {
|
|
||||||
for i, md := range msgs {
|
|
||||||
m := &Message{
|
|
||||||
File: file,
|
|
||||||
Outers: outerPath,
|
|
||||||
DescriptorProto: md,
|
|
||||||
Index: i,
|
|
||||||
}
|
|
||||||
for _, fd := range md.GetField() {
|
|
||||||
m.Fields = append(m.Fields, &Field{
|
|
||||||
Message: m,
|
|
||||||
FieldDescriptorProto: fd,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
file.Messages = append(file.Messages, m)
|
|
||||||
r.msgs[m.FQMN()] = m
|
|
||||||
glog.V(1).Infof("register name: %s", m.FQMN())
|
|
||||||
|
|
||||||
var outers []string
|
|
||||||
outers = append(outers, outerPath...)
|
|
||||||
outers = append(outers, m.GetName())
|
|
||||||
r.registerMsg(file, outers, m.GetNestedType())
|
|
||||||
r.registerEnum(file, outers, m.GetEnumType())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Registry) registerEnum(file *File, outerPath []string, enums []*descriptor.EnumDescriptorProto) {
|
|
||||||
for i, ed := range enums {
|
|
||||||
e := &Enum{
|
|
||||||
File: file,
|
|
||||||
Outers: outerPath,
|
|
||||||
EnumDescriptorProto: ed,
|
|
||||||
Index: i,
|
|
||||||
}
|
|
||||||
file.Enums = append(file.Enums, e)
|
|
||||||
r.enums[e.FQEN()] = e
|
|
||||||
glog.V(1).Infof("register enum name: %s", e.FQEN())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookupMsg looks up a message type by "name".
|
|
||||||
// It tries to resolve "name" from "location" if "name" is a relative message name.
|
|
||||||
func (r *Registry) LookupMsg(location, name string) (*Message, error) {
|
|
||||||
glog.V(1).Infof("lookup %s from %s", name, location)
|
|
||||||
if strings.HasPrefix(name, ".") {
|
|
||||||
m, ok := r.msgs[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("no message found: %s", name)
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(location, ".") {
|
|
||||||
location = fmt.Sprintf(".%s", location)
|
|
||||||
}
|
|
||||||
components := strings.Split(location, ".")
|
|
||||||
for len(components) > 0 {
|
|
||||||
fqmn := strings.Join(append(components, name), ".")
|
|
||||||
if m, ok := r.msgs[fqmn]; ok {
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
components = components[:len(components)-1]
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("no message found: %s", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookupEnum looks up a enum type by "name".
|
|
||||||
// It tries to resolve "name" from "location" if "name" is a relative enum name.
|
|
||||||
func (r *Registry) LookupEnum(location, name string) (*Enum, error) {
|
|
||||||
glog.V(1).Infof("lookup enum %s from %s", name, location)
|
|
||||||
if strings.HasPrefix(name, ".") {
|
|
||||||
e, ok := r.enums[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("no enum found: %s", name)
|
|
||||||
}
|
|
||||||
return e, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(location, ".") {
|
|
||||||
location = fmt.Sprintf(".%s", location)
|
|
||||||
}
|
|
||||||
components := strings.Split(location, ".")
|
|
||||||
for len(components) > 0 {
|
|
||||||
fqen := strings.Join(append(components, name), ".")
|
|
||||||
if e, ok := r.enums[fqen]; ok {
|
|
||||||
return e, nil
|
|
||||||
}
|
|
||||||
components = components[:len(components)-1]
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("no enum found: %s", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookupFile looks up a file by name.
|
|
||||||
func (r *Registry) LookupFile(name string) (*File, error) {
|
|
||||||
f, ok := r.files[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("no such file given: %s", name)
|
|
||||||
}
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddPkgMap adds a mapping from a .proto file to proto package name.
|
|
||||||
func (r *Registry) AddPkgMap(file, protoPkg string) {
|
|
||||||
r.pkgMap[file] = protoPkg
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPrefix registeres the perfix to be added to go package paths generated from proto package names.
|
|
||||||
func (r *Registry) SetPrefix(prefix string) {
|
|
||||||
r.prefix = prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReserveGoPackageAlias reserves the unique alias of go package.
|
|
||||||
// If succeeded, the alias will be never used for other packages in generated go files.
|
|
||||||
// If failed, the alias is already taken by another package, so you need to use another
|
|
||||||
// alias for the package in your go files.
|
|
||||||
func (r *Registry) ReserveGoPackageAlias(alias, pkgpath string) error {
|
|
||||||
if taken, ok := r.pkgAliases[alias]; ok {
|
|
||||||
if taken == pkgpath {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("package name %s is already taken. Use another alias", alias)
|
|
||||||
}
|
|
||||||
r.pkgAliases[alias] = pkgpath
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// goPackagePath returns the go package path which go files generated from "f" should have.
|
|
||||||
// It respects the mapping registered by AddPkgMap if exists. Or use go_package as import path
|
|
||||||
// if it includes a slash, Otherwide, it generates a path from the file name of "f".
|
|
||||||
func (r *Registry) goPackagePath(f *descriptor.FileDescriptorProto) string {
|
|
||||||
name := f.GetName()
|
|
||||||
if pkg, ok := r.pkgMap[name]; ok {
|
|
||||||
return path.Join(r.prefix, pkg)
|
|
||||||
}
|
|
||||||
|
|
||||||
gopkg := f.Options.GetGoPackage()
|
|
||||||
idx := strings.LastIndex(gopkg, "/")
|
|
||||||
if idx >= 0 {
|
|
||||||
return gopkg
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.Join(r.prefix, path.Dir(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAllFQMNs returns a list of all FQMNs
|
|
||||||
func (r *Registry) GetAllFQMNs() []string {
|
|
||||||
var keys []string
|
|
||||||
for k := range r.msgs {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAllFQENs returns a list of all FQENs
|
|
||||||
func (r *Registry) GetAllFQENs() []string {
|
|
||||||
var keys []string
|
|
||||||
for k := range r.enums {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAllowDeleteBody controls whether http delete methods may have a
|
|
||||||
// body or fail loading if encountered.
|
|
||||||
func (r *Registry) SetAllowDeleteBody(allow bool) {
|
|
||||||
r.allowDeleteBody = allow
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaultGoPackageName returns the default go package name to be used for go files generated from "f".
|
|
||||||
// You might need to use an unique alias for the package when you import it. Use ReserveGoPackageAlias to get a unique alias.
|
|
||||||
func defaultGoPackageName(f *descriptor.FileDescriptorProto) string {
|
|
||||||
name := packageIdentityName(f)
|
|
||||||
return strings.Replace(name, ".", "_", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// packageIdentityName returns the identity of packages.
|
|
||||||
// protoc-gen-grpc-gateway rejects CodeGenerationRequests which contains more than one packages
|
|
||||||
// as protoc-gen-go does.
|
|
||||||
func packageIdentityName(f *descriptor.FileDescriptorProto) string {
|
|
||||||
if f.Options != nil && f.Options.GoPackage != nil {
|
|
||||||
gopkg := f.Options.GetGoPackage()
|
|
||||||
idx := strings.LastIndex(gopkg, "/")
|
|
||||||
if idx < 0 {
|
|
||||||
return gopkg
|
|
||||||
}
|
|
||||||
|
|
||||||
return gopkg[idx+1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.Package == nil {
|
|
||||||
base := filepath.Base(f.GetName())
|
|
||||||
ext := filepath.Ext(base)
|
|
||||||
return strings.TrimSuffix(base, ext)
|
|
||||||
}
|
|
||||||
return f.GetPackage()
|
|
||||||
}
|
|
@ -1,533 +0,0 @@
|
|||||||
package descriptor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func loadFile(t *testing.T, reg *Registry, src string) *descriptor.FileDescriptorProto {
|
|
||||||
var file descriptor.FileDescriptorProto
|
|
||||||
if err := proto.UnmarshalText(src, &file); err != nil {
|
|
||||||
t.Fatalf("proto.UnmarshalText(%s, &file) failed with %v; want success", src, err)
|
|
||||||
}
|
|
||||||
reg.loadFile(&file)
|
|
||||||
return &file
|
|
||||||
}
|
|
||||||
|
|
||||||
func load(t *testing.T, reg *Registry, src string) error {
|
|
||||||
var req plugin.CodeGeneratorRequest
|
|
||||||
if err := proto.UnmarshalText(src, &req); err != nil {
|
|
||||||
t.Fatalf("proto.UnmarshalText(%s, &file) failed with %v; want success", src, err)
|
|
||||||
}
|
|
||||||
return reg.Load(&req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFile(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
fd := loadFile(t, reg, `
|
|
||||||
name: 'example.proto'
|
|
||||||
package: 'example'
|
|
||||||
message_type <
|
|
||||||
name: 'ExampleMessage'
|
|
||||||
field <
|
|
||||||
name: 'str'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_STRING
|
|
||||||
number: 1
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: ".", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := reg.LookupMsg("", ".example.ExampleMessage")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", "", ".example.ExampleMessage", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want {
|
|
||||||
t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", "", ".example.ExampleMessage", got, want)
|
|
||||||
}
|
|
||||||
if got, want := msg.File, file; got != want {
|
|
||||||
t.Errorf("msg.File = %v; want %v", got, want)
|
|
||||||
}
|
|
||||||
if got := msg.Outers; got != nil {
|
|
||||||
t.Errorf("msg.Outers = %v; want %v", got, nil)
|
|
||||||
}
|
|
||||||
if got, want := len(msg.Fields), 1; got != want {
|
|
||||||
t.Errorf("len(msg.Fields) = %d; want %d", got, want)
|
|
||||||
} else if got, want := msg.Fields[0].FieldDescriptorProto, fd.MessageType[0].Field[0]; got != want {
|
|
||||||
t.Errorf("msg.Fields[0].FieldDescriptorProto = %v; want %v", got, want)
|
|
||||||
} else if got, want := msg.Fields[0].Message, msg; got != want {
|
|
||||||
t.Errorf("msg.Fields[0].Message = %v; want %v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := len(file.Messages), 1; got != want {
|
|
||||||
t.Errorf("file.Meeesages = %#v; want %#v", file.Messages, []*Message{msg})
|
|
||||||
}
|
|
||||||
if got, want := file.Messages[0], msg; got != want {
|
|
||||||
t.Errorf("file.Meeesages[0] = %v; want %v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileNestedPackage(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'example.proto'
|
|
||||||
package: 'example.nested.nested2'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: ".", Name: "example_nested_nested2"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithDir(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "path/to", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithoutPackage(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example_file.proto'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/example_file.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "path/to", Name: "example_file"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithMapping(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
reg.AddPkgMap("path/to/example.proto", "example.com/proj/example/proto")
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "example.com/proj/example/proto", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithPackageNameCollision(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/another.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
if err := reg.ReserveGoPackageAlias("ioutil", "io/ioutil"); err != nil {
|
|
||||||
t.Fatalf("reg.ReserveGoPackageAlias(%q) failed with %v; want success", "ioutil", err)
|
|
||||||
}
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/ioutil.proto'
|
|
||||||
package: 'ioutil'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/another.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "path/to/another.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "path/to", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
file = reg.files["path/to/example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "path/to/example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg = GoPackage{Path: "path/to", Name: "example", Alias: ""}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
file = reg.files["path/to/ioutil.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "path/to/ioutil.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg = GoPackage{Path: "path/to", Name: "ioutil", Alias: "ioutil_0"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithIdenticalGoPkg(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
reg.AddPkgMap("path/to/another.proto", "example.com/example")
|
|
||||||
reg.AddPkgMap("path/to/example.proto", "example.com/example")
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/another.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "example.com/example", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
file = reg.files["path/to/another.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg = GoPackage{Path: "example.com/example", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileWithPrefix(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
reg.SetPrefix("third_party")
|
|
||||||
loadFile(t, reg, `
|
|
||||||
name: 'path/to/example.proto'
|
|
||||||
package: 'example'
|
|
||||||
`)
|
|
||||||
|
|
||||||
file := reg.files["path/to/example.proto"]
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wantPkg := GoPackage{Path: "third_party/path/to", Name: "example"}
|
|
||||||
if got, want := file.GoPkg, wantPkg; got != want {
|
|
||||||
t.Errorf("file.GoPkg = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLookupMsgWithoutPackage(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
fd := loadFile(t, reg, `
|
|
||||||
name: 'example.proto'
|
|
||||||
message_type <
|
|
||||||
name: 'ExampleMessage'
|
|
||||||
field <
|
|
||||||
name: 'str'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_STRING
|
|
||||||
number: 1
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`)
|
|
||||||
|
|
||||||
msg, err := reg.LookupMsg("", ".ExampleMessage")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", "", ".ExampleMessage", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want {
|
|
||||||
t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", "", ".ExampleMessage", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLookupMsgWithNestedPackage(t *testing.T) {
|
|
||||||
reg := NewRegistry()
|
|
||||||
fd := loadFile(t, reg, `
|
|
||||||
name: 'example.proto'
|
|
||||||
package: 'nested.nested2.mypackage'
|
|
||||||
message_type <
|
|
||||||
name: 'ExampleMessage'
|
|
||||||
field <
|
|
||||||
name: 'str'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_STRING
|
|
||||||
number: 1
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`)
|
|
||||||
|
|
||||||
for _, name := range []string{
|
|
||||||
"nested.nested2.mypackage.ExampleMessage",
|
|
||||||
"nested2.mypackage.ExampleMessage",
|
|
||||||
"mypackage.ExampleMessage",
|
|
||||||
"ExampleMessage",
|
|
||||||
} {
|
|
||||||
msg, err := reg.LookupMsg("nested.nested2.mypackage", name)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", ".nested.nested2.mypackage", name, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want {
|
|
||||||
t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", ".nested.nested2.mypackage", name, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, loc := range []string{
|
|
||||||
".nested.nested2.mypackage",
|
|
||||||
"nested.nested2.mypackage",
|
|
||||||
".nested.nested2",
|
|
||||||
"nested.nested2",
|
|
||||||
".nested",
|
|
||||||
"nested",
|
|
||||||
".",
|
|
||||||
"",
|
|
||||||
"somewhere.else",
|
|
||||||
} {
|
|
||||||
name := "nested.nested2.mypackage.ExampleMessage"
|
|
||||||
msg, err := reg.LookupMsg(loc, name)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", loc, name, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want {
|
|
||||||
t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", loc, name, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, loc := range []string{
|
|
||||||
".nested.nested2.mypackage",
|
|
||||||
"nested.nested2.mypackage",
|
|
||||||
".nested.nested2",
|
|
||||||
"nested.nested2",
|
|
||||||
".nested",
|
|
||||||
"nested",
|
|
||||||
} {
|
|
||||||
name := "nested2.mypackage.ExampleMessage"
|
|
||||||
msg, err := reg.LookupMsg(loc, name)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", loc, name, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want {
|
|
||||||
t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", loc, name, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadWithInconsistentTargetPackage(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
req string
|
|
||||||
consistent bool
|
|
||||||
}{
|
|
||||||
// root package, no explicit go package
|
|
||||||
{
|
|
||||||
req: `
|
|
||||||
file_to_generate: 'a.proto'
|
|
||||||
file_to_generate: 'b.proto'
|
|
||||||
proto_file <
|
|
||||||
name: 'a.proto'
|
|
||||||
message_type < name: 'A' >
|
|
||||||
service <
|
|
||||||
name: "AService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "A"
|
|
||||||
output_type: "A"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/a" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
proto_file <
|
|
||||||
name: 'b.proto'
|
|
||||||
message_type < name: 'B' >
|
|
||||||
service <
|
|
||||||
name: "BService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "B"
|
|
||||||
output_type: "B"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/b" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`,
|
|
||||||
consistent: false,
|
|
||||||
},
|
|
||||||
// named package, no explicit go package
|
|
||||||
{
|
|
||||||
req: `
|
|
||||||
file_to_generate: 'a.proto'
|
|
||||||
file_to_generate: 'b.proto'
|
|
||||||
proto_file <
|
|
||||||
name: 'a.proto'
|
|
||||||
package: 'example.foo'
|
|
||||||
message_type < name: 'A' >
|
|
||||||
service <
|
|
||||||
name: "AService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "A"
|
|
||||||
output_type: "A"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/a" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
proto_file <
|
|
||||||
name: 'b.proto'
|
|
||||||
package: 'example.foo'
|
|
||||||
message_type < name: 'B' >
|
|
||||||
service <
|
|
||||||
name: "BService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "B"
|
|
||||||
output_type: "B"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/b" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`,
|
|
||||||
consistent: true,
|
|
||||||
},
|
|
||||||
// root package, explicit go package
|
|
||||||
{
|
|
||||||
req: `
|
|
||||||
file_to_generate: 'a.proto'
|
|
||||||
file_to_generate: 'b.proto'
|
|
||||||
proto_file <
|
|
||||||
name: 'a.proto'
|
|
||||||
options < go_package: 'foo' >
|
|
||||||
message_type < name: 'A' >
|
|
||||||
service <
|
|
||||||
name: "AService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "A"
|
|
||||||
output_type: "A"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/a" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
proto_file <
|
|
||||||
name: 'b.proto'
|
|
||||||
options < go_package: 'foo' >
|
|
||||||
message_type < name: 'B' >
|
|
||||||
service <
|
|
||||||
name: "BService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "B"
|
|
||||||
output_type: "B"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/b" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`,
|
|
||||||
consistent: true,
|
|
||||||
},
|
|
||||||
// named package, explicit go package
|
|
||||||
{
|
|
||||||
req: `
|
|
||||||
file_to_generate: 'a.proto'
|
|
||||||
file_to_generate: 'b.proto'
|
|
||||||
proto_file <
|
|
||||||
name: 'a.proto'
|
|
||||||
package: 'example.foo'
|
|
||||||
options < go_package: 'foo' >
|
|
||||||
message_type < name: 'A' >
|
|
||||||
service <
|
|
||||||
name: "AService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "A"
|
|
||||||
output_type: "A"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/a" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
proto_file <
|
|
||||||
name: 'b.proto'
|
|
||||||
package: 'example.foo'
|
|
||||||
options < go_package: 'foo' >
|
|
||||||
message_type < name: 'B' >
|
|
||||||
service <
|
|
||||||
name: "BService"
|
|
||||||
method <
|
|
||||||
name: "Meth"
|
|
||||||
input_type: "B"
|
|
||||||
output_type: "B"
|
|
||||||
options <
|
|
||||||
[google.api.http] < post: "/v1/b" body: "*" >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
`,
|
|
||||||
consistent: true,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
reg := NewRegistry()
|
|
||||||
err := load(t, reg, spec.req)
|
|
||||||
if got, want := err == nil, spec.consistent; got != want {
|
|
||||||
if want {
|
|
||||||
t.Errorf("reg.Load(%s) failed with %v; want success", spec.req, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t.Errorf("reg.Load(%s) succeeded; want an package inconsistency error", spec.req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
266
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go
generated
vendored
266
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go
generated
vendored
@ -1,266 +0,0 @@
|
|||||||
package descriptor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule"
|
|
||||||
options "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
)
|
|
||||||
|
|
||||||
// loadServices registers services and their methods from "targetFile" to "r".
|
|
||||||
// It must be called after loadFile is called for all files so that loadServices
|
|
||||||
// can resolve names of message types and their fields.
|
|
||||||
func (r *Registry) loadServices(file *File) error {
|
|
||||||
glog.V(1).Infof("Loading services from %s", file.GetName())
|
|
||||||
var svcs []*Service
|
|
||||||
for _, sd := range file.GetService() {
|
|
||||||
glog.V(2).Infof("Registering %s", sd.GetName())
|
|
||||||
svc := &Service{
|
|
||||||
File: file,
|
|
||||||
ServiceDescriptorProto: sd,
|
|
||||||
}
|
|
||||||
for _, md := range sd.GetMethod() {
|
|
||||||
glog.V(2).Infof("Processing %s.%s", sd.GetName(), md.GetName())
|
|
||||||
opts, err := extractAPIOptions(md)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to extract ApiMethodOptions from %s.%s: %v", svc.GetName(), md.GetName(), err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if opts == nil {
|
|
||||||
glog.V(1).Infof("Found non-target method: %s.%s", svc.GetName(), md.GetName())
|
|
||||||
}
|
|
||||||
meth, err := r.newMethod(svc, md, opts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
svc.Methods = append(svc.Methods, meth)
|
|
||||||
}
|
|
||||||
if len(svc.Methods) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
glog.V(2).Infof("Registered %s with %d method(s)", svc.GetName(), len(svc.Methods))
|
|
||||||
svcs = append(svcs, svc)
|
|
||||||
}
|
|
||||||
file.Services = svcs
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Registry) newMethod(svc *Service, md *descriptor.MethodDescriptorProto, opts *options.HttpRule) (*Method, error) {
|
|
||||||
requestType, err := r.LookupMsg(svc.File.GetPackage(), md.GetInputType())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
responseType, err := r.LookupMsg(svc.File.GetPackage(), md.GetOutputType())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
meth := &Method{
|
|
||||||
Service: svc,
|
|
||||||
MethodDescriptorProto: md,
|
|
||||||
RequestType: requestType,
|
|
||||||
ResponseType: responseType,
|
|
||||||
}
|
|
||||||
|
|
||||||
newBinding := func(opts *options.HttpRule, idx int) (*Binding, error) {
|
|
||||||
var (
|
|
||||||
httpMethod string
|
|
||||||
pathTemplate string
|
|
||||||
)
|
|
||||||
switch {
|
|
||||||
case opts.GetGet() != "":
|
|
||||||
httpMethod = "GET"
|
|
||||||
pathTemplate = opts.GetGet()
|
|
||||||
if opts.Body != "" {
|
|
||||||
return nil, fmt.Errorf("needs request body even though http method is GET: %s", md.GetName())
|
|
||||||
}
|
|
||||||
|
|
||||||
case opts.GetPut() != "":
|
|
||||||
httpMethod = "PUT"
|
|
||||||
pathTemplate = opts.GetPut()
|
|
||||||
|
|
||||||
case opts.GetPost() != "":
|
|
||||||
httpMethod = "POST"
|
|
||||||
pathTemplate = opts.GetPost()
|
|
||||||
|
|
||||||
case opts.GetDelete() != "":
|
|
||||||
httpMethod = "DELETE"
|
|
||||||
pathTemplate = opts.GetDelete()
|
|
||||||
if opts.Body != "" && !r.allowDeleteBody {
|
|
||||||
return nil, fmt.Errorf("needs request body even though http method is DELETE: %s", md.GetName())
|
|
||||||
}
|
|
||||||
|
|
||||||
case opts.GetPatch() != "":
|
|
||||||
httpMethod = "PATCH"
|
|
||||||
pathTemplate = opts.GetPatch()
|
|
||||||
|
|
||||||
case opts.GetCustom() != nil:
|
|
||||||
custom := opts.GetCustom()
|
|
||||||
httpMethod = custom.Kind
|
|
||||||
pathTemplate = custom.Path
|
|
||||||
|
|
||||||
default:
|
|
||||||
glog.V(1).Infof("No pattern specified in google.api.HttpRule: %s", md.GetName())
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed, err := httprule.Parse(pathTemplate)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
tmpl := parsed.Compile()
|
|
||||||
|
|
||||||
if md.GetClientStreaming() && len(tmpl.Fields) > 0 {
|
|
||||||
return nil, fmt.Errorf("cannot use path parameter in client streaming")
|
|
||||||
}
|
|
||||||
|
|
||||||
b := &Binding{
|
|
||||||
Method: meth,
|
|
||||||
Index: idx,
|
|
||||||
PathTmpl: tmpl,
|
|
||||||
HTTPMethod: httpMethod,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, f := range tmpl.Fields {
|
|
||||||
param, err := r.newParam(meth, f)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b.PathParams = append(b.PathParams, param)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(yugui) Handle query params
|
|
||||||
|
|
||||||
b.Body, err = r.newBody(meth, opts.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
b, err := newBinding(opts, 0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if b != nil {
|
|
||||||
meth.Bindings = append(meth.Bindings, b)
|
|
||||||
}
|
|
||||||
for i, additional := range opts.GetAdditionalBindings() {
|
|
||||||
if len(additional.AdditionalBindings) > 0 {
|
|
||||||
return nil, fmt.Errorf("additional_binding in additional_binding not allowed: %s.%s", svc.GetName(), meth.GetName())
|
|
||||||
}
|
|
||||||
b, err := newBinding(additional, i+1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
meth.Bindings = append(meth.Bindings, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
return meth, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func extractAPIOptions(meth *descriptor.MethodDescriptorProto) (*options.HttpRule, error) {
|
|
||||||
if meth.Options == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if !proto.HasExtension(meth.Options, options.E_Http) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
ext, err := proto.GetExtension(meth.Options, options.E_Http)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
opts, ok := ext.(*options.HttpRule)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("extension is %T; want an HttpRule", ext)
|
|
||||||
}
|
|
||||||
return opts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Registry) newParam(meth *Method, path string) (Parameter, error) {
|
|
||||||
msg := meth.RequestType
|
|
||||||
fields, err := r.resolveFiledPath(msg, path)
|
|
||||||
if err != nil {
|
|
||||||
return Parameter{}, err
|
|
||||||
}
|
|
||||||
l := len(fields)
|
|
||||||
if l == 0 {
|
|
||||||
return Parameter{}, fmt.Errorf("invalid field access list for %s", path)
|
|
||||||
}
|
|
||||||
target := fields[l-1].Target
|
|
||||||
switch target.GetType() {
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE, descriptor.FieldDescriptorProto_TYPE_GROUP:
|
|
||||||
return Parameter{}, fmt.Errorf("aggregate type %s in parameter of %s.%s: %s", target.Type, meth.Service.GetName(), meth.GetName(), path)
|
|
||||||
}
|
|
||||||
return Parameter{
|
|
||||||
FieldPath: FieldPath(fields),
|
|
||||||
Method: meth,
|
|
||||||
Target: fields[l-1].Target,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Registry) newBody(meth *Method, path string) (*Body, error) {
|
|
||||||
msg := meth.RequestType
|
|
||||||
switch path {
|
|
||||||
case "":
|
|
||||||
return nil, nil
|
|
||||||
case "*":
|
|
||||||
return &Body{FieldPath: nil}, nil
|
|
||||||
}
|
|
||||||
fields, err := r.resolveFiledPath(msg, path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Body{FieldPath: FieldPath(fields)}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// lookupField looks up a field named "name" within "msg".
|
|
||||||
// It returns nil if no such field found.
|
|
||||||
func lookupField(msg *Message, name string) *Field {
|
|
||||||
for _, f := range msg.Fields {
|
|
||||||
if f.GetName() == name {
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// resolveFieldPath resolves "path" into a list of fieldDescriptor, starting from "msg".
|
|
||||||
func (r *Registry) resolveFiledPath(msg *Message, path string) ([]FieldPathComponent, error) {
|
|
||||||
if path == "" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
root := msg
|
|
||||||
var result []FieldPathComponent
|
|
||||||
for i, c := range strings.Split(path, ".") {
|
|
||||||
if i > 0 {
|
|
||||||
f := result[i-1].Target
|
|
||||||
switch f.GetType() {
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE, descriptor.FieldDescriptorProto_TYPE_GROUP:
|
|
||||||
var err error
|
|
||||||
msg, err = r.LookupMsg(msg.FQMN(), f.GetTypeName())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("not an aggregate type: %s in %s", f.GetName(), path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(2).Infof("Lookup %s in %s", c, msg.FQMN())
|
|
||||||
f := lookupField(msg, c)
|
|
||||||
if f == nil {
|
|
||||||
return nil, fmt.Errorf("no field %q found in %s", path, root.GetName())
|
|
||||||
}
|
|
||||||
if f.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return nil, fmt.Errorf("repeated field not allowed in field path: %s in %s", f.GetName(), path)
|
|
||||||
}
|
|
||||||
result = append(result, FieldPathComponent{Name: c, Target: f})
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
322
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go
generated
vendored
322
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go
generated
vendored
@ -1,322 +0,0 @@
|
|||||||
package descriptor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
gogen "github.com/golang/protobuf/protoc-gen-go/generator"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GoPackage represents a golang package
|
|
||||||
type GoPackage struct {
|
|
||||||
// Path is the package path to the package.
|
|
||||||
Path string
|
|
||||||
// Name is the package name of the package
|
|
||||||
Name string
|
|
||||||
// Alias is an alias of the package unique within the current invokation of grpc-gateway generator.
|
|
||||||
Alias string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Standard returns whether the import is a golang standard package.
|
|
||||||
func (p GoPackage) Standard() bool {
|
|
||||||
return !strings.Contains(p.Path, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a string representation of this package in the form of import line in golang.
|
|
||||||
func (p GoPackage) String() string {
|
|
||||||
if p.Alias == "" {
|
|
||||||
return fmt.Sprintf("%q", p.Path)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s %q", p.Alias, p.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// File wraps descriptor.FileDescriptorProto for richer features.
|
|
||||||
type File struct {
|
|
||||||
*descriptor.FileDescriptorProto
|
|
||||||
// GoPkg is the go package of the go file generated from this file..
|
|
||||||
GoPkg GoPackage
|
|
||||||
// Messages is the list of messages defined in this file.
|
|
||||||
Messages []*Message
|
|
||||||
// Enums is the list of enums defined in this file.
|
|
||||||
Enums []*Enum
|
|
||||||
// Services is the list of services defined in this file.
|
|
||||||
Services []*Service
|
|
||||||
}
|
|
||||||
|
|
||||||
// proto2 determines if the syntax of the file is proto2.
|
|
||||||
func (f *File) proto2() bool {
|
|
||||||
return f.Syntax == nil || f.GetSyntax() == "proto2"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message describes a protocol buffer message types
|
|
||||||
type Message struct {
|
|
||||||
// File is the file where the message is defined
|
|
||||||
File *File
|
|
||||||
// Outers is a list of outer messages if this message is a nested type.
|
|
||||||
Outers []string
|
|
||||||
*descriptor.DescriptorProto
|
|
||||||
Fields []*Field
|
|
||||||
|
|
||||||
// Index is proto path index of this message in File.
|
|
||||||
Index int
|
|
||||||
}
|
|
||||||
|
|
||||||
// FQMN returns a fully qualified message name of this message.
|
|
||||||
func (m *Message) FQMN() string {
|
|
||||||
components := []string{""}
|
|
||||||
if m.File.Package != nil {
|
|
||||||
components = append(components, m.File.GetPackage())
|
|
||||||
}
|
|
||||||
components = append(components, m.Outers...)
|
|
||||||
components = append(components, m.GetName())
|
|
||||||
return strings.Join(components, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoType returns a go type name for the message type.
|
|
||||||
// It prefixes the type name with the package alias if
|
|
||||||
// its belonging package is not "currentPackage".
|
|
||||||
func (m *Message) GoType(currentPackage string) string {
|
|
||||||
var components []string
|
|
||||||
components = append(components, m.Outers...)
|
|
||||||
components = append(components, m.GetName())
|
|
||||||
|
|
||||||
name := strings.Join(components, "_")
|
|
||||||
if m.File.GoPkg.Path == currentPackage {
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
pkg := m.File.GoPkg.Name
|
|
||||||
if alias := m.File.GoPkg.Alias; alias != "" {
|
|
||||||
pkg = alias
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s.%s", pkg, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enum describes a protocol buffer enum types
|
|
||||||
type Enum struct {
|
|
||||||
// File is the file where the enum is defined
|
|
||||||
File *File
|
|
||||||
// Outers is a list of outer messages if this enum is a nested type.
|
|
||||||
Outers []string
|
|
||||||
*descriptor.EnumDescriptorProto
|
|
||||||
|
|
||||||
Index int
|
|
||||||
}
|
|
||||||
|
|
||||||
// FQEN returns a fully qualified enum name of this enum.
|
|
||||||
func (e *Enum) FQEN() string {
|
|
||||||
components := []string{""}
|
|
||||||
if e.File.Package != nil {
|
|
||||||
components = append(components, e.File.GetPackage())
|
|
||||||
}
|
|
||||||
components = append(components, e.Outers...)
|
|
||||||
components = append(components, e.GetName())
|
|
||||||
return strings.Join(components, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Service wraps descriptor.ServiceDescriptorProto for richer features.
|
|
||||||
type Service struct {
|
|
||||||
// File is the file where this service is defined.
|
|
||||||
File *File
|
|
||||||
*descriptor.ServiceDescriptorProto
|
|
||||||
// Methods is the list of methods defined in this service.
|
|
||||||
Methods []*Method
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method wraps descriptor.MethodDescriptorProto for richer features.
|
|
||||||
type Method struct {
|
|
||||||
// Service is the service which this method belongs to.
|
|
||||||
Service *Service
|
|
||||||
*descriptor.MethodDescriptorProto
|
|
||||||
|
|
||||||
// RequestType is the message type of requests to this method.
|
|
||||||
RequestType *Message
|
|
||||||
// ResponseType is the message type of responses from this method.
|
|
||||||
ResponseType *Message
|
|
||||||
Bindings []*Binding
|
|
||||||
}
|
|
||||||
|
|
||||||
// Binding describes how an HTTP endpoint is bound to a gRPC method.
|
|
||||||
type Binding struct {
|
|
||||||
// Method is the method which the endpoint is bound to.
|
|
||||||
Method *Method
|
|
||||||
// Index is a zero-origin index of the binding in the target method
|
|
||||||
Index int
|
|
||||||
// PathTmpl is path template where this method is mapped to.
|
|
||||||
PathTmpl httprule.Template
|
|
||||||
// HTTPMethod is the HTTP method which this method is mapped to.
|
|
||||||
HTTPMethod string
|
|
||||||
// PathParams is the list of parameters provided in HTTP request paths.
|
|
||||||
PathParams []Parameter
|
|
||||||
// Body describes parameters provided in HTTP request body.
|
|
||||||
Body *Body
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExplicitParams returns a list of explicitly bound parameters of "b",
|
|
||||||
// i.e. a union of field path for body and field paths for path parameters.
|
|
||||||
func (b *Binding) ExplicitParams() []string {
|
|
||||||
var result []string
|
|
||||||
if b.Body != nil {
|
|
||||||
result = append(result, b.Body.FieldPath.String())
|
|
||||||
}
|
|
||||||
for _, p := range b.PathParams {
|
|
||||||
result = append(result, p.FieldPath.String())
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Field wraps descriptor.FieldDescriptorProto for richer features.
|
|
||||||
type Field struct {
|
|
||||||
// Message is the message type which this field belongs to.
|
|
||||||
Message *Message
|
|
||||||
// FieldMessage is the message type of the field.
|
|
||||||
FieldMessage *Message
|
|
||||||
*descriptor.FieldDescriptorProto
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parameter is a parameter provided in http requests
|
|
||||||
type Parameter struct {
|
|
||||||
// FieldPath is a path to a proto field which this parameter is mapped to.
|
|
||||||
FieldPath
|
|
||||||
// Target is the proto field which this parameter is mapped to.
|
|
||||||
Target *Field
|
|
||||||
// Method is the method which this parameter is used for.
|
|
||||||
Method *Method
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConvertFuncExpr returns a go expression of a converter function.
|
|
||||||
// The converter function converts a string into a value for the parameter.
|
|
||||||
func (p Parameter) ConvertFuncExpr() (string, error) {
|
|
||||||
tbl := proto3ConvertFuncs
|
|
||||||
if p.Target.Message.File.proto2() {
|
|
||||||
tbl = proto2ConvertFuncs
|
|
||||||
}
|
|
||||||
typ := p.Target.GetType()
|
|
||||||
conv, ok := tbl[typ]
|
|
||||||
if !ok {
|
|
||||||
return "", fmt.Errorf("unsupported field type %s of parameter %s in %s.%s", typ, p.FieldPath, p.Method.Service.GetName(), p.Method.GetName())
|
|
||||||
}
|
|
||||||
return conv, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body describes a http requtest body to be sent to the method.
|
|
||||||
type Body struct {
|
|
||||||
// FieldPath is a path to a proto field which the request body is mapped to.
|
|
||||||
// The request body is mapped to the request type itself if FieldPath is empty.
|
|
||||||
FieldPath FieldPath
|
|
||||||
}
|
|
||||||
|
|
||||||
// RHS returns a right-hand-side expression in go to be used to initialize method request object.
|
|
||||||
// It starts with "msgExpr", which is the go expression of the method request object.
|
|
||||||
func (b Body) RHS(msgExpr string) string {
|
|
||||||
return b.FieldPath.RHS(msgExpr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FieldPath is a path to a field from a request message.
|
|
||||||
type FieldPath []FieldPathComponent
|
|
||||||
|
|
||||||
// String returns a string representation of the field path.
|
|
||||||
func (p FieldPath) String() string {
|
|
||||||
var components []string
|
|
||||||
for _, c := range p {
|
|
||||||
components = append(components, c.Name)
|
|
||||||
}
|
|
||||||
return strings.Join(components, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNestedProto3 indicates whether the FieldPath is a nested Proto3 path.
|
|
||||||
func (p FieldPath) IsNestedProto3() bool {
|
|
||||||
if len(p) > 1 && !p[0].Target.Message.File.proto2() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// RHS is a right-hand-side expression in go to be used to assign a value to the target field.
|
|
||||||
// It starts with "msgExpr", which is the go expression of the method request object.
|
|
||||||
func (p FieldPath) RHS(msgExpr string) string {
|
|
||||||
l := len(p)
|
|
||||||
if l == 0 {
|
|
||||||
return msgExpr
|
|
||||||
}
|
|
||||||
components := []string{msgExpr}
|
|
||||||
for i, c := range p {
|
|
||||||
if i == l-1 {
|
|
||||||
components = append(components, c.RHS())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
components = append(components, c.LHS())
|
|
||||||
}
|
|
||||||
return strings.Join(components, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// FieldPathComponent is a path component in FieldPath
|
|
||||||
type FieldPathComponent struct {
|
|
||||||
// Name is a name of the proto field which this component corresponds to.
|
|
||||||
// TODO(yugui) is this necessary?
|
|
||||||
Name string
|
|
||||||
// Target is the proto field which this component corresponds to.
|
|
||||||
Target *Field
|
|
||||||
}
|
|
||||||
|
|
||||||
// RHS returns a right-hand-side expression in go for this field.
|
|
||||||
func (c FieldPathComponent) RHS() string {
|
|
||||||
return gogen.CamelCase(c.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LHS returns a left-hand-side expression in go for this field.
|
|
||||||
func (c FieldPathComponent) LHS() string {
|
|
||||||
if c.Target.Message.File.proto2() {
|
|
||||||
return fmt.Sprintf("Get%s()", gogen.CamelCase(c.Name))
|
|
||||||
}
|
|
||||||
return gogen.CamelCase(c.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
proto3ConvertFuncs = map[descriptor.FieldDescriptorProto_Type]string{
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_DOUBLE: "runtime.Float64",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FLOAT: "runtime.Float32",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT64: "runtime.Int64",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT64: "runtime.Uint64",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT32: "runtime.Int32",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED64: "runtime.Uint64",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED32: "runtime.Uint32",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_BOOL: "runtime.Bool",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_STRING: "runtime.String",
|
|
||||||
// FieldDescriptorProto_TYPE_GROUP
|
|
||||||
// FieldDescriptorProto_TYPE_MESSAGE
|
|
||||||
// FieldDescriptorProto_TYPE_BYTES
|
|
||||||
// TODO(yugui) Handle bytes
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT32: "runtime.Uint32",
|
|
||||||
// FieldDescriptorProto_TYPE_ENUM
|
|
||||||
// TODO(yugui) Handle Enum
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32: "runtime.Int32",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64: "runtime.Int64",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT32: "runtime.Int32",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT64: "runtime.Int64",
|
|
||||||
}
|
|
||||||
|
|
||||||
proto2ConvertFuncs = map[descriptor.FieldDescriptorProto_Type]string{
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_DOUBLE: "runtime.Float64P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FLOAT: "runtime.Float32P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT64: "runtime.Int64P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT64: "runtime.Uint64P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT32: "runtime.Int32P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED64: "runtime.Uint64P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED32: "runtime.Uint32P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_BOOL: "runtime.BoolP",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_STRING: "runtime.StringP",
|
|
||||||
// FieldDescriptorProto_TYPE_GROUP
|
|
||||||
// FieldDescriptorProto_TYPE_MESSAGE
|
|
||||||
// FieldDescriptorProto_TYPE_BYTES
|
|
||||||
// TODO(yugui) Handle bytes
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT32: "runtime.Uint32P",
|
|
||||||
// FieldDescriptorProto_TYPE_ENUM
|
|
||||||
// TODO(yugui) Handle Enum
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32: "runtime.Int32P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64: "runtime.Int64P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT32: "runtime.Int32P",
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT64: "runtime.Int64P",
|
|
||||||
}
|
|
||||||
)
|
|
@ -1,206 +0,0 @@
|
|||||||
package descriptor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGoPackageStandard(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
pkg GoPackage
|
|
||||||
want bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "fmt", Name: "fmt"},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "encoding/json", Name: "json"},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/golang/protobuf/jsonpb", Name: "jsonpb"},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "golang.org/x/net/context", Name: "context"},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/grpc-ecosystem/grpc-gateway", Name: "main"},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/google/googleapis/google/api/http.pb", Name: "http_pb", Alias: "htpb"},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
if got, want := spec.pkg.Standard(), spec.want; got != want {
|
|
||||||
t.Errorf("%#v.Standard() = %v; want %v", spec.pkg, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoPackageString(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
pkg GoPackage
|
|
||||||
want string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "fmt", Name: "fmt"},
|
|
||||||
want: `"fmt"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "encoding/json", Name: "json"},
|
|
||||||
want: `"encoding/json"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/golang/protobuf/jsonpb", Name: "jsonpb"},
|
|
||||||
want: `"github.com/golang/protobuf/jsonpb"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "golang.org/x/net/context", Name: "context"},
|
|
||||||
want: `"golang.org/x/net/context"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/grpc-ecosystem/grpc-gateway", Name: "main"},
|
|
||||||
want: `"github.com/grpc-ecosystem/grpc-gateway"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pkg: GoPackage{Path: "github.com/google/googleapis/google/api/http.pb", Name: "http_pb", Alias: "htpb"},
|
|
||||||
want: `htpb "github.com/google/googleapis/google/api/http.pb"`,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
if got, want := spec.pkg.String(), spec.want; got != want {
|
|
||||||
t.Errorf("%#v.String() = %q; want %q", spec.pkg, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFieldPath(t *testing.T) {
|
|
||||||
var fds []*descriptor.FileDescriptorProto
|
|
||||||
for _, src := range []string{
|
|
||||||
`
|
|
||||||
name: 'example.proto'
|
|
||||||
package: 'example'
|
|
||||||
message_type <
|
|
||||||
name: 'Nest'
|
|
||||||
field <
|
|
||||||
name: 'nest2_field'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_MESSAGE
|
|
||||||
type_name: 'Nest2'
|
|
||||||
number: 1
|
|
||||||
>
|
|
||||||
field <
|
|
||||||
name: 'terminal_field'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_STRING
|
|
||||||
number: 2
|
|
||||||
>
|
|
||||||
>
|
|
||||||
syntax: "proto3"
|
|
||||||
`, `
|
|
||||||
name: 'another.proto'
|
|
||||||
package: 'example'
|
|
||||||
message_type <
|
|
||||||
name: 'Nest2'
|
|
||||||
field <
|
|
||||||
name: 'nest_field'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_MESSAGE
|
|
||||||
type_name: 'Nest'
|
|
||||||
number: 1
|
|
||||||
>
|
|
||||||
field <
|
|
||||||
name: 'terminal_field'
|
|
||||||
label: LABEL_OPTIONAL
|
|
||||||
type: TYPE_STRING
|
|
||||||
number: 2
|
|
||||||
>
|
|
||||||
>
|
|
||||||
syntax: "proto2"
|
|
||||||
`,
|
|
||||||
} {
|
|
||||||
var fd descriptor.FileDescriptorProto
|
|
||||||
if err := proto.UnmarshalText(src, &fd); err != nil {
|
|
||||||
t.Fatalf("proto.UnmarshalText(%s, &fd) failed with %v; want success", src, err)
|
|
||||||
}
|
|
||||||
fds = append(fds, &fd)
|
|
||||||
}
|
|
||||||
nest := &Message{
|
|
||||||
DescriptorProto: fds[0].MessageType[0],
|
|
||||||
Fields: []*Field{
|
|
||||||
{FieldDescriptorProto: fds[0].MessageType[0].Field[0]},
|
|
||||||
{FieldDescriptorProto: fds[0].MessageType[0].Field[1]},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nest2 := &Message{
|
|
||||||
DescriptorProto: fds[1].MessageType[0],
|
|
||||||
Fields: []*Field{
|
|
||||||
{FieldDescriptorProto: fds[1].MessageType[0].Field[0]},
|
|
||||||
{FieldDescriptorProto: fds[1].MessageType[0].Field[1]},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
file1 := &File{
|
|
||||||
FileDescriptorProto: fds[0],
|
|
||||||
GoPkg: GoPackage{Path: "example", Name: "example"},
|
|
||||||
Messages: []*Message{nest},
|
|
||||||
}
|
|
||||||
file2 := &File{
|
|
||||||
FileDescriptorProto: fds[1],
|
|
||||||
GoPkg: GoPackage{Path: "example", Name: "example"},
|
|
||||||
Messages: []*Message{nest2},
|
|
||||||
}
|
|
||||||
crossLinkFixture(file1)
|
|
||||||
crossLinkFixture(file2)
|
|
||||||
|
|
||||||
c1 := FieldPathComponent{
|
|
||||||
Name: "nest_field",
|
|
||||||
Target: nest2.Fields[0],
|
|
||||||
}
|
|
||||||
if got, want := c1.LHS(), "GetNestField()"; got != want {
|
|
||||||
t.Errorf("c1.LHS() = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := c1.RHS(), "NestField"; got != want {
|
|
||||||
t.Errorf("c1.RHS() = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
c2 := FieldPathComponent{
|
|
||||||
Name: "nest2_field",
|
|
||||||
Target: nest.Fields[0],
|
|
||||||
}
|
|
||||||
if got, want := c2.LHS(), "Nest2Field"; got != want {
|
|
||||||
t.Errorf("c2.LHS() = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
if got, want := c2.LHS(), "Nest2Field"; got != want {
|
|
||||||
t.Errorf("c2.LHS() = %q; want %q", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
fp := FieldPath{
|
|
||||||
c1, c2, c1, FieldPathComponent{
|
|
||||||
Name: "terminal_field",
|
|
||||||
Target: nest.Fields[1],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if got, want := fp.RHS("resp"), "resp.GetNestField().Nest2Field.GetNestField().TerminalField"; got != want {
|
|
||||||
t.Errorf("fp.RHS(%q) = %q; want %q", "resp", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
fp2 := FieldPath{
|
|
||||||
c2, c1, c2, FieldPathComponent{
|
|
||||||
Name: "terminal_field",
|
|
||||||
Target: nest2.Fields[1],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if got, want := fp2.RHS("resp"), "resp.Nest2Field.GetNestField().Nest2Field.TerminalField"; got != want {
|
|
||||||
t.Errorf("fp2.RHS(%q) = %q; want %q", "resp", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
var fpEmpty FieldPath
|
|
||||||
if got, want := fpEmpty.RHS("resp"), "resp"; got != want {
|
|
||||||
t.Errorf("fpEmpty.RHS(%q) = %q; want %q", "resp", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
// Package generator provides an abstract interface to code generators.
|
|
||||||
package generator
|
|
||||||
|
|
||||||
import (
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Generator is an abstraction of code generators.
|
|
||||||
type Generator interface {
|
|
||||||
// Generate generates output files from input .proto files.
|
|
||||||
Generate(targets []*descriptor.File) ([]*plugin.CodeGeneratorResponse_File, error)
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
// Package gengateway provides a code generator for grpc gateway files.
|
|
||||||
package gengateway
|
|
@ -1,111 +0,0 @@
|
|||||||
package gengateway
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"go/format"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
gen "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/generator"
|
|
||||||
options "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errNoTargetService = errors.New("no target service defined in the file")
|
|
||||||
)
|
|
||||||
|
|
||||||
type generator struct {
|
|
||||||
reg *descriptor.Registry
|
|
||||||
baseImports []descriptor.GoPackage
|
|
||||||
useRequestContext bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns a new generator which generates grpc gateway files.
|
|
||||||
func New(reg *descriptor.Registry, useRequestContext bool) gen.Generator {
|
|
||||||
var imports []descriptor.GoPackage
|
|
||||||
for _, pkgpath := range []string{
|
|
||||||
"io",
|
|
||||||
"net/http",
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime",
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities",
|
|
||||||
"github.com/golang/protobuf/proto",
|
|
||||||
"golang.org/x/net/context",
|
|
||||||
"google.golang.org/grpc",
|
|
||||||
"google.golang.org/grpc/codes",
|
|
||||||
"google.golang.org/grpc/grpclog",
|
|
||||||
} {
|
|
||||||
pkg := descriptor.GoPackage{
|
|
||||||
Path: pkgpath,
|
|
||||||
Name: path.Base(pkgpath),
|
|
||||||
}
|
|
||||||
if err := reg.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
alias := fmt.Sprintf("%s_%d", pkg.Name, i)
|
|
||||||
if err := reg.ReserveGoPackageAlias(alias, pkg.Path); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pkg.Alias = alias
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
imports = append(imports, pkg)
|
|
||||||
}
|
|
||||||
return &generator{reg: reg, baseImports: imports, useRequestContext: useRequestContext}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGeneratorResponse_File, error) {
|
|
||||||
var files []*plugin.CodeGeneratorResponse_File
|
|
||||||
for _, file := range targets {
|
|
||||||
glog.V(1).Infof("Processing %s", file.GetName())
|
|
||||||
code, err := g.generate(file)
|
|
||||||
if err == errNoTargetService {
|
|
||||||
glog.V(1).Infof("%s: %v", file.GetName(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
formatted, err := format.Source([]byte(code))
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("%v: %s", err, code)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
name := file.GetName()
|
|
||||||
ext := filepath.Ext(name)
|
|
||||||
base := strings.TrimSuffix(name, ext)
|
|
||||||
output := fmt.Sprintf("%s.pb.gw.go", base)
|
|
||||||
files = append(files, &plugin.CodeGeneratorResponse_File{
|
|
||||||
Name: proto.String(output),
|
|
||||||
Content: proto.String(string(formatted)),
|
|
||||||
})
|
|
||||||
glog.V(1).Infof("Will emit %s", output)
|
|
||||||
}
|
|
||||||
return files, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *generator) generate(file *descriptor.File) (string, error) {
|
|
||||||
pkgSeen := make(map[string]bool)
|
|
||||||
var imports []descriptor.GoPackage
|
|
||||||
for _, pkg := range g.baseImports {
|
|
||||||
pkgSeen[pkg.Path] = true
|
|
||||||
imports = append(imports, pkg)
|
|
||||||
}
|
|
||||||
for _, svc := range file.Services {
|
|
||||||
for _, m := range svc.Methods {
|
|
||||||
pkg := m.RequestType.File.GoPkg
|
|
||||||
if m.Options == nil || !proto.HasExtension(m.Options, options.E_Http) ||
|
|
||||||
pkg == file.GoPkg || pkgSeen[pkg.Path] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pkgSeen[pkg.Path] = true
|
|
||||||
imports = append(imports, pkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return applyTemplate(param{File: file, Imports: imports, UseRequestContext: g.useRequestContext})
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
package gengateway
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
protodescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGenerateServiceWithoutBindings(t *testing.T) {
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
msg1 := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
File: &descriptor.File{
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "github.com/golang/protobuf/ptypes/empty",
|
|
||||||
Name: "empty",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Example"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
meth1 := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("ExampleWithoutBindings"),
|
|
||||||
InputType: proto.String("empty.Empty"),
|
|
||||||
OutputType: proto.String("empty.Empty"),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth, meth1},
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
Dependency: []string{"a.example/b/c.proto", "a.example/d/e.proto"},
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "GET",
|
|
||||||
Body: &descriptor.Body{FieldPath: nil},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth1,
|
|
||||||
RequestType: msg1,
|
|
||||||
ResponseType: msg1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
g := &generator{}
|
|
||||||
got, err := g.generate(crossLinkFixture(&file))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("generate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if notwanted := `"github.com/golang/protobuf/ptypes/empty"`; strings.Contains(got, notwanted) {
|
|
||||||
t.Errorf("generate(%#v) = %s; does not want to contain %s", file, got, notwanted)
|
|
||||||
}
|
|
||||||
}
|
|
398
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/template.go
generated
vendored
398
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/template.go
generated
vendored
@ -1,398 +0,0 @@
|
|||||||
package gengateway
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type param struct {
|
|
||||||
*descriptor.File
|
|
||||||
Imports []descriptor.GoPackage
|
|
||||||
UseRequestContext bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type binding struct {
|
|
||||||
*descriptor.Binding
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasQueryParam determines if the binding needs parameters in query string.
|
|
||||||
//
|
|
||||||
// It sometimes returns true even though actually the binding does not need.
|
|
||||||
// But it is not serious because it just results in a small amount of extra codes generated.
|
|
||||||
func (b binding) HasQueryParam() bool {
|
|
||||||
if b.Body != nil && len(b.Body.FieldPath) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
fields := make(map[string]bool)
|
|
||||||
for _, f := range b.Method.RequestType.Fields {
|
|
||||||
fields[f.GetName()] = true
|
|
||||||
}
|
|
||||||
if b.Body != nil {
|
|
||||||
delete(fields, b.Body.FieldPath.String())
|
|
||||||
}
|
|
||||||
for _, p := range b.PathParams {
|
|
||||||
delete(fields, p.FieldPath.String())
|
|
||||||
}
|
|
||||||
return len(fields) > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b binding) QueryParamFilter() queryParamFilter {
|
|
||||||
var seqs [][]string
|
|
||||||
if b.Body != nil {
|
|
||||||
seqs = append(seqs, strings.Split(b.Body.FieldPath.String(), "."))
|
|
||||||
}
|
|
||||||
for _, p := range b.PathParams {
|
|
||||||
seqs = append(seqs, strings.Split(p.FieldPath.String(), "."))
|
|
||||||
}
|
|
||||||
return queryParamFilter{utilities.NewDoubleArray(seqs)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// queryParamFilter is a wrapper of utilities.DoubleArray which provides String() to output DoubleArray.Encoding in a stable and predictable format.
|
|
||||||
type queryParamFilter struct {
|
|
||||||
*utilities.DoubleArray
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f queryParamFilter) String() string {
|
|
||||||
encodings := make([]string, len(f.Encoding))
|
|
||||||
for str, enc := range f.Encoding {
|
|
||||||
encodings[enc] = fmt.Sprintf("%q: %d", str, enc)
|
|
||||||
}
|
|
||||||
e := strings.Join(encodings, ", ")
|
|
||||||
return fmt.Sprintf("&utilities.DoubleArray{Encoding: map[string]int{%s}, Base: %#v, Check: %#v}", e, f.Base, f.Check)
|
|
||||||
}
|
|
||||||
|
|
||||||
type trailerParams struct {
|
|
||||||
Services []*descriptor.Service
|
|
||||||
UseRequestContext bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func applyTemplate(p param) (string, error) {
|
|
||||||
w := bytes.NewBuffer(nil)
|
|
||||||
if err := headerTemplate.Execute(w, p); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
var targetServices []*descriptor.Service
|
|
||||||
for _, svc := range p.Services {
|
|
||||||
var methodWithBindingsSeen bool
|
|
||||||
for _, meth := range svc.Methods {
|
|
||||||
glog.V(2).Infof("Processing %s.%s", svc.GetName(), meth.GetName())
|
|
||||||
methName := strings.Title(*meth.Name)
|
|
||||||
meth.Name = &methName
|
|
||||||
for _, b := range meth.Bindings {
|
|
||||||
methodWithBindingsSeen = true
|
|
||||||
if err := handlerTemplate.Execute(w, binding{Binding: b}); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if methodWithBindingsSeen {
|
|
||||||
targetServices = append(targetServices, svc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(targetServices) == 0 {
|
|
||||||
return "", errNoTargetService
|
|
||||||
}
|
|
||||||
|
|
||||||
tp := trailerParams{
|
|
||||||
Services: targetServices,
|
|
||||||
UseRequestContext: p.UseRequestContext,
|
|
||||||
}
|
|
||||||
if err := trailerTemplate.Execute(w, tp); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return w.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
headerTemplate = template.Must(template.New("header").Parse(`
|
|
||||||
// Code generated by protoc-gen-grpc-gateway
|
|
||||||
// source: {{.GetName}}
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package {{.GoPkg.Name}} is a reverse proxy.
|
|
||||||
|
|
||||||
It translates gRPC into RESTful JSON APIs.
|
|
||||||
*/
|
|
||||||
package {{.GoPkg.Name}}
|
|
||||||
import (
|
|
||||||
{{range $i := .Imports}}{{if $i.Standard}}{{$i | printf "%s\n"}}{{end}}{{end}}
|
|
||||||
|
|
||||||
{{range $i := .Imports}}{{if not $i.Standard}}{{$i | printf "%s\n"}}{{end}}{{end}}
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ codes.Code
|
|
||||||
var _ io.Reader
|
|
||||||
var _ = runtime.String
|
|
||||||
var _ = utilities.NewDoubleArray
|
|
||||||
`))
|
|
||||||
|
|
||||||
handlerTemplate = template.Must(template.New("handler").Parse(`
|
|
||||||
{{if and .Method.GetClientStreaming .Method.GetServerStreaming}}
|
|
||||||
{{template "bidi-streaming-request-func" .}}
|
|
||||||
{{else if .Method.GetClientStreaming}}
|
|
||||||
{{template "client-streaming-request-func" .}}
|
|
||||||
{{else}}
|
|
||||||
{{template "client-rpc-request-func" .}}
|
|
||||||
{{end}}
|
|
||||||
`))
|
|
||||||
|
|
||||||
_ = template.Must(handlerTemplate.New("request-func-signature").Parse(strings.Replace(`
|
|
||||||
{{if .Method.GetServerStreaming}}
|
|
||||||
func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, marshaler runtime.Marshaler, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) ({{.Method.Service.GetName}}_{{.Method.GetName}}Client, runtime.ServerMetadata, error)
|
|
||||||
{{else}}
|
|
||||||
func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, marshaler runtime.Marshaler, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error)
|
|
||||||
{{end}}`, "\n", "", -1)))
|
|
||||||
|
|
||||||
_ = template.Must(handlerTemplate.New("client-streaming-request-func").Parse(`
|
|
||||||
{{template "request-func-signature" .}} {
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
stream, err := client.{{.Method.GetName}}(ctx)
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to start streaming: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
dec := marshaler.NewDecoder(req.Body)
|
|
||||||
for {
|
|
||||||
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
|
|
||||||
err = dec.Decode(&protoReq)
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to decode request: %v", err)
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
if err = stream.Send(&protoReq); err != nil {
|
|
||||||
grpclog.Printf("Failed to send request: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := stream.CloseSend(); err != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to get header from client: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
{{if .Method.GetServerStreaming}}
|
|
||||||
return stream, metadata, nil
|
|
||||||
{{else}}
|
|
||||||
msg, err := stream.CloseAndRecv()
|
|
||||||
metadata.TrailerMD = stream.Trailer()
|
|
||||||
return msg, metadata, err
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
`))
|
|
||||||
|
|
||||||
_ = template.Must(handlerTemplate.New("client-rpc-request-func").Parse(`
|
|
||||||
{{if .HasQueryParam}}
|
|
||||||
var (
|
|
||||||
filter_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}} = {{.QueryParamFilter}}
|
|
||||||
)
|
|
||||||
{{end}}
|
|
||||||
{{template "request-func-signature" .}} {
|
|
||||||
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
{{if .Body}}
|
|
||||||
if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{if .PathParams}}
|
|
||||||
var (
|
|
||||||
val string
|
|
||||||
ok bool
|
|
||||||
err error
|
|
||||||
_ = err
|
|
||||||
)
|
|
||||||
{{range $param := .PathParams}}
|
|
||||||
val, ok = pathParams[{{$param | printf "%q"}}]
|
|
||||||
if !ok {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", {{$param | printf "%q"}})
|
|
||||||
}
|
|
||||||
{{if $param.IsNestedProto3 }}
|
|
||||||
err = runtime.PopulateFieldFromPath(&protoReq, {{$param | printf "%q"}}, val)
|
|
||||||
{{else}}
|
|
||||||
{{$param.RHS "protoReq"}}, err = {{$param.ConvertFuncExpr}}(val)
|
|
||||||
{{end}}
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if .HasQueryParam}}
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}); err != nil {
|
|
||||||
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{if .Method.GetServerStreaming}}
|
|
||||||
stream, err := client.{{.Method.GetName}}(ctx, &protoReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
return stream, metadata, nil
|
|
||||||
{{else}}
|
|
||||||
msg, err := client.{{.Method.GetName}}(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
||||||
return msg, metadata, err
|
|
||||||
{{end}}
|
|
||||||
}`))
|
|
||||||
|
|
||||||
_ = template.Must(handlerTemplate.New("bidi-streaming-request-func").Parse(`
|
|
||||||
{{template "request-func-signature" .}} {
|
|
||||||
var metadata runtime.ServerMetadata
|
|
||||||
stream, err := client.{{.Method.GetName}}(ctx)
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to start streaming: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
dec := marshaler.NewDecoder(req.Body)
|
|
||||||
handleSend := func() error {
|
|
||||||
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
|
|
||||||
err = dec.Decode(&protoReq)
|
|
||||||
if err == io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to decode request: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err = stream.Send(&protoReq); err != nil {
|
|
||||||
grpclog.Printf("Failed to send request: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := handleSend(); err != nil {
|
|
||||||
if cerr := stream.CloseSend(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", cerr)
|
|
||||||
}
|
|
||||||
if err == io.EOF {
|
|
||||||
return stream, metadata, nil
|
|
||||||
}
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
if err := handleSend(); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := stream.CloseSend(); err != nil {
|
|
||||||
grpclog.Printf("Failed to terminate client stream: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
header, err := stream.Header()
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to get header from client: %v", err)
|
|
||||||
return nil, metadata, err
|
|
||||||
}
|
|
||||||
metadata.HeaderMD = header
|
|
||||||
return stream, metadata, nil
|
|
||||||
}
|
|
||||||
`))
|
|
||||||
|
|
||||||
trailerTemplate = template.Must(template.New("trailer").Parse(`
|
|
||||||
{{$UseRequestContext := .UseRequestContext}}
|
|
||||||
{{range $svc := .Services}}
|
|
||||||
// Register{{$svc.GetName}}HandlerFromEndpoint is same as Register{{$svc.GetName}}Handler but
|
|
||||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
|
||||||
func Register{{$svc.GetName}}HandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
|
||||||
conn, err := grpc.Dial(endpoint, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
if cerr := conn.Close(); cerr != nil {
|
|
||||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return Register{{$svc.GetName}}Handler(ctx, mux, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register{{$svc.GetName}}Handler registers the http handlers for service {{$svc.GetName}} to "mux".
|
|
||||||
// The handlers forward requests to the grpc endpoint over "conn".
|
|
||||||
func Register{{$svc.GetName}}Handler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
|
||||||
client := New{{$svc.GetName}}Client(conn)
|
|
||||||
{{range $m := $svc.Methods}}
|
|
||||||
{{range $b := $m.Bindings}}
|
|
||||||
mux.Handle({{$b.HTTPMethod | printf "%q"}}, pattern_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
||||||
{{- if $UseRequestContext }}
|
|
||||||
ctx, cancel := context.WithCancel(req.Context())
|
|
||||||
{{- else -}}
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
{{- end }}
|
|
||||||
defer cancel()
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
go func(done <-chan struct{}, closed <-chan bool) {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-closed:
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}(ctx.Done(), cn.CloseNotify())
|
|
||||||
}
|
|
||||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
||||||
rctx, err := runtime.AnnotateContext(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
}
|
|
||||||
resp, md, err := request_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(rctx, inboundMarshaler, client, req, pathParams)
|
|
||||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
{{if $m.GetServerStreaming}}
|
|
||||||
forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
|
||||||
{{else}}
|
|
||||||
forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
||||||
{{end}}
|
|
||||||
})
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
{{range $m := $svc.Methods}}
|
|
||||||
{{range $b := $m.Bindings}}
|
|
||||||
pattern_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}} = runtime.MustPattern(runtime.NewPattern({{$b.PathTmpl.Version}}, {{$b.PathTmpl.OpCodes | printf "%#v"}}, {{$b.PathTmpl.Pool | printf "%#v"}}, {{$b.PathTmpl.Verb | printf "%q"}}))
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
{{range $m := $svc.Methods}}
|
|
||||||
{{range $b := $m.Bindings}}
|
|
||||||
forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}} = {{if $m.GetServerStreaming}}runtime.ForwardResponseStream{{else}}runtime.ForwardResponseMessage{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
)
|
|
||||||
{{end}}`))
|
|
||||||
)
|
|
@ -1,404 +0,0 @@
|
|||||||
package gengateway
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
protodescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule"
|
|
||||||
)
|
|
||||||
|
|
||||||
func crossLinkFixture(f *descriptor.File) *descriptor.File {
|
|
||||||
for _, m := range f.Messages {
|
|
||||||
m.File = f
|
|
||||||
}
|
|
||||||
for _, svc := range f.Services {
|
|
||||||
svc.File = f
|
|
||||||
for _, m := range svc.Methods {
|
|
||||||
m.Service = svc
|
|
||||||
for _, b := range m.Bindings {
|
|
||||||
b.Method = m
|
|
||||||
for _, param := range b.PathParams {
|
|
||||||
param.Method = m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateHeader(t *testing.T) {
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Example"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
Dependency: []string{"a.example/b/c.proto", "a.example/d/e.proto"},
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "GET",
|
|
||||||
Body: &descriptor.Body{FieldPath: nil},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
got, err := applyTemplate(param{File: crossLinkFixture(&file)})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if want := "package example_pb\n"; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateRequestWithoutClientStreaming(t *testing.T) {
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("nested"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String("NestedMessage"),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nesteddesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("NestedMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("int32"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_INT32.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("bool"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_BOOL.Enum(),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Echo"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
ClientStreaming: proto.Bool(false),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
for _, spec := range []struct {
|
|
||||||
serverStreaming bool
|
|
||||||
sigWant string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
serverStreaming: false,
|
|
||||||
sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
serverStreaming: true,
|
|
||||||
sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
meth.ServerStreaming = proto.Bool(spec.serverStreaming)
|
|
||||||
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
nested := &descriptor.Message{
|
|
||||||
DescriptorProto: nesteddesc,
|
|
||||||
}
|
|
||||||
|
|
||||||
nestedField := &descriptor.Field{
|
|
||||||
Message: msg,
|
|
||||||
FieldDescriptorProto: msg.GetField()[0],
|
|
||||||
}
|
|
||||||
intField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[0],
|
|
||||||
}
|
|
||||||
boolField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[1],
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc, nesteddesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg, nested},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "POST",
|
|
||||||
PathTmpl: httprule.Template{
|
|
||||||
Version: 1,
|
|
||||||
OpCodes: []int{0, 0},
|
|
||||||
},
|
|
||||||
PathParams: []descriptor.Parameter{
|
|
||||||
{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "int32",
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Body: &descriptor.Body{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "bool",
|
|
||||||
Target: boolField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
got, err := applyTemplate(param{File: crossLinkFixture(&file)})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if want := spec.sigWant; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `marshaler.NewDecoder(req.Body).Decode(&protoReq.GetNested().Bool)`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `val, ok = pathParams["nested.int32"]`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `protoReq.GetNested().Int32, err = runtime.Int32P(val)`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `pattern_ExampleService_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{0, 0}, []string(nil), ""))`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateRequestWithClientStreaming(t *testing.T) {
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("nested"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String("NestedMessage"),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nesteddesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("NestedMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("int32"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_INT32.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("bool"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_BOOL.Enum(),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Echo"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
ClientStreaming: proto.Bool(true),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
for _, spec := range []struct {
|
|
||||||
serverStreaming bool
|
|
||||||
sigWant string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
serverStreaming: false,
|
|
||||||
sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
serverStreaming: true,
|
|
||||||
sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
meth.ServerStreaming = proto.Bool(spec.serverStreaming)
|
|
||||||
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
nested := &descriptor.Message{
|
|
||||||
DescriptorProto: nesteddesc,
|
|
||||||
}
|
|
||||||
|
|
||||||
nestedField := &descriptor.Field{
|
|
||||||
Message: msg,
|
|
||||||
FieldDescriptorProto: msg.GetField()[0],
|
|
||||||
}
|
|
||||||
intField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[0],
|
|
||||||
}
|
|
||||||
boolField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[1],
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc, nesteddesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg, nested},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "POST",
|
|
||||||
PathTmpl: httprule.Template{
|
|
||||||
Version: 1,
|
|
||||||
OpCodes: []int{0, 0},
|
|
||||||
},
|
|
||||||
PathParams: []descriptor.Parameter{
|
|
||||||
{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "int32",
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Body: &descriptor.Body{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "bool",
|
|
||||||
Target: boolField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
got, err := applyTemplate(param{File: crossLinkFixture(&file)})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if want := spec.sigWant; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `marshaler.NewDecoder(req.Body)`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want := `pattern_ExampleService_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{0, 0}, []string(nil), ""))`; !strings.Contains(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
117
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/compile.go
generated
vendored
117
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/compile.go
generated
vendored
@ -1,117 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
opcodeVersion = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
// Template is a compiled representation of path templates.
|
|
||||||
type Template struct {
|
|
||||||
// Version is the version number of the format.
|
|
||||||
Version int
|
|
||||||
// OpCodes is a sequence of operations.
|
|
||||||
OpCodes []int
|
|
||||||
// Pool is a constant pool
|
|
||||||
Pool []string
|
|
||||||
// Verb is a VERB part in the template.
|
|
||||||
Verb string
|
|
||||||
// Fields is a list of field paths bound in this template.
|
|
||||||
Fields []string
|
|
||||||
// Original template (example: /v1/a_bit_of_everything)
|
|
||||||
Template string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compiler compiles utilities representation of path templates into marshallable operations.
|
|
||||||
// They can be unmarshalled by runtime.NewPattern.
|
|
||||||
type Compiler interface {
|
|
||||||
Compile() Template
|
|
||||||
}
|
|
||||||
|
|
||||||
type op struct {
|
|
||||||
// code is the opcode of the operation
|
|
||||||
code utilities.OpCode
|
|
||||||
|
|
||||||
// str is a string operand of the code.
|
|
||||||
// num is ignored if str is not empty.
|
|
||||||
str string
|
|
||||||
|
|
||||||
// num is a numeric operand of the code.
|
|
||||||
num int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w wildcard) compile() []op {
|
|
||||||
return []op{
|
|
||||||
{code: utilities.OpPush},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w deepWildcard) compile() []op {
|
|
||||||
return []op{
|
|
||||||
{code: utilities.OpPushM},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l literal) compile() []op {
|
|
||||||
return []op{
|
|
||||||
{
|
|
||||||
code: utilities.OpLitPush,
|
|
||||||
str: string(l),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v variable) compile() []op {
|
|
||||||
var ops []op
|
|
||||||
for _, s := range v.segments {
|
|
||||||
ops = append(ops, s.compile()...)
|
|
||||||
}
|
|
||||||
ops = append(ops, op{
|
|
||||||
code: utilities.OpConcatN,
|
|
||||||
num: len(v.segments),
|
|
||||||
}, op{
|
|
||||||
code: utilities.OpCapture,
|
|
||||||
str: v.path,
|
|
||||||
})
|
|
||||||
|
|
||||||
return ops
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t template) Compile() Template {
|
|
||||||
var rawOps []op
|
|
||||||
for _, s := range t.segments {
|
|
||||||
rawOps = append(rawOps, s.compile()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
ops []int
|
|
||||||
pool []string
|
|
||||||
fields []string
|
|
||||||
)
|
|
||||||
consts := make(map[string]int)
|
|
||||||
for _, op := range rawOps {
|
|
||||||
ops = append(ops, int(op.code))
|
|
||||||
if op.str == "" {
|
|
||||||
ops = append(ops, op.num)
|
|
||||||
} else {
|
|
||||||
if _, ok := consts[op.str]; !ok {
|
|
||||||
consts[op.str] = len(pool)
|
|
||||||
pool = append(pool, op.str)
|
|
||||||
}
|
|
||||||
ops = append(ops, consts[op.str])
|
|
||||||
}
|
|
||||||
if op.code == utilities.OpCapture {
|
|
||||||
fields = append(fields, op.str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Template{
|
|
||||||
Version: opcodeVersion,
|
|
||||||
OpCodes: ops,
|
|
||||||
Pool: pool,
|
|
||||||
Verb: t.verb,
|
|
||||||
Fields: fields,
|
|
||||||
Template: t.template,
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
operandFiller = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCompile(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
segs []segment
|
|
||||||
verb string
|
|
||||||
|
|
||||||
ops []int
|
|
||||||
pool []string
|
|
||||||
fields []string
|
|
||||||
}{
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
ops: []int{int(utilities.OpPush), operandFiller},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
ops: []int{int(utilities.OpPushM), operandFiller},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
},
|
|
||||||
ops: []int{int(utilities.OpLitPush), 0},
|
|
||||||
pool: []string{"v1"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
},
|
|
||||||
verb: "LOCK",
|
|
||||||
ops: []int{int(utilities.OpLitPush), 0},
|
|
||||||
pool: []string{"v1"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name.nested",
|
|
||||||
segments: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ops: []int{
|
|
||||||
int(utilities.OpPush), operandFiller,
|
|
||||||
int(utilities.OpConcatN), 1,
|
|
||||||
int(utilities.OpCapture), 0,
|
|
||||||
},
|
|
||||||
pool: []string{"name.nested"},
|
|
||||||
fields: []string{"name.nested"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
literal("obj"),
|
|
||||||
variable{
|
|
||||||
path: "name.nested",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
wildcard{},
|
|
||||||
literal("b"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
variable{
|
|
||||||
path: "obj",
|
|
||||||
segments: []segment{
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ops: []int{
|
|
||||||
int(utilities.OpLitPush), 0,
|
|
||||||
int(utilities.OpLitPush), 1,
|
|
||||||
int(utilities.OpPush), operandFiller,
|
|
||||||
int(utilities.OpLitPush), 2,
|
|
||||||
int(utilities.OpConcatN), 3,
|
|
||||||
int(utilities.OpCapture), 3,
|
|
||||||
int(utilities.OpPushM), operandFiller,
|
|
||||||
int(utilities.OpConcatN), 1,
|
|
||||||
int(utilities.OpCapture), 0,
|
|
||||||
},
|
|
||||||
pool: []string{"obj", "a", "b", "name.nested"},
|
|
||||||
fields: []string{"name.nested", "obj"},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
tmpl := template{
|
|
||||||
segments: spec.segs,
|
|
||||||
verb: spec.verb,
|
|
||||||
}
|
|
||||||
compiled := tmpl.Compile()
|
|
||||||
if got, want := compiled.Version, opcodeVersion; got != want {
|
|
||||||
t.Errorf("tmpl.Compile().Version = %d; want %d; segs=%#v, verb=%q", got, want, spec.segs, spec.verb)
|
|
||||||
}
|
|
||||||
if got, want := compiled.OpCodes, spec.ops; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("tmpl.Compile().OpCodes = %v; want %v; segs=%#v, verb=%q", got, want, spec.segs, spec.verb)
|
|
||||||
}
|
|
||||||
if got, want := compiled.Pool, spec.pool; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("tmpl.Compile().Pool = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb)
|
|
||||||
}
|
|
||||||
if got, want := compiled.Verb, spec.verb; got != want {
|
|
||||||
t.Errorf("tmpl.Compile().Verb = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb)
|
|
||||||
}
|
|
||||||
if got, want := compiled.Fields, spec.fields; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("tmpl.Compile().Fields = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
351
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/parse.go
generated
vendored
351
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/parse.go
generated
vendored
@ -1,351 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InvalidTemplateError indicates that the path template is not valid.
|
|
||||||
type InvalidTemplateError struct {
|
|
||||||
tmpl string
|
|
||||||
msg string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e InvalidTemplateError) Error() string {
|
|
||||||
return fmt.Sprintf("%s: %s", e.msg, e.tmpl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse parses the string representation of path template
|
|
||||||
func Parse(tmpl string) (Compiler, error) {
|
|
||||||
if !strings.HasPrefix(tmpl, "/") {
|
|
||||||
return template{}, InvalidTemplateError{tmpl: tmpl, msg: "no leading /"}
|
|
||||||
}
|
|
||||||
tokens, verb := tokenize(tmpl[1:])
|
|
||||||
|
|
||||||
p := parser{tokens: tokens}
|
|
||||||
segs, err := p.topLevelSegments()
|
|
||||||
if err != nil {
|
|
||||||
return template{}, InvalidTemplateError{tmpl: tmpl, msg: err.Error()}
|
|
||||||
}
|
|
||||||
|
|
||||||
return template{
|
|
||||||
segments: segs,
|
|
||||||
verb: verb,
|
|
||||||
template: tmpl,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func tokenize(path string) (tokens []string, verb string) {
|
|
||||||
if path == "" {
|
|
||||||
return []string{eof}, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
init = iota
|
|
||||||
field
|
|
||||||
nested
|
|
||||||
)
|
|
||||||
var (
|
|
||||||
st = init
|
|
||||||
)
|
|
||||||
for path != "" {
|
|
||||||
var idx int
|
|
||||||
switch st {
|
|
||||||
case init:
|
|
||||||
idx = strings.IndexAny(path, "/{")
|
|
||||||
case field:
|
|
||||||
idx = strings.IndexAny(path, ".=}")
|
|
||||||
case nested:
|
|
||||||
idx = strings.IndexAny(path, "/}")
|
|
||||||
}
|
|
||||||
if idx < 0 {
|
|
||||||
tokens = append(tokens, path)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
switch r := path[idx]; r {
|
|
||||||
case '/', '.':
|
|
||||||
case '{':
|
|
||||||
st = field
|
|
||||||
case '=':
|
|
||||||
st = nested
|
|
||||||
case '}':
|
|
||||||
st = init
|
|
||||||
}
|
|
||||||
if idx == 0 {
|
|
||||||
tokens = append(tokens, path[idx:idx+1])
|
|
||||||
} else {
|
|
||||||
tokens = append(tokens, path[:idx], path[idx:idx+1])
|
|
||||||
}
|
|
||||||
path = path[idx+1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
l := len(tokens)
|
|
||||||
t := tokens[l-1]
|
|
||||||
if idx := strings.LastIndex(t, ":"); idx == 0 {
|
|
||||||
tokens, verb = tokens[:l-1], t[1:]
|
|
||||||
} else if idx > 0 {
|
|
||||||
tokens[l-1], verb = t[:idx], t[idx+1:]
|
|
||||||
}
|
|
||||||
tokens = append(tokens, eof)
|
|
||||||
return tokens, verb
|
|
||||||
}
|
|
||||||
|
|
||||||
// parser is a parser of the template syntax defined in github.com/googleapis/googleapis/google/api/http.proto.
|
|
||||||
type parser struct {
|
|
||||||
tokens []string
|
|
||||||
accepted []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// topLevelSegments is the target of this parser.
|
|
||||||
func (p *parser) topLevelSegments() ([]segment, error) {
|
|
||||||
glog.V(1).Infof("Parsing %q", p.tokens)
|
|
||||||
segs, err := p.segments()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
glog.V(2).Infof("accept segments: %q; %q", p.accepted, p.tokens)
|
|
||||||
if _, err := p.accept(typeEOF); err != nil {
|
|
||||||
return nil, fmt.Errorf("unexpected token %q after segments %q", p.tokens[0], strings.Join(p.accepted, ""))
|
|
||||||
}
|
|
||||||
glog.V(2).Infof("accept eof: %q; %q", p.accepted, p.tokens)
|
|
||||||
return segs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) segments() ([]segment, error) {
|
|
||||||
s, err := p.segment()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
glog.V(2).Infof("accept segment: %q; %q", p.accepted, p.tokens)
|
|
||||||
|
|
||||||
segs := []segment{s}
|
|
||||||
for {
|
|
||||||
if _, err := p.accept("/"); err != nil {
|
|
||||||
return segs, nil
|
|
||||||
}
|
|
||||||
s, err := p.segment()
|
|
||||||
if err != nil {
|
|
||||||
return segs, err
|
|
||||||
}
|
|
||||||
segs = append(segs, s)
|
|
||||||
glog.V(2).Infof("accept segment: %q; %q", p.accepted, p.tokens)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) segment() (segment, error) {
|
|
||||||
if _, err := p.accept("*"); err == nil {
|
|
||||||
return wildcard{}, nil
|
|
||||||
}
|
|
||||||
if _, err := p.accept("**"); err == nil {
|
|
||||||
return deepWildcard{}, nil
|
|
||||||
}
|
|
||||||
if l, err := p.literal(); err == nil {
|
|
||||||
return l, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
v, err := p.variable()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("segment neither wildcards, literal or variable: %v", err)
|
|
||||||
}
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) literal() (segment, error) {
|
|
||||||
lit, err := p.accept(typeLiteral)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return literal(lit), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) variable() (segment, error) {
|
|
||||||
if _, err := p.accept("{"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
path, err := p.fieldPath()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var segs []segment
|
|
||||||
if _, err := p.accept("="); err == nil {
|
|
||||||
segs, err = p.segments()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid segment in variable %q: %v", path, err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
segs = []segment{wildcard{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := p.accept("}"); err != nil {
|
|
||||||
return nil, fmt.Errorf("unterminated variable segment: %s", path)
|
|
||||||
}
|
|
||||||
return variable{
|
|
||||||
path: path,
|
|
||||||
segments: segs,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) fieldPath() (string, error) {
|
|
||||||
c, err := p.accept(typeIdent)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
components := []string{c}
|
|
||||||
for {
|
|
||||||
if _, err = p.accept("."); err != nil {
|
|
||||||
return strings.Join(components, "."), nil
|
|
||||||
}
|
|
||||||
c, err := p.accept(typeIdent)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("invalid field path component: %v", err)
|
|
||||||
}
|
|
||||||
components = append(components, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A termType is a type of terminal symbols.
|
|
||||||
type termType string
|
|
||||||
|
|
||||||
// These constants define some of valid values of termType.
|
|
||||||
// They improve readability of parse functions.
|
|
||||||
//
|
|
||||||
// You can also use "/", "*", "**", "." or "=" as valid values.
|
|
||||||
const (
|
|
||||||
typeIdent = termType("ident")
|
|
||||||
typeLiteral = termType("literal")
|
|
||||||
typeEOF = termType("$")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// eof is the terminal symbol which always appears at the end of token sequence.
|
|
||||||
eof = "\u0000"
|
|
||||||
)
|
|
||||||
|
|
||||||
// accept tries to accept a token in "p".
|
|
||||||
// This function consumes a token and returns it if it matches to the specified "term".
|
|
||||||
// If it doesn't match, the function does not consume any tokens and return an error.
|
|
||||||
func (p *parser) accept(term termType) (string, error) {
|
|
||||||
t := p.tokens[0]
|
|
||||||
switch term {
|
|
||||||
case "/", "*", "**", ".", "=", "{", "}":
|
|
||||||
if t != string(term) {
|
|
||||||
return "", fmt.Errorf("expected %q but got %q", term, t)
|
|
||||||
}
|
|
||||||
case typeEOF:
|
|
||||||
if t != eof {
|
|
||||||
return "", fmt.Errorf("expected EOF but got %q", t)
|
|
||||||
}
|
|
||||||
case typeIdent:
|
|
||||||
if err := expectIdent(t); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
case typeLiteral:
|
|
||||||
if err := expectPChars(t); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return "", fmt.Errorf("unknown termType %q", term)
|
|
||||||
}
|
|
||||||
p.tokens = p.tokens[1:]
|
|
||||||
p.accepted = append(p.accepted, t)
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// expectPChars determines if "t" consists of only pchars defined in RFC3986.
|
|
||||||
//
|
|
||||||
// https://www.ietf.org/rfc/rfc3986.txt, P.49
|
|
||||||
// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
||||||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
||||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
|
||||||
// / "*" / "+" / "," / ";" / "="
|
|
||||||
// pct-encoded = "%" HEXDIG HEXDIG
|
|
||||||
func expectPChars(t string) error {
|
|
||||||
const (
|
|
||||||
init = iota
|
|
||||||
pct1
|
|
||||||
pct2
|
|
||||||
)
|
|
||||||
st := init
|
|
||||||
for _, r := range t {
|
|
||||||
if st != init {
|
|
||||||
if !isHexDigit(r) {
|
|
||||||
return fmt.Errorf("invalid hexdigit: %c(%U)", r, r)
|
|
||||||
}
|
|
||||||
switch st {
|
|
||||||
case pct1:
|
|
||||||
st = pct2
|
|
||||||
case pct2:
|
|
||||||
st = init
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// unreserved
|
|
||||||
switch {
|
|
||||||
case 'A' <= r && r <= 'Z':
|
|
||||||
continue
|
|
||||||
case 'a' <= r && r <= 'z':
|
|
||||||
continue
|
|
||||||
case '0' <= r && r <= '9':
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '-', '.', '_', '~':
|
|
||||||
// unreserved
|
|
||||||
case '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=':
|
|
||||||
// sub-delims
|
|
||||||
case ':', '@':
|
|
||||||
// rest of pchar
|
|
||||||
case '%':
|
|
||||||
// pct-encoded
|
|
||||||
st = pct1
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid character in path segment: %q(%U)", r, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if st != init {
|
|
||||||
return fmt.Errorf("invalid percent-encoding in %q", t)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// expectIdent determines if "ident" is a valid identifier in .proto schema ([[:alpha:]_][[:alphanum:]_]*).
|
|
||||||
func expectIdent(ident string) error {
|
|
||||||
if ident == "" {
|
|
||||||
return fmt.Errorf("empty identifier")
|
|
||||||
}
|
|
||||||
for pos, r := range ident {
|
|
||||||
switch {
|
|
||||||
case '0' <= r && r <= '9':
|
|
||||||
if pos == 0 {
|
|
||||||
return fmt.Errorf("identifier starting with digit: %s", ident)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
case 'A' <= r && r <= 'Z':
|
|
||||||
continue
|
|
||||||
case 'a' <= r && r <= 'z':
|
|
||||||
continue
|
|
||||||
case r == '_':
|
|
||||||
continue
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid character %q(%U) in identifier: %s", r, r, ident)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isHexDigit(r rune) bool {
|
|
||||||
switch {
|
|
||||||
case '0' <= r && r <= '9':
|
|
||||||
return true
|
|
||||||
case 'A' <= r && r <= 'F':
|
|
||||||
return true
|
|
||||||
case 'a' <= r && r <= 'f':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
313
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/parse_test.go
generated
vendored
313
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/parse_test.go
generated
vendored
@ -1,313 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTokenize(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
src string
|
|
||||||
tokens []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
src: "",
|
|
||||||
tokens: []string{eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1",
|
|
||||||
tokens: []string{"v1", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/b",
|
|
||||||
tokens: []string{"v1", "/", "b", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/endpoint/*",
|
|
||||||
tokens: []string{"v1", "/", "endpoint", "/", "*", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/endpoint/**",
|
|
||||||
tokens: []string{"v1", "/", "endpoint", "/", "**", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/b/{bucket_name=*}",
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"b", "/",
|
|
||||||
"{", "bucket_name", "=", "*", "}",
|
|
||||||
eof,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/b/{bucket_name=buckets/*}",
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"b", "/",
|
|
||||||
"{", "bucket_name", "=", "buckets", "/", "*", "}",
|
|
||||||
eof,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/b/{bucket_name=buckets/*}/o",
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"b", "/",
|
|
||||||
"{", "bucket_name", "=", "buckets", "/", "*", "}", "/",
|
|
||||||
"o",
|
|
||||||
eof,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/b/{bucket_name=buckets/*}/o/{name}",
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"b", "/",
|
|
||||||
"{", "bucket_name", "=", "buckets", "/", "*", "}", "/",
|
|
||||||
"o", "/", "{", "name", "}",
|
|
||||||
eof,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: "v1/a=b&c=d;e=f:g/endpoint.rdf",
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"a=b&c=d;e=f:g", "/",
|
|
||||||
"endpoint.rdf",
|
|
||||||
eof,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
tokens, verb := tokenize(spec.src)
|
|
||||||
if got, want := tokens, spec.tokens; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("tokenize(%q) = %q, _; want %q, _", spec.src, got, want)
|
|
||||||
}
|
|
||||||
if got, want := verb, ""; got != want {
|
|
||||||
t.Errorf("tokenize(%q) = _, %q; want _, %q", spec.src, got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
src := fmt.Sprintf("%s:%s", spec.src, "LOCK")
|
|
||||||
tokens, verb = tokenize(src)
|
|
||||||
if got, want := tokens, spec.tokens; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("tokenize(%q) = %q, _; want %q, _", src, got, want)
|
|
||||||
}
|
|
||||||
if got, want := verb, "LOCK"; got != want {
|
|
||||||
t.Errorf("tokenize(%q) = _, %q; want _, %q", src, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseSegments(t *testing.T) {
|
|
||||||
flag.Set("v", "3")
|
|
||||||
for _, spec := range []struct {
|
|
||||||
tokens []string
|
|
||||||
want []segment
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
tokens: []string{"v1", eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"-._~!$&'()*+,;=:@", eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("-._~!$&'()*+,;=:@"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"%e7%ac%ac%e4%b8%80%e7%89%88", eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("%e7%ac%ac%e4%b8%80%e7%89%88"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"v1", "/", "*", eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"v1", "/", "**", eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"{", "name", "}", eof},
|
|
||||||
want: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"{", "name", "=", "*", "}", eof},
|
|
||||||
want: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"{", "field", ".", "nested", ".", "nested2", "=", "*", "}", eof},
|
|
||||||
want: []segment{
|
|
||||||
variable{
|
|
||||||
path: "field.nested.nested2",
|
|
||||||
segments: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{"{", "name", "=", "a", "/", "b", "/", "*", "}", eof},
|
|
||||||
want: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
literal("b"),
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tokens: []string{
|
|
||||||
"v1", "/",
|
|
||||||
"{",
|
|
||||||
"name", ".", "nested", ".", "nested2",
|
|
||||||
"=",
|
|
||||||
"a", "/", "b", "/", "*",
|
|
||||||
"}", "/",
|
|
||||||
"o", "/",
|
|
||||||
"{",
|
|
||||||
"another_name",
|
|
||||||
"=",
|
|
||||||
"a", "/", "b", "/", "*", "/", "c",
|
|
||||||
"}", "/",
|
|
||||||
"**",
|
|
||||||
eof},
|
|
||||||
want: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
variable{
|
|
||||||
path: "name.nested.nested2",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
literal("b"),
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
literal("o"),
|
|
||||||
variable{
|
|
||||||
path: "another_name",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
literal("b"),
|
|
||||||
wildcard{},
|
|
||||||
literal("c"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
p := parser{tokens: spec.tokens}
|
|
||||||
segs, err := p.topLevelSegments()
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("parser{%q}.segments() failed with %v; want success", spec.tokens, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if got, want := segs, spec.want; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("parser{%q}.segments() = %#v; want %#v", spec.tokens, got, want)
|
|
||||||
}
|
|
||||||
if got := p.tokens; len(got) > 0 {
|
|
||||||
t.Errorf("p.tokens = %q; want []; spec.tokens=%q", got, spec.tokens)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseSegmentsWithErrors(t *testing.T) {
|
|
||||||
flag.Set("v", "3")
|
|
||||||
for _, spec := range []struct {
|
|
||||||
tokens []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
// double slash
|
|
||||||
tokens: []string{"/", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// invalid literal
|
|
||||||
tokens: []string{"a?b", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// invalid percent-encoding
|
|
||||||
tokens: []string{"%", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// invalid percent-encoding
|
|
||||||
tokens: []string{"%2", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// invalid percent-encoding
|
|
||||||
tokens: []string{"a%2z", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// empty segments
|
|
||||||
tokens: []string{eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// unterminated variable
|
|
||||||
tokens: []string{"{", "name", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// unterminated variable
|
|
||||||
tokens: []string{"{", "name", "=", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// unterminated variable
|
|
||||||
tokens: []string{"{", "name", "=", "*", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// empty component in field path
|
|
||||||
tokens: []string{"{", "name", ".", "}", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// empty component in field path
|
|
||||||
tokens: []string{"{", "name", ".", ".", "nested", "}", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// invalid character in identifier
|
|
||||||
tokens: []string{"{", "field-name", "}", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// no slash between segments
|
|
||||||
tokens: []string{"v1", "endpoint", eof},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// no slash between segments
|
|
||||||
tokens: []string{"v1", "{", "name", "}", eof},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
p := parser{tokens: spec.tokens}
|
|
||||||
segs, err := p.topLevelSegments()
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("parser{%q}.segments() succeeded; want InvalidTemplateError; accepted %#v", spec.tokens, segs)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
glog.V(1).Info(err)
|
|
||||||
}
|
|
||||||
}
|
|
60
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/types.go
generated
vendored
60
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/types.go
generated
vendored
@ -1,60 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type template struct {
|
|
||||||
segments []segment
|
|
||||||
verb string
|
|
||||||
template string
|
|
||||||
}
|
|
||||||
|
|
||||||
type segment interface {
|
|
||||||
fmt.Stringer
|
|
||||||
compile() (ops []op)
|
|
||||||
}
|
|
||||||
|
|
||||||
type wildcard struct{}
|
|
||||||
|
|
||||||
type deepWildcard struct{}
|
|
||||||
|
|
||||||
type literal string
|
|
||||||
|
|
||||||
type variable struct {
|
|
||||||
path string
|
|
||||||
segments []segment
|
|
||||||
}
|
|
||||||
|
|
||||||
func (wildcard) String() string {
|
|
||||||
return "*"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (deepWildcard) String() string {
|
|
||||||
return "**"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l literal) String() string {
|
|
||||||
return string(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v variable) String() string {
|
|
||||||
var segs []string
|
|
||||||
for _, s := range v.segments {
|
|
||||||
segs = append(segs, s.String())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("{%s=%s}", v.path, strings.Join(segs, "/"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t template) String() string {
|
|
||||||
var segs []string
|
|
||||||
for _, s := range t.segments {
|
|
||||||
segs = append(segs, s.String())
|
|
||||||
}
|
|
||||||
str := strings.Join(segs, "/")
|
|
||||||
if t.verb != "" {
|
|
||||||
str = fmt.Sprintf("%s:%s", str, t.verb)
|
|
||||||
}
|
|
||||||
return "/" + str
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package httprule
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTemplateStringer(t *testing.T) {
|
|
||||||
for _, spec := range []struct {
|
|
||||||
segs []segment
|
|
||||||
want string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
},
|
|
||||||
want: "/v1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
wildcard{},
|
|
||||||
},
|
|
||||||
want: "/*",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
want: "/**",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
want: "/{name=a}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
wildcard{},
|
|
||||||
literal("b"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
want: "/{name=a/*/b}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
segs: []segment{
|
|
||||||
literal("v1"),
|
|
||||||
variable{
|
|
||||||
path: "name",
|
|
||||||
segments: []segment{
|
|
||||||
literal("a"),
|
|
||||||
wildcard{},
|
|
||||||
literal("b"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
literal("c"),
|
|
||||||
variable{
|
|
||||||
path: "field.nested",
|
|
||||||
segments: []segment{
|
|
||||||
wildcard{},
|
|
||||||
literal("d"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wildcard{},
|
|
||||||
literal("e"),
|
|
||||||
deepWildcard{},
|
|
||||||
},
|
|
||||||
want: "/v1/{name=a/*/b}/c/{field.nested=*/d}/*/e/**",
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
tmpl := template{segments: spec.segs}
|
|
||||||
if got, want := tmpl.String(), spec.want; got != want {
|
|
||||||
t.Errorf("%#v.String() = %q; want %q", tmpl, got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl.verb = "LOCK"
|
|
||||||
if got, want := tmpl.String(), fmt.Sprintf("%s:LOCK", spec.want); got != want {
|
|
||||||
t.Errorf("%#v.String() = %q; want %q", tmpl, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
119
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go
generated
vendored
119
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go
generated
vendored
@ -1,119 +0,0 @@
|
|||||||
// Command protoc-gen-grpc-gateway is a plugin for Google protocol buffer
|
|
||||||
// compiler to generate a reverse-proxy, which converts incoming RESTful
|
|
||||||
// HTTP/1 requests gRPC invocation.
|
|
||||||
// You rarely need to run this program directly. Instead, put this program
|
|
||||||
// into your $PATH with a name "protoc-gen-grpc-gateway" and run
|
|
||||||
// protoc --grpc-gateway_out=output_directory path/to/input.proto
|
|
||||||
//
|
|
||||||
// See README.md for more details.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
importPrefix = flag.String("import_prefix", "", "prefix to be added to go package paths for imported proto files")
|
|
||||||
useRequestContext = flag.Bool("request_context", false, "determine whether to use http.Request's context or not")
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseReq(r io.Reader) (*plugin.CodeGeneratorRequest, error) {
|
|
||||||
glog.V(1).Info("Parsing code generator request")
|
|
||||||
input, err := ioutil.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to read code generator request: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req := new(plugin.CodeGeneratorRequest)
|
|
||||||
if err = proto.Unmarshal(input, req); err != nil {
|
|
||||||
glog.Errorf("Failed to unmarshal code generator request: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
glog.V(1).Info("Parsed code generator request")
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
reg := descriptor.NewRegistry()
|
|
||||||
|
|
||||||
glog.V(1).Info("Processing code generator request")
|
|
||||||
req, err := parseReq(os.Stdin)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
if req.Parameter != nil {
|
|
||||||
for _, p := range strings.Split(req.GetParameter(), ",") {
|
|
||||||
spec := strings.SplitN(p, "=", 2)
|
|
||||||
if len(spec) == 1 {
|
|
||||||
if err := flag.CommandLine.Set(spec[0], ""); err != nil {
|
|
||||||
glog.Fatalf("Cannot set flag %s", p)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name, value := spec[0], spec[1]
|
|
||||||
if strings.HasPrefix(name, "M") {
|
|
||||||
reg.AddPkgMap(name[1:], value)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := flag.CommandLine.Set(name, value); err != nil {
|
|
||||||
glog.Fatalf("Cannot set flag %s", p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g := gengateway.New(reg, *useRequestContext)
|
|
||||||
|
|
||||||
reg.SetPrefix(*importPrefix)
|
|
||||||
if err := reg.Load(req); err != nil {
|
|
||||||
emitError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var targets []*descriptor.File
|
|
||||||
for _, target := range req.FileToGenerate {
|
|
||||||
f, err := reg.LookupFile(target)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
targets = append(targets, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := g.Generate(targets)
|
|
||||||
glog.V(1).Info("Processed code generator request")
|
|
||||||
if err != nil {
|
|
||||||
emitError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
emitFiles(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitFiles(out []*plugin.CodeGeneratorResponse_File) {
|
|
||||||
emitResp(&plugin.CodeGeneratorResponse{File: out})
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitError(err error) {
|
|
||||||
emitResp(&plugin.CodeGeneratorResponse{Error: proto.String(err.Error())})
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitResp(resp *plugin.CodeGeneratorResponse) {
|
|
||||||
buf, err := proto.Marshal(resp)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := os.Stdout.Write(buf); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
2
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/doc.go
generated
vendored
2
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/doc.go
generated
vendored
@ -1,2 +0,0 @@
|
|||||||
// Package genswagger provides a code generator for swagger.
|
|
||||||
package genswagger
|
|
58
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/generator.go
generated
vendored
58
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/generator.go
generated
vendored
@ -1,58 +0,0 @@
|
|||||||
package genswagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
gen "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/generator"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errNoTargetService = errors.New("no target service defined in the file")
|
|
||||||
)
|
|
||||||
|
|
||||||
type generator struct {
|
|
||||||
reg *descriptor.Registry
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns a new generator which generates grpc gateway files.
|
|
||||||
func New(reg *descriptor.Registry) gen.Generator {
|
|
||||||
return &generator{reg: reg}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGeneratorResponse_File, error) {
|
|
||||||
var files []*plugin.CodeGeneratorResponse_File
|
|
||||||
for _, file := range targets {
|
|
||||||
glog.V(1).Infof("Processing %s", file.GetName())
|
|
||||||
code, err := applyTemplate(param{File: file, reg: g.reg})
|
|
||||||
if err == errNoTargetService {
|
|
||||||
glog.V(1).Infof("%s: %v", file.GetName(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var formatted bytes.Buffer
|
|
||||||
json.Indent(&formatted, []byte(code), "", " ")
|
|
||||||
|
|
||||||
name := file.GetName()
|
|
||||||
ext := filepath.Ext(name)
|
|
||||||
base := strings.TrimSuffix(name, ext)
|
|
||||||
output := fmt.Sprintf("%s.swagger.json", base)
|
|
||||||
files = append(files, &plugin.CodeGeneratorResponse_File{
|
|
||||||
Name: proto.String(output),
|
|
||||||
Content: proto.String(formatted.String()),
|
|
||||||
})
|
|
||||||
glog.V(1).Infof("Will emit %s", output)
|
|
||||||
}
|
|
||||||
return files, nil
|
|
||||||
}
|
|
835
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go
generated
vendored
835
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go
generated
vendored
@ -1,835 +0,0 @@
|
|||||||
package genswagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
pbdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func listEnumNames(enum *descriptor.Enum) (names []string) {
|
|
||||||
for _, value := range enum.GetValue() {
|
|
||||||
names = append(names, value.GetName())
|
|
||||||
}
|
|
||||||
return names
|
|
||||||
}
|
|
||||||
|
|
||||||
func getEnumDefault(enum *descriptor.Enum) string {
|
|
||||||
for _, value := range enum.GetValue() {
|
|
||||||
if value.GetNumber() == 0 {
|
|
||||||
return value.GetName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// messageToQueryParameters converts a message to a list of swagger query parameters.
|
|
||||||
func messageToQueryParameters(message *descriptor.Message, reg *descriptor.Registry, pathParams []descriptor.Parameter) (params []swaggerParameterObject, err error) {
|
|
||||||
for _, field := range message.Fields {
|
|
||||||
p, err := queryParams(message, field, "", reg, pathParams)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
params = append(params, p...)
|
|
||||||
}
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// queryParams converts a field to a list of swagger query parameters recuresively.
|
|
||||||
func queryParams(message *descriptor.Message, field *descriptor.Field, prefix string, reg *descriptor.Registry, pathParams []descriptor.Parameter) (params []swaggerParameterObject, err error) {
|
|
||||||
// make sure the parameter is not already listed as a path parameter
|
|
||||||
for _, pathParam := range pathParams {
|
|
||||||
if pathParam.Target == field {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
schema := schemaOfField(field, reg)
|
|
||||||
fieldType := field.GetTypeName()
|
|
||||||
if message.File != nil {
|
|
||||||
comments := fieldProtoComments(reg, message, field)
|
|
||||||
if err := updateSwaggerDataFromComments(&schema, comments); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnum := field.GetType() == pbdescriptor.FieldDescriptorProto_TYPE_ENUM
|
|
||||||
items := schema.Items
|
|
||||||
if schema.Type != "" || isEnum {
|
|
||||||
if schema.Type == "object" {
|
|
||||||
return nil, nil // TODO: currently, mapping object in query parameter is not supported
|
|
||||||
}
|
|
||||||
if items != nil && (items.Type == "" || items.Type == "object") && !isEnum {
|
|
||||||
return nil, nil // TODO: currently, mapping object in query parameter is not supported
|
|
||||||
}
|
|
||||||
desc := schema.Description
|
|
||||||
if schema.Title != "" { // merge title because title of parameter object will be ignored
|
|
||||||
desc = strings.TrimSpace(schema.Title + ". " + schema.Description)
|
|
||||||
}
|
|
||||||
param := swaggerParameterObject{
|
|
||||||
Name: prefix + field.GetName(),
|
|
||||||
Description: desc,
|
|
||||||
In: "query",
|
|
||||||
Type: schema.Type,
|
|
||||||
Items: schema.Items,
|
|
||||||
Format: schema.Format,
|
|
||||||
}
|
|
||||||
if isEnum {
|
|
||||||
enum, err := reg.LookupEnum("", fieldType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unknown enum type %s", fieldType)
|
|
||||||
}
|
|
||||||
if items != nil { // array
|
|
||||||
param.Items = &swaggerItemsObject{
|
|
||||||
Type: "string",
|
|
||||||
Enum: listEnumNames(enum),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
param.Type = "string"
|
|
||||||
param.Enum = listEnumNames(enum)
|
|
||||||
param.Default = getEnumDefault(enum)
|
|
||||||
}
|
|
||||||
valueComments := enumValueProtoComments(reg, enum)
|
|
||||||
if valueComments != "" {
|
|
||||||
param.Description = strings.TrimLeft(param.Description+"\n\n "+valueComments, "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return []swaggerParameterObject{param}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// nested type, recurse
|
|
||||||
msg, err := reg.LookupMsg("", fieldType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unknown message type %s", fieldType)
|
|
||||||
}
|
|
||||||
for _, nestedField := range msg.Fields {
|
|
||||||
p, err := queryParams(msg, nestedField, prefix+field.GetName()+".", reg, pathParams)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
params = append(params, p...)
|
|
||||||
}
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// findServicesMessagesAndEnumerations discovers all messages and enums defined in the RPC methods of the service.
|
|
||||||
func findServicesMessagesAndEnumerations(s []*descriptor.Service, reg *descriptor.Registry, m messageMap, e enumMap) {
|
|
||||||
for _, svc := range s {
|
|
||||||
for _, meth := range svc.Methods {
|
|
||||||
m[fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)] = meth.RequestType
|
|
||||||
findNestedMessagesAndEnumerations(meth.RequestType, reg, m, e)
|
|
||||||
m[fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)] = meth.ResponseType
|
|
||||||
findNestedMessagesAndEnumerations(meth.ResponseType, reg, m, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// findNestedMessagesAndEnumerations those can be generated by the services.
|
|
||||||
func findNestedMessagesAndEnumerations(message *descriptor.Message, reg *descriptor.Registry, m messageMap, e enumMap) {
|
|
||||||
// Iterate over all the fields that
|
|
||||||
for _, t := range message.Fields {
|
|
||||||
fieldType := t.GetTypeName()
|
|
||||||
// If the type is an empty string then it is a proto primitive
|
|
||||||
if fieldType != "" {
|
|
||||||
if _, ok := m[fieldType]; !ok {
|
|
||||||
msg, err := reg.LookupMsg("", fieldType)
|
|
||||||
if err != nil {
|
|
||||||
enum, err := reg.LookupEnum("", fieldType)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
e[fieldType] = enum
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
m[fieldType] = msg
|
|
||||||
findNestedMessagesAndEnumerations(msg, reg, m, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, reg *descriptor.Registry) {
|
|
||||||
for name, msg := range messages {
|
|
||||||
switch name {
|
|
||||||
case ".google.protobuf.Timestamp":
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if opt := msg.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
schema := swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Type: "object",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
msgComments := protoComments(reg, msg.File, msg.Outers, "MessageType", int32(msg.Index))
|
|
||||||
if err := updateSwaggerDataFromComments(&schema, msgComments); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, f := range msg.Fields {
|
|
||||||
fieldValue := schemaOfField(f, reg)
|
|
||||||
comments := fieldProtoComments(reg, msg, f)
|
|
||||||
if err := updateSwaggerDataFromComments(&fieldValue, comments); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
schema.Properties = append(schema.Properties, keyVal{f.GetName(), fieldValue})
|
|
||||||
}
|
|
||||||
d[fullyQualifiedNameToSwaggerName(msg.FQMN(), reg)] = schema
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// schemaOfField returns a swagger Schema Object for a protobuf field.
|
|
||||||
func schemaOfField(f *descriptor.Field, reg *descriptor.Registry) swaggerSchemaObject {
|
|
||||||
const (
|
|
||||||
singular = 0
|
|
||||||
array = 1
|
|
||||||
object = 2
|
|
||||||
)
|
|
||||||
var (
|
|
||||||
core schemaCore
|
|
||||||
aggregate int
|
|
||||||
)
|
|
||||||
|
|
||||||
fd := f.FieldDescriptorProto
|
|
||||||
if m, err := reg.LookupMsg("", f.GetTypeName()); err == nil {
|
|
||||||
if opt := m.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry {
|
|
||||||
fd = m.GetField()[1]
|
|
||||||
aggregate = object
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if fd.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
aggregate = array
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ft := fd.GetType(); ft {
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_ENUM, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE, pbdescriptor.FieldDescriptorProto_TYPE_GROUP:
|
|
||||||
if fd.GetTypeName() == ".google.protobuf.Timestamp" && pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE == ft {
|
|
||||||
core = schemaCore{
|
|
||||||
Type: "string",
|
|
||||||
Format: "date-time",
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
core = schemaCore{
|
|
||||||
Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(fd.GetTypeName(), reg),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
ftype, format, ok := primitiveSchema(ft)
|
|
||||||
if ok {
|
|
||||||
core = schemaCore{Type: ftype, Format: format}
|
|
||||||
} else {
|
|
||||||
core = schemaCore{Type: ft.String(), Format: "UNKNOWN"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch aggregate {
|
|
||||||
case array:
|
|
||||||
return swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Type: "array",
|
|
||||||
Items: (*swaggerItemsObject)(&core),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
case object:
|
|
||||||
return swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Type: "object",
|
|
||||||
},
|
|
||||||
AdditionalProperties: &swaggerSchemaObject{schemaCore: core},
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return swaggerSchemaObject{schemaCore: core}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// primitiveSchema returns a pair of "Type" and "Format" in JSON Schema for
|
|
||||||
// the given primitive field type.
|
|
||||||
// The last return parameter is true iff the field type is actually primitive.
|
|
||||||
func primitiveSchema(t pbdescriptor.FieldDescriptorProto_Type) (ftype, format string, ok bool) {
|
|
||||||
switch t {
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
|
||||||
return "number", "double", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_FLOAT:
|
|
||||||
return "number", "float", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_INT64:
|
|
||||||
return "string", "int64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_UINT64:
|
|
||||||
// 64bit integer types are marshaled as string in the default JSONPb marshaler.
|
|
||||||
// TODO(yugui) Add an option to declare 64bit integers as int64.
|
|
||||||
//
|
|
||||||
// NOTE: uint64 is not a predefined format of integer type in Swagger spec.
|
|
||||||
// So we cannot expect that uint64 is commonly supported by swagger processor.
|
|
||||||
return "string", "uint64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_INT32:
|
|
||||||
return "integer", "int32", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_FIXED64:
|
|
||||||
// Ditto.
|
|
||||||
return "string", "uint64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_FIXED32:
|
|
||||||
// Ditto.
|
|
||||||
return "integer", "int64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_BOOL:
|
|
||||||
return "boolean", "boolean", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_STRING:
|
|
||||||
// NOTE: in swagger specifition, format should be empty on string type
|
|
||||||
return "string", "", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_BYTES:
|
|
||||||
return "string", "byte", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_UINT32:
|
|
||||||
// Ditto.
|
|
||||||
return "integer", "int64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
|
||||||
return "integer", "int32", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
|
||||||
return "string", "int64", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_SINT32:
|
|
||||||
return "integer", "int32", true
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_SINT64:
|
|
||||||
return "string", "int64", true
|
|
||||||
default:
|
|
||||||
return "", "", false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// renderEnumerationsAsDefinition inserts enums into the definitions object.
|
|
||||||
func renderEnumerationsAsDefinition(enums enumMap, d swaggerDefinitionsObject, reg *descriptor.Registry) {
|
|
||||||
for _, enum := range enums {
|
|
||||||
enumComments := protoComments(reg, enum.File, enum.Outers, "EnumType", int32(enum.Index))
|
|
||||||
|
|
||||||
// it may be necessary to sort the result of the GetValue function.
|
|
||||||
enumNames := listEnumNames(enum)
|
|
||||||
defaultValue := getEnumDefault(enum)
|
|
||||||
valueComments := enumValueProtoComments(reg, enum)
|
|
||||||
if valueComments != "" {
|
|
||||||
enumComments = strings.TrimLeft(enumComments+"\n\n "+valueComments, "\n")
|
|
||||||
}
|
|
||||||
enumSchemaObject := swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Type: "string",
|
|
||||||
Enum: enumNames,
|
|
||||||
Default: defaultValue,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if err := updateSwaggerDataFromComments(&enumSchemaObject, enumComments); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
d[fullyQualifiedNameToSwaggerName(enum.FQEN(), reg)] = enumSchemaObject
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take in a FQMN or FQEN and return a swagger safe version of the FQMN
|
|
||||||
func fullyQualifiedNameToSwaggerName(fqn string, reg *descriptor.Registry) string {
|
|
||||||
return resolveFullyQualifiedNameToSwaggerName(fqn, append(reg.GetAllFQMNs(), reg.GetAllFQENs()...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take the names of every proto and "uniq-ify" them. The idea is to produce a
|
|
||||||
// set of names that meet a couple of conditions. They must be stable, they
|
|
||||||
// must be unique, and they must be shorter than the FQN.
|
|
||||||
//
|
|
||||||
// This likely could be made better. This will always generate the same names
|
|
||||||
// but may not always produce optimal names. This is a reasonably close
|
|
||||||
// approximation of what they should look like in most cases.
|
|
||||||
func resolveFullyQualifiedNameToSwaggerName(fqn string, messages []string) string {
|
|
||||||
packagesByDepth := make(map[int][][]string)
|
|
||||||
uniqueNames := make(map[string]string)
|
|
||||||
|
|
||||||
hierarchy := func(pkg string) []string {
|
|
||||||
return strings.Split(pkg, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range messages {
|
|
||||||
h := hierarchy(p)
|
|
||||||
for depth := range h {
|
|
||||||
if _, ok := packagesByDepth[depth]; !ok {
|
|
||||||
packagesByDepth[depth] = make([][]string, 0)
|
|
||||||
}
|
|
||||||
packagesByDepth[depth] = append(packagesByDepth[depth], h[len(h)-depth:])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count := func(list [][]string, item []string) int {
|
|
||||||
i := 0
|
|
||||||
for _, element := range list {
|
|
||||||
if reflect.DeepEqual(element, item) {
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range messages {
|
|
||||||
h := hierarchy(p)
|
|
||||||
for depth := 0; depth < len(h); depth++ {
|
|
||||||
if count(packagesByDepth[depth], h[len(h)-depth:]) == 1 {
|
|
||||||
uniqueNames[p] = strings.Join(h[len(h)-depth-1:], "")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if depth == len(h)-1 {
|
|
||||||
uniqueNames[p] = strings.Join(h, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uniqueNames[fqn]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swagger expects paths of the form /path/{string_value} but grpc-gateway paths are expected to be of the form /path/{string_value=strprefix/*}. This should reformat it correctly.
|
|
||||||
func templateToSwaggerPath(path string) string {
|
|
||||||
// It seems like the right thing to do here is to just use
|
|
||||||
// strings.Split(path, "/") but that breaks badly when you hit a url like
|
|
||||||
// /{my_field=prefix/*}/ and end up with 2 sections representing my_field.
|
|
||||||
// Instead do the right thing and write a small pushdown (counter) automata
|
|
||||||
// for it.
|
|
||||||
var parts []string
|
|
||||||
depth := 0
|
|
||||||
buffer := ""
|
|
||||||
for _, char := range path {
|
|
||||||
switch char {
|
|
||||||
case '{':
|
|
||||||
// Push on the stack
|
|
||||||
depth++
|
|
||||||
buffer += string(char)
|
|
||||||
break
|
|
||||||
case '}':
|
|
||||||
if depth == 0 {
|
|
||||||
panic("Encountered } without matching { before it.")
|
|
||||||
}
|
|
||||||
// Pop from the stack
|
|
||||||
depth--
|
|
||||||
buffer += "}"
|
|
||||||
case '/':
|
|
||||||
if depth == 0 {
|
|
||||||
parts = append(parts, buffer)
|
|
||||||
buffer = ""
|
|
||||||
// Since the stack was empty when we hit the '/' we are done with this
|
|
||||||
// section.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
buffer += string(char)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now append the last element to parts
|
|
||||||
parts = append(parts, buffer)
|
|
||||||
|
|
||||||
// Parts is now an array of segments of the path. Interestingly, since the
|
|
||||||
// syntax for this subsection CAN be handled by a regexp since it has no
|
|
||||||
// memory.
|
|
||||||
re := regexp.MustCompile("{([a-zA-Z][a-zA-Z0-9_.]*).*}")
|
|
||||||
for index, part := range parts {
|
|
||||||
parts[index] = re.ReplaceAllString(part, "{$1}")
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(parts, "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderServices(services []*descriptor.Service, paths swaggerPathsObject, reg *descriptor.Registry) error {
|
|
||||||
// Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array.
|
|
||||||
for svcIdx, svc := range services {
|
|
||||||
for methIdx, meth := range svc.Methods {
|
|
||||||
for _, b := range meth.Bindings {
|
|
||||||
// Iterate over all the swagger parameters
|
|
||||||
parameters := swaggerParametersObject{}
|
|
||||||
for _, parameter := range b.PathParams {
|
|
||||||
|
|
||||||
var paramType, paramFormat string
|
|
||||||
switch pt := parameter.Target.GetType(); pt {
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_GROUP, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
|
||||||
return fmt.Errorf("only primitive types are allowed in path parameters")
|
|
||||||
case pbdescriptor.FieldDescriptorProto_TYPE_ENUM:
|
|
||||||
paramType = fullyQualifiedNameToSwaggerName(parameter.Target.GetTypeName(), reg)
|
|
||||||
paramFormat = ""
|
|
||||||
default:
|
|
||||||
var ok bool
|
|
||||||
paramType, paramFormat, ok = primitiveSchema(pt)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("unknown field type %v", pt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters = append(parameters, swaggerParameterObject{
|
|
||||||
Name: parameter.String(),
|
|
||||||
In: "path",
|
|
||||||
Required: true,
|
|
||||||
// Parameters in gRPC-Gateway can only be strings?
|
|
||||||
Type: paramType,
|
|
||||||
Format: paramFormat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Now check if there is a body parameter
|
|
||||||
if b.Body != nil {
|
|
||||||
var schema swaggerSchemaObject
|
|
||||||
|
|
||||||
if len(b.Body.FieldPath) == 0 {
|
|
||||||
schema = swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lastField := b.Body.FieldPath[len(b.Body.FieldPath)-1]
|
|
||||||
schema = schemaOfField(lastField.Target, reg)
|
|
||||||
}
|
|
||||||
|
|
||||||
desc := ""
|
|
||||||
if meth.GetClientStreaming() {
|
|
||||||
desc = "(streaming inputs)"
|
|
||||||
}
|
|
||||||
parameters = append(parameters, swaggerParameterObject{
|
|
||||||
Name: "body",
|
|
||||||
Description: desc,
|
|
||||||
In: "body",
|
|
||||||
Required: true,
|
|
||||||
Schema: &schema,
|
|
||||||
})
|
|
||||||
} else if b.HTTPMethod == "GET" {
|
|
||||||
// add the parameters to the query string
|
|
||||||
queryParams, err := messageToQueryParameters(meth.RequestType, reg, b.PathParams)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
parameters = append(parameters, queryParams...)
|
|
||||||
}
|
|
||||||
|
|
||||||
pathItemObject, ok := paths[templateToSwaggerPath(b.PathTmpl.Template)]
|
|
||||||
if !ok {
|
|
||||||
pathItemObject = swaggerPathItemObject{}
|
|
||||||
}
|
|
||||||
|
|
||||||
methProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.ServiceDescriptorProto)(nil)), "Method")
|
|
||||||
desc := ""
|
|
||||||
if meth.GetServerStreaming() {
|
|
||||||
desc += "(streaming responses)"
|
|
||||||
}
|
|
||||||
operationObject := &swaggerOperationObject{
|
|
||||||
Tags: []string{svc.GetName()},
|
|
||||||
OperationID: fmt.Sprintf("%s", meth.GetName()),
|
|
||||||
Parameters: parameters,
|
|
||||||
Responses: swaggerResponsesObject{
|
|
||||||
"200": swaggerResponseObject{
|
|
||||||
Description: desc,
|
|
||||||
Schema: swaggerSchemaObject{
|
|
||||||
schemaCore: schemaCore{
|
|
||||||
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
methComments := protoComments(reg, svc.File, nil, "Service", int32(svcIdx), methProtoPath, int32(methIdx))
|
|
||||||
if err := updateSwaggerDataFromComments(operationObject, methComments); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch b.HTTPMethod {
|
|
||||||
case "DELETE":
|
|
||||||
pathItemObject.Delete = operationObject
|
|
||||||
break
|
|
||||||
case "GET":
|
|
||||||
pathItemObject.Get = operationObject
|
|
||||||
break
|
|
||||||
case "POST":
|
|
||||||
pathItemObject.Post = operationObject
|
|
||||||
break
|
|
||||||
case "PUT":
|
|
||||||
pathItemObject.Put = operationObject
|
|
||||||
break
|
|
||||||
case "PATCH":
|
|
||||||
pathItemObject.Patch = operationObject
|
|
||||||
break
|
|
||||||
}
|
|
||||||
paths[templateToSwaggerPath(b.PathTmpl.Template)] = pathItemObject
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success! return nil on the error object
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function is called with a param which contains the entire definition of a method.
|
|
||||||
func applyTemplate(p param) (string, error) {
|
|
||||||
// Create the basic template object. This is the object that everything is
|
|
||||||
// defined off of.
|
|
||||||
s := swaggerObject{
|
|
||||||
// Swagger 2.0 is the version of this document
|
|
||||||
Swagger: "2.0",
|
|
||||||
Schemes: []string{"http", "https"},
|
|
||||||
Consumes: []string{"application/json"},
|
|
||||||
Produces: []string{"application/json"},
|
|
||||||
Paths: make(swaggerPathsObject),
|
|
||||||
Definitions: make(swaggerDefinitionsObject),
|
|
||||||
Info: swaggerInfoObject{
|
|
||||||
Title: *p.File.Name,
|
|
||||||
Version: "version not set",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loops through all the services and their exposed GET/POST/PUT/DELETE definitions
|
|
||||||
// and create entries for all of them.
|
|
||||||
if err := renderServices(p.Services, s.Paths, p.reg); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find all the service's messages and enumerations that are defined (recursively) and then
|
|
||||||
// write their request and response types out as definition objects.
|
|
||||||
m := messageMap{}
|
|
||||||
e := enumMap{}
|
|
||||||
findServicesMessagesAndEnumerations(p.Services, p.reg, m, e)
|
|
||||||
renderMessagesAsDefinition(m, s.Definitions, p.reg)
|
|
||||||
renderEnumerationsAsDefinition(e, s.Definitions, p.reg)
|
|
||||||
|
|
||||||
// File itself might have some comments and metadata.
|
|
||||||
packageProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.FileDescriptorProto)(nil)), "Package")
|
|
||||||
packageComments := protoComments(p.reg, p.File, nil, "Package", packageProtoPath)
|
|
||||||
if err := updateSwaggerDataFromComments(&s, packageComments); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We now have rendered the entire swagger object. Write the bytes out to a
|
|
||||||
// string so it can be written to disk.
|
|
||||||
var w bytes.Buffer
|
|
||||||
enc := json.NewEncoder(&w)
|
|
||||||
enc.Encode(&s)
|
|
||||||
|
|
||||||
return w.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateSwaggerDataFromComments updates a Swagger object based on a comment
|
|
||||||
// from the proto file.
|
|
||||||
//
|
|
||||||
// First paragraph of a comment is used for summary. Remaining paragraphs of a
|
|
||||||
// comment are used for description. If 'Summary' field is not present on the
|
|
||||||
// passed swaggerObject, the summary and description are joined by \n\n.
|
|
||||||
//
|
|
||||||
// If there is a field named 'Info', its 'Summary' and 'Description' fields
|
|
||||||
// will be updated instead.
|
|
||||||
//
|
|
||||||
// If there is no 'Summary', the same behavior will be attempted on 'Title',
|
|
||||||
// but only if the last character is not a period.
|
|
||||||
func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) error {
|
|
||||||
if len(comment) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out what to apply changes to.
|
|
||||||
swaggerObjectValue := reflect.ValueOf(swaggerObject)
|
|
||||||
infoObjectValue := swaggerObjectValue.Elem().FieldByName("Info")
|
|
||||||
if !infoObjectValue.CanSet() {
|
|
||||||
// No such field? Apply summary and description directly to
|
|
||||||
// passed object.
|
|
||||||
infoObjectValue = swaggerObjectValue.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out which properties to update.
|
|
||||||
summaryValue := infoObjectValue.FieldByName("Summary")
|
|
||||||
descriptionValue := infoObjectValue.FieldByName("Description")
|
|
||||||
usingTitle := false
|
|
||||||
if !summaryValue.CanSet() {
|
|
||||||
summaryValue = infoObjectValue.FieldByName("Title")
|
|
||||||
usingTitle = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is a summary (or summary-equivalent), use the first
|
|
||||||
// paragraph as summary, and the rest as description.
|
|
||||||
if summaryValue.CanSet() {
|
|
||||||
paragraphs := strings.Split(comment, "\n\n")
|
|
||||||
|
|
||||||
summary := strings.TrimSpace(paragraphs[0])
|
|
||||||
description := strings.TrimSpace(strings.Join(paragraphs[1:], "\n\n"))
|
|
||||||
if !usingTitle || summary == "" || summary[len(summary)-1] != '.' {
|
|
||||||
if len(summary) > 0 {
|
|
||||||
summaryValue.Set(reflect.ValueOf(summary))
|
|
||||||
}
|
|
||||||
if len(description) > 0 {
|
|
||||||
if !descriptionValue.CanSet() {
|
|
||||||
return fmt.Errorf("Encountered object type with a summary, but no description")
|
|
||||||
}
|
|
||||||
descriptionValue.Set(reflect.ValueOf(description))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There was no summary field on the swaggerObject. Try to apply the
|
|
||||||
// whole comment into description.
|
|
||||||
if descriptionValue.CanSet() {
|
|
||||||
descriptionValue.Set(reflect.ValueOf(comment))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("no description nor summary property")
|
|
||||||
}
|
|
||||||
|
|
||||||
func fieldProtoComments(reg *descriptor.Registry, msg *descriptor.Message, field *descriptor.Field) string {
|
|
||||||
protoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.DescriptorProto)(nil)), "Field")
|
|
||||||
for i, f := range msg.Fields {
|
|
||||||
if f == field {
|
|
||||||
return protoComments(reg, msg.File, msg.Outers, "MessageType", int32(msg.Index), protoPath, int32(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func enumValueProtoComments(reg *descriptor.Registry, enum *descriptor.Enum) string {
|
|
||||||
protoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.EnumDescriptorProto)(nil)), "Value")
|
|
||||||
var comments []string
|
|
||||||
for idx, value := range enum.GetValue() {
|
|
||||||
name := value.GetName()
|
|
||||||
str := protoComments(reg, enum.File, enum.Outers, "EnumType", int32(enum.Index), protoPath, int32(idx))
|
|
||||||
if str != "" {
|
|
||||||
comments = append(comments, name+": "+str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(comments) > 0 {
|
|
||||||
return "- " + strings.Join(comments, "\n - ")
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func protoComments(reg *descriptor.Registry, file *descriptor.File, outers []string, typeName string, typeIndex int32, fieldPaths ...int32) string {
|
|
||||||
if file.SourceCodeInfo == nil {
|
|
||||||
// Curious! A file without any source code info.
|
|
||||||
// This could be a test that's providing incomplete
|
|
||||||
// descriptor.File information.
|
|
||||||
//
|
|
||||||
// We could simply return no comments, but panic
|
|
||||||
// could make debugging easier.
|
|
||||||
panic("descriptor.File should not contain nil SourceCodeInfo")
|
|
||||||
}
|
|
||||||
|
|
||||||
outerPaths := make([]int32, len(outers))
|
|
||||||
for i := range outers {
|
|
||||||
location := ""
|
|
||||||
if file.Package != nil {
|
|
||||||
location = file.GetPackage()
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := reg.LookupMsg(location, strings.Join(outers[:i+1], "."))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
outerPaths[i] = int32(msg.Index)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, loc := range file.SourceCodeInfo.Location {
|
|
||||||
if !isProtoPathMatches(loc.Path, outerPaths, typeName, typeIndex, fieldPaths) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
comments := ""
|
|
||||||
if loc.LeadingComments != nil {
|
|
||||||
comments = strings.TrimRight(*loc.LeadingComments, "\n")
|
|
||||||
comments = strings.TrimSpace(comments)
|
|
||||||
// TODO(ivucica): this is a hack to fix "// " being interpreted as "//".
|
|
||||||
// perhaps we should:
|
|
||||||
// - split by \n
|
|
||||||
// - determine if every (but first and last) line begins with " "
|
|
||||||
// - trim every line only if that is the case
|
|
||||||
// - join by \n
|
|
||||||
comments = strings.Replace(comments, "\n ", "\n", -1)
|
|
||||||
}
|
|
||||||
return comments
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var messageProtoPath = protoPathIndex(reflect.TypeOf((*pbdescriptor.FileDescriptorProto)(nil)), "MessageType")
|
|
||||||
var nestedProtoPath = protoPathIndex(reflect.TypeOf((*pbdescriptor.DescriptorProto)(nil)), "NestedType")
|
|
||||||
var packageProtoPath = protoPathIndex(reflect.TypeOf((*pbdescriptor.FileDescriptorProto)(nil)), "Package")
|
|
||||||
|
|
||||||
func isProtoPathMatches(paths []int32, outerPaths []int32, typeName string, typeIndex int32, fieldPaths []int32) bool {
|
|
||||||
if typeName == "Package" && typeIndex == packageProtoPath {
|
|
||||||
// path for package comments is just [2], and all the other processing
|
|
||||||
// is too complex for it.
|
|
||||||
if len(paths) == 0 || typeIndex != paths[0] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(paths) != len(outerPaths)*2+2+len(fieldPaths) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
typeNameDescriptor := reflect.TypeOf((*pbdescriptor.FileDescriptorProto)(nil))
|
|
||||||
if len(outerPaths) > 0 {
|
|
||||||
if paths[0] != messageProtoPath || paths[1] != outerPaths[0] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
paths = paths[2:]
|
|
||||||
outerPaths = outerPaths[1:]
|
|
||||||
|
|
||||||
for i, v := range outerPaths {
|
|
||||||
if paths[i*2] != nestedProtoPath || paths[i*2+1] != v {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
paths = paths[len(outerPaths)*2:]
|
|
||||||
|
|
||||||
if typeName == "MessageType" {
|
|
||||||
typeName = "NestedType"
|
|
||||||
}
|
|
||||||
typeNameDescriptor = reflect.TypeOf((*pbdescriptor.DescriptorProto)(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
if paths[0] != protoPathIndex(typeNameDescriptor, typeName) || paths[1] != typeIndex {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
paths = paths[2:]
|
|
||||||
|
|
||||||
for i, v := range fieldPaths {
|
|
||||||
if paths[i] != v {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// protoPathIndex returns a path component for google.protobuf.descriptor.SourceCode_Location.
|
|
||||||
//
|
|
||||||
// Specifically, it returns an id as generated from descriptor proto which
|
|
||||||
// can be used to determine what type the id following it in the path is.
|
|
||||||
// For example, if we are trying to locate comments related to a field named
|
|
||||||
// `Address` in a message named `Person`, the path will be:
|
|
||||||
//
|
|
||||||
// [4, a, 2, b]
|
|
||||||
//
|
|
||||||
// While `a` gets determined by the order in which the messages appear in
|
|
||||||
// the proto file, and `b` is the field index specified in the proto
|
|
||||||
// file itself, the path actually needs to specify that `a` refers to a
|
|
||||||
// message and not, say, a service; and that `b` refers to a field and not
|
|
||||||
// an option.
|
|
||||||
//
|
|
||||||
// protoPathIndex figures out the values 4 and 2 in the above example. Because
|
|
||||||
// messages are top level objects, the value of 4 comes from field id for
|
|
||||||
// `MessageType` inside `google.protobuf.descriptor.FileDescriptor` message.
|
|
||||||
// This field has a message type `google.protobuf.descriptor.DescriptorProto`.
|
|
||||||
// And inside message `DescriptorProto`, there is a field named `Field` with id
|
|
||||||
// 2.
|
|
||||||
//
|
|
||||||
// Some code generators seem to be hardcoding these values; this method instead
|
|
||||||
// interprets them from `descriptor.proto`-derived Go source as necessary.
|
|
||||||
func protoPathIndex(descriptorType reflect.Type, what string) int32 {
|
|
||||||
field, ok := descriptorType.Elem().FieldByName(what)
|
|
||||||
if !ok {
|
|
||||||
panic(fmt.Errorf("could not find protobuf descriptor type id for %s", what))
|
|
||||||
}
|
|
||||||
pbtag := field.Tag.Get("protobuf")
|
|
||||||
if pbtag == "" {
|
|
||||||
panic(fmt.Errorf("no Go tag 'protobuf' on protobuf descriptor for %s", what))
|
|
||||||
}
|
|
||||||
path, err := strconv.Atoi(strings.Split(pbtag, ",")[1])
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("protobuf descriptor id for %s cannot be converted to a number: %s", what, err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
return int32(path)
|
|
||||||
}
|
|
661
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template_test.go
generated
vendored
661
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template_test.go
generated
vendored
@ -1,661 +0,0 @@
|
|||||||
package genswagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
protodescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule"
|
|
||||||
)
|
|
||||||
|
|
||||||
func crossLinkFixture(f *descriptor.File) *descriptor.File {
|
|
||||||
for _, m := range f.Messages {
|
|
||||||
m.File = f
|
|
||||||
}
|
|
||||||
for _, svc := range f.Services {
|
|
||||||
svc.File = f
|
|
||||||
for _, m := range svc.Methods {
|
|
||||||
m.Service = svc
|
|
||||||
for _, b := range m.Bindings {
|
|
||||||
b.Method = m
|
|
||||||
for _, param := range b.PathParams {
|
|
||||||
param.Method = m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMessageToQueryParameters(t *testing.T) {
|
|
||||||
type test struct {
|
|
||||||
MsgDescs []*protodescriptor.DescriptorProto
|
|
||||||
Message string
|
|
||||||
Params []swaggerParameterObject
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []test{
|
|
||||||
{
|
|
||||||
MsgDescs: []*protodescriptor.DescriptorProto{
|
|
||||||
&protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("a"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_STRING.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("b"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_DOUBLE.Enum(),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Message: "ExampleMessage",
|
|
||||||
Params: []swaggerParameterObject{
|
|
||||||
swaggerParameterObject{
|
|
||||||
Name: "a",
|
|
||||||
In: "query",
|
|
||||||
Required: false,
|
|
||||||
Type: "string",
|
|
||||||
},
|
|
||||||
swaggerParameterObject{
|
|
||||||
Name: "b",
|
|
||||||
In: "query",
|
|
||||||
Required: false,
|
|
||||||
Type: "number",
|
|
||||||
Format: "double",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgDescs: []*protodescriptor.DescriptorProto{
|
|
||||||
&protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("nested"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String(".example.Nested"),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("Nested"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("a"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_STRING.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("deep"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String(".example.Nested.DeepNested"),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
NestedType: []*protodescriptor.DescriptorProto{{
|
|
||||||
Name: proto.String("DeepNested"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("b"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_STRING.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("c"),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_ENUM.Enum(),
|
|
||||||
TypeName: proto.String(".example.Nested.DeepNested.DeepEnum"),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
EnumType: []*protodescriptor.EnumDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("DeepEnum"),
|
|
||||||
Value: []*protodescriptor.EnumValueDescriptorProto{
|
|
||||||
{Name: proto.String("FALSE"), Number: proto.Int32(0)},
|
|
||||||
{Name: proto.String("TRUE"), Number: proto.Int32(1)},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Message: "ExampleMessage",
|
|
||||||
Params: []swaggerParameterObject{
|
|
||||||
swaggerParameterObject{
|
|
||||||
Name: "nested.a",
|
|
||||||
In: "query",
|
|
||||||
Required: false,
|
|
||||||
Type: "string",
|
|
||||||
},
|
|
||||||
swaggerParameterObject{
|
|
||||||
Name: "nested.deep.b",
|
|
||||||
In: "query",
|
|
||||||
Required: false,
|
|
||||||
Type: "string",
|
|
||||||
},
|
|
||||||
swaggerParameterObject{
|
|
||||||
Name: "nested.deep.c",
|
|
||||||
In: "query",
|
|
||||||
Required: false,
|
|
||||||
Type: "string",
|
|
||||||
Enum: []string{"FALSE", "TRUE"},
|
|
||||||
Default: "FALSE",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
reg := descriptor.NewRegistry()
|
|
||||||
msgs := []*descriptor.Message{}
|
|
||||||
for _, msgdesc := range test.MsgDescs {
|
|
||||||
msgs = append(msgs, &descriptor.Message{DescriptorProto: msgdesc})
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
SourceCodeInfo: &protodescriptor.SourceCodeInfo{},
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
Dependency: []string{},
|
|
||||||
MessageType: test.MsgDescs,
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: msgs,
|
|
||||||
}
|
|
||||||
reg.Load(&plugin.CodeGeneratorRequest{
|
|
||||||
ProtoFile: []*protodescriptor.FileDescriptorProto{file.FileDescriptorProto},
|
|
||||||
})
|
|
||||||
|
|
||||||
message, err := reg.LookupMsg("", ".example."+test.Message)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to lookup message: %s", err)
|
|
||||||
}
|
|
||||||
params, err := messageToQueryParameters(message, reg, []descriptor.Parameter{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to convert message to query parameters: %s", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(params, test.Params) {
|
|
||||||
t.Errorf("expected %v, got %v", test.Params, params)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateSimple(t *testing.T) {
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Example"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
SourceCodeInfo: &protodescriptor.SourceCodeInfo{},
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
Dependency: []string{"a.example/b/c.proto", "a.example/d/e.proto"},
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "GET",
|
|
||||||
Body: &descriptor.Body{FieldPath: nil},
|
|
||||||
PathTmpl: httprule.Template{
|
|
||||||
Version: 1,
|
|
||||||
OpCodes: []int{0, 0},
|
|
||||||
Template: "/v1/echo", // TODO(achew22): Figure out what this should really be
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
result, err := applyTemplate(param{File: crossLinkFixture(&file), reg: descriptor.NewRegistry()})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
got := new(swaggerObject)
|
|
||||||
err = json.Unmarshal([]byte(result), got)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("json.Unmarshal(%s) failed with %v; want success", result, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if want, is, name := "2.0", got.Swagger, "Swagger"; !reflect.DeepEqual(is, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
|
|
||||||
}
|
|
||||||
if want, is, name := "", got.BasePath, "BasePath"; !reflect.DeepEqual(is, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
|
|
||||||
}
|
|
||||||
if want, is, name := []string{"http", "https"}, got.Schemes, "Schemes"; !reflect.DeepEqual(is, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
|
|
||||||
}
|
|
||||||
if want, is, name := []string{"application/json"}, got.Consumes, "Consumes"; !reflect.DeepEqual(is, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
|
|
||||||
}
|
|
||||||
if want, is, name := []string{"application/json"}, got.Produces, "Produces"; !reflect.DeepEqual(is, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there was a failure, print out the input and the json result for debugging.
|
|
||||||
if t.Failed() {
|
|
||||||
t.Errorf("had: %s", file)
|
|
||||||
t.Errorf("got: %s", result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateRequestWithoutClientStreaming(t *testing.T) {
|
|
||||||
t.Skip()
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("nested"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String("NestedMessage"),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nesteddesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("NestedMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("int32"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_INT32.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("bool"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_BOOL.Enum(),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Echo"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
ClientStreaming: proto.Bool(false),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
|
|
||||||
meth.ServerStreaming = proto.Bool(false)
|
|
||||||
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
nested := &descriptor.Message{
|
|
||||||
DescriptorProto: nesteddesc,
|
|
||||||
}
|
|
||||||
|
|
||||||
nestedField := &descriptor.Field{
|
|
||||||
Message: msg,
|
|
||||||
FieldDescriptorProto: msg.GetField()[0],
|
|
||||||
}
|
|
||||||
intField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[0],
|
|
||||||
}
|
|
||||||
boolField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[1],
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
SourceCodeInfo: &protodescriptor.SourceCodeInfo{},
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc, nesteddesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg, nested},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "POST",
|
|
||||||
PathTmpl: httprule.Template{
|
|
||||||
Version: 1,
|
|
||||||
OpCodes: []int{0, 0},
|
|
||||||
Template: "/v1/echo", // TODO(achew): Figure out what this hsould really be
|
|
||||||
},
|
|
||||||
PathParams: []descriptor.Parameter{
|
|
||||||
{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "int32",
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Body: &descriptor.Body{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "bool",
|
|
||||||
Target: boolField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
result, err := applyTemplate(param{File: crossLinkFixture(&file)})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var obj swaggerObject
|
|
||||||
err = json.Unmarshal([]byte(result), &obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if want, got := "2.0", obj.Swagger; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).Swagger = %s want to be %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want, got := "", obj.BasePath; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).BasePath = %s want to be %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want, got := []string{"http", "https"}, obj.Schemes; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).Schemes = %s want to be %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want, got := []string{"application/json"}, obj.Consumes; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).Consumes = %s want to be %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want, got := []string{"application/json"}, obj.Produces; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).Produces = %s want to be %s", file, got, want)
|
|
||||||
}
|
|
||||||
if want, got, name := "Generated for ExampleService.Echo - ", obj.Paths["/v1/echo"].Post.Summary, "Paths[/v1/echo].Post.Summary"; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there was a failure, print out the input and the json result for debugging.
|
|
||||||
if t.Failed() {
|
|
||||||
t.Errorf("had: %s", file)
|
|
||||||
t.Errorf("got: %s", result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyTemplateRequestWithClientStreaming(t *testing.T) {
|
|
||||||
t.Skip()
|
|
||||||
msgdesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("ExampleMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("nested"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
|
|
||||||
TypeName: proto.String("NestedMessage"),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nesteddesc := &protodescriptor.DescriptorProto{
|
|
||||||
Name: proto.String("NestedMessage"),
|
|
||||||
Field: []*protodescriptor.FieldDescriptorProto{
|
|
||||||
{
|
|
||||||
Name: proto.String("int32"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_INT32.Enum(),
|
|
||||||
Number: proto.Int32(1),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: proto.String("bool"),
|
|
||||||
Label: protodescriptor.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
|
|
||||||
Type: protodescriptor.FieldDescriptorProto_TYPE_BOOL.Enum(),
|
|
||||||
Number: proto.Int32(2),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
meth := &protodescriptor.MethodDescriptorProto{
|
|
||||||
Name: proto.String("Echo"),
|
|
||||||
InputType: proto.String("ExampleMessage"),
|
|
||||||
OutputType: proto.String("ExampleMessage"),
|
|
||||||
ClientStreaming: proto.Bool(true),
|
|
||||||
ServerStreaming: proto.Bool(true),
|
|
||||||
}
|
|
||||||
svc := &protodescriptor.ServiceDescriptorProto{
|
|
||||||
Name: proto.String("ExampleService"),
|
|
||||||
Method: []*protodescriptor.MethodDescriptorProto{meth},
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := &descriptor.Message{
|
|
||||||
DescriptorProto: msgdesc,
|
|
||||||
}
|
|
||||||
nested := &descriptor.Message{
|
|
||||||
DescriptorProto: nesteddesc,
|
|
||||||
}
|
|
||||||
|
|
||||||
nestedField := &descriptor.Field{
|
|
||||||
Message: msg,
|
|
||||||
FieldDescriptorProto: msg.GetField()[0],
|
|
||||||
}
|
|
||||||
intField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[0],
|
|
||||||
}
|
|
||||||
boolField := &descriptor.Field{
|
|
||||||
Message: nested,
|
|
||||||
FieldDescriptorProto: nested.GetField()[1],
|
|
||||||
}
|
|
||||||
file := descriptor.File{
|
|
||||||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
|
|
||||||
SourceCodeInfo: &protodescriptor.SourceCodeInfo{},
|
|
||||||
Name: proto.String("example.proto"),
|
|
||||||
Package: proto.String("example"),
|
|
||||||
MessageType: []*protodescriptor.DescriptorProto{msgdesc, nesteddesc},
|
|
||||||
Service: []*protodescriptor.ServiceDescriptorProto{svc},
|
|
||||||
},
|
|
||||||
GoPkg: descriptor.GoPackage{
|
|
||||||
Path: "example.com/path/to/example/example.pb",
|
|
||||||
Name: "example_pb",
|
|
||||||
},
|
|
||||||
Messages: []*descriptor.Message{msg, nested},
|
|
||||||
Services: []*descriptor.Service{
|
|
||||||
{
|
|
||||||
ServiceDescriptorProto: svc,
|
|
||||||
Methods: []*descriptor.Method{
|
|
||||||
{
|
|
||||||
MethodDescriptorProto: meth,
|
|
||||||
RequestType: msg,
|
|
||||||
ResponseType: msg,
|
|
||||||
Bindings: []*descriptor.Binding{
|
|
||||||
{
|
|
||||||
HTTPMethod: "POST",
|
|
||||||
PathTmpl: httprule.Template{
|
|
||||||
Version: 1,
|
|
||||||
OpCodes: []int{0, 0},
|
|
||||||
Template: "/v1/echo", // TODO(achew): Figure out what this hsould really be
|
|
||||||
},
|
|
||||||
PathParams: []descriptor.Parameter{
|
|
||||||
{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "int32",
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
Target: intField,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Body: &descriptor.Body{
|
|
||||||
FieldPath: descriptor.FieldPath([]descriptor.FieldPathComponent{
|
|
||||||
{
|
|
||||||
Name: "nested",
|
|
||||||
Target: nestedField,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "bool",
|
|
||||||
Target: boolField,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err := applyTemplate(param{File: crossLinkFixture(&file)})
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("applyTemplate(%#v) should have failed cause swagger doesn't support streaming", file)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTemplateToSwaggerPath(t *testing.T) {
|
|
||||||
var tests = []struct {
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{"/test", "/test"},
|
|
||||||
{"/{test}", "/{test}"},
|
|
||||||
{"/{test=prefix/*}", "/{test}"},
|
|
||||||
{"/{test=prefix/that/has/multiple/parts/to/it/*}", "/{test}"},
|
|
||||||
{"/{test1}/{test2}", "/{test1}/{test2}"},
|
|
||||||
{"/{test1}/{test2}/", "/{test1}/{test2}/"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, data := range tests {
|
|
||||||
actual := templateToSwaggerPath(data.input)
|
|
||||||
if data.expected != actual {
|
|
||||||
t.Errorf("Expected templateToSwaggerPath(%v) = %v, actual: %v", data.input, data.expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveFullyQualifiedNameToSwaggerName(t *testing.T) {
|
|
||||||
var tests = []struct {
|
|
||||||
input string
|
|
||||||
output string
|
|
||||||
listOfFQMNs []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
".a.b.C",
|
|
||||||
"C",
|
|
||||||
[]string{
|
|
||||||
".a.b.C",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
".a.b.C",
|
|
||||||
"abC",
|
|
||||||
[]string{
|
|
||||||
".a.C",
|
|
||||||
".a.b.C",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
".a.b.C",
|
|
||||||
"abC",
|
|
||||||
[]string{
|
|
||||||
".C",
|
|
||||||
".a.C",
|
|
||||||
".a.b.C",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, data := range tests {
|
|
||||||
output := resolveFullyQualifiedNameToSwaggerName(data.input, data.listOfFQMNs)
|
|
||||||
if output != data.output {
|
|
||||||
t.Errorf("Expected fullyQualifiedNameToSwaggerName(%v) to be %s but got %s",
|
|
||||||
data.input, data.output, output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFQMNtoSwaggerName(t *testing.T) {
|
|
||||||
var tests = []struct {
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{"/test", "/test"},
|
|
||||||
{"/{test}", "/{test}"},
|
|
||||||
{"/{test=prefix/*}", "/{test}"},
|
|
||||||
{"/{test=prefix/that/has/multiple/parts/to/it/*}", "/{test}"},
|
|
||||||
{"/{test1}/{test2}", "/{test1}/{test2}"},
|
|
||||||
{"/{test1}/{test2}/", "/{test1}/{test2}/"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, data := range tests {
|
|
||||||
actual := templateToSwaggerPath(data.input)
|
|
||||||
if data.expected != actual {
|
|
||||||
t.Errorf("Expected templateToSwaggerPath(%v) = %v, actual: %v", data.input, data.expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
189
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go
generated
vendored
189
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go
generated
vendored
@ -1,189 +0,0 @@
|
|||||||
package genswagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
type param struct {
|
|
||||||
*descriptor.File
|
|
||||||
reg *descriptor.Registry
|
|
||||||
}
|
|
||||||
|
|
||||||
type binding struct {
|
|
||||||
*descriptor.Binding
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#infoObject
|
|
||||||
type swaggerInfoObject struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
TermsOfService string `json:"termsOfService,omitempty"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
|
|
||||||
Contact *swaggerContactObject `json:"contact,omitempty"`
|
|
||||||
License *swaggerLicenseObject `json:"license,omitempty"`
|
|
||||||
ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#contactObject
|
|
||||||
type swaggerContactObject struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
Email string `json:"email,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#licenseObject
|
|
||||||
type swaggerLicenseObject struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#externalDocumentationObject
|
|
||||||
type swaggerExternalDocumentationObject struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#swaggerObject
|
|
||||||
type swaggerObject struct {
|
|
||||||
Swagger string `json:"swagger"`
|
|
||||||
Info swaggerInfoObject `json:"info"`
|
|
||||||
Host string `json:"host,omitempty"`
|
|
||||||
BasePath string `json:"basePath,omitempty"`
|
|
||||||
Schemes []string `json:"schemes"`
|
|
||||||
Consumes []string `json:"consumes"`
|
|
||||||
Produces []string `json:"produces"`
|
|
||||||
Paths swaggerPathsObject `json:"paths"`
|
|
||||||
Definitions swaggerDefinitionsObject `json:"definitions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#pathsObject
|
|
||||||
type swaggerPathsObject map[string]swaggerPathItemObject
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#pathItemObject
|
|
||||||
type swaggerPathItemObject struct {
|
|
||||||
Get *swaggerOperationObject `json:"get,omitempty"`
|
|
||||||
Delete *swaggerOperationObject `json:"delete,omitempty"`
|
|
||||||
Post *swaggerOperationObject `json:"post,omitempty"`
|
|
||||||
Put *swaggerOperationObject `json:"put,omitempty"`
|
|
||||||
Patch *swaggerOperationObject `json:"patch,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#operationObject
|
|
||||||
type swaggerOperationObject struct {
|
|
||||||
Summary string `json:"summary,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
OperationID string `json:"operationId"`
|
|
||||||
Responses swaggerResponsesObject `json:"responses"`
|
|
||||||
Parameters swaggerParametersObject `json:"parameters,omitempty"`
|
|
||||||
Tags []string `json:"tags,omitempty"`
|
|
||||||
|
|
||||||
ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type swaggerParametersObject []swaggerParameterObject
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#parameterObject
|
|
||||||
type swaggerParameterObject struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
In string `json:"in,omitempty"`
|
|
||||||
Required bool `json:"required"`
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Format string `json:"format,omitempty"`
|
|
||||||
Items *swaggerItemsObject `json:"items,omitempty"`
|
|
||||||
Enum []string `json:"enum,omitempty"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
|
|
||||||
// Or you can explicitly refer to another type. If this is defined all
|
|
||||||
// other fields should be empty
|
|
||||||
Schema *swaggerSchemaObject `json:"schema,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// core part of schema, which is common to itemsObject and schemaObject.
|
|
||||||
// http://swagger.io/specification/#itemsObject
|
|
||||||
type schemaCore struct {
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Format string `json:"format,omitempty"`
|
|
||||||
Ref string `json:"$ref,omitempty"`
|
|
||||||
|
|
||||||
Items *swaggerItemsObject `json:"items,omitempty"`
|
|
||||||
|
|
||||||
// If the item is an enumeration include a list of all the *NAMES* of the
|
|
||||||
// enum values. I'm not sure how well this will work but assuming all enums
|
|
||||||
// start from 0 index it will be great. I don't think that is a good assumption.
|
|
||||||
Enum []string `json:"enum,omitempty"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type swaggerItemsObject schemaCore
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#responsesObject
|
|
||||||
type swaggerResponsesObject map[string]swaggerResponseObject
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#responseObject
|
|
||||||
type swaggerResponseObject struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Schema swaggerSchemaObject `json:"schema"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type keyVal struct {
|
|
||||||
Key string
|
|
||||||
Value interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type swaggerSchemaObjectProperties []keyVal
|
|
||||||
|
|
||||||
func (op swaggerSchemaObjectProperties) MarshalJSON() ([]byte, error) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
buf.WriteString("{")
|
|
||||||
for i, kv := range op {
|
|
||||||
if i != 0 {
|
|
||||||
buf.WriteString(",")
|
|
||||||
}
|
|
||||||
key, err := json.Marshal(kv.Key)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf.Write(key)
|
|
||||||
buf.WriteString(":")
|
|
||||||
val, err := json.Marshal(kv.Value)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf.Write(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.WriteString("}")
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#schemaObject
|
|
||||||
type swaggerSchemaObject struct {
|
|
||||||
schemaCore
|
|
||||||
// Properties can be recursively defined
|
|
||||||
Properties swaggerSchemaObjectProperties `json:"properties,omitempty"`
|
|
||||||
AdditionalProperties *swaggerSchemaObject `json:"additionalProperties,omitempty"`
|
|
||||||
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Title string `json:"title,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#referenceObject
|
|
||||||
type swaggerReferenceObject struct {
|
|
||||||
Ref string `json:"$ref"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://swagger.io/specification/#definitionsObject
|
|
||||||
type swaggerDefinitionsObject map[string]swaggerSchemaObject
|
|
||||||
|
|
||||||
// Internal type mapping from FQMN to descriptor.Message. Used as a set by the
|
|
||||||
// findServiceMessages function.
|
|
||||||
type messageMap map[string]*descriptor.Message
|
|
||||||
|
|
||||||
// Internal type mapping from FQEN to descriptor.Enum. Used as a set by the
|
|
||||||
// findServiceMessages function.
|
|
||||||
type enumMap map[string]*descriptor.Enum
|
|
144
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/main.go
generated
vendored
144
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/main.go
generated
vendored
@ -1,144 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
importPrefix = flag.String("import_prefix", "", "prefix to be added to go package paths for imported proto files")
|
|
||||||
file = flag.String("file", "stdin", "where to load data from")
|
|
||||||
allowDeleteBody = flag.Bool("allow_delete_body", false, "unless set, HTTP DELETE methods may not have a body")
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseReq(r io.Reader) (*plugin.CodeGeneratorRequest, error) {
|
|
||||||
glog.V(1).Info("Parsing code generator request")
|
|
||||||
input, err := ioutil.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to read code generator request: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req := new(plugin.CodeGeneratorRequest)
|
|
||||||
if err = proto.Unmarshal(input, req); err != nil {
|
|
||||||
glog.Errorf("Failed to unmarshal code generator request: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
glog.V(1).Info("Parsed code generator request")
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
reg := descriptor.NewRegistry()
|
|
||||||
|
|
||||||
glog.V(1).Info("Processing code generator request")
|
|
||||||
f := os.Stdin
|
|
||||||
if *file != "stdin" {
|
|
||||||
f, _ = os.Open("input.txt")
|
|
||||||
}
|
|
||||||
req, err := parseReq(f)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
pkgMap := make(map[string]string)
|
|
||||||
if req.Parameter != nil {
|
|
||||||
err := parseReqParam(req.GetParameter(), flag.CommandLine, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatalf("Error parsing flags: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reg.SetPrefix(*importPrefix)
|
|
||||||
reg.SetAllowDeleteBody(*allowDeleteBody)
|
|
||||||
for k, v := range pkgMap {
|
|
||||||
reg.AddPkgMap(k, v)
|
|
||||||
}
|
|
||||||
g := genswagger.New(reg)
|
|
||||||
|
|
||||||
if err := reg.Load(req); err != nil {
|
|
||||||
emitError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var targets []*descriptor.File
|
|
||||||
for _, target := range req.FileToGenerate {
|
|
||||||
f, err := reg.LookupFile(target)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
targets = append(targets, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := g.Generate(targets)
|
|
||||||
glog.V(1).Info("Processed code generator request")
|
|
||||||
if err != nil {
|
|
||||||
emitError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
emitFiles(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitFiles(out []*plugin.CodeGeneratorResponse_File) {
|
|
||||||
emitResp(&plugin.CodeGeneratorResponse{File: out})
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitError(err error) {
|
|
||||||
emitResp(&plugin.CodeGeneratorResponse{Error: proto.String(err.Error())})
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitResp(resp *plugin.CodeGeneratorResponse) {
|
|
||||||
buf, err := proto.Marshal(resp)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := os.Stdout.Write(buf); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseReqParam parses a CodeGeneratorRequest parameter and adds the
|
|
||||||
// extracted values to the given FlagSet and pkgMap. Returns a non-nil
|
|
||||||
// error if setting a flag failed.
|
|
||||||
func parseReqParam(param string, f *flag.FlagSet, pkgMap map[string]string) error {
|
|
||||||
if param == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, p := range strings.Split(param, ",") {
|
|
||||||
spec := strings.SplitN(p, "=", 2)
|
|
||||||
if len(spec) == 1 {
|
|
||||||
if spec[0] == "allow_delete_body" {
|
|
||||||
err := f.Set(spec[0], "true")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Cannot set flag %s: %v", p, err)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err := f.Set(spec[0], "")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Cannot set flag %s: %v", p, err)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name, value := spec[0], spec[1]
|
|
||||||
if strings.HasPrefix(name, "M") {
|
|
||||||
pkgMap[name[1:]] = value
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := f.Set(name, value); err != nil {
|
|
||||||
return fmt.Errorf("Cannot set flag %s: %v", p, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
129
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/main_test.go
generated
vendored
129
vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/main_test.go
generated
vendored
@ -1,129 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestParseReqParam(t *testing.T) {
|
|
||||||
|
|
||||||
f := flag.CommandLine
|
|
||||||
|
|
||||||
// this one must be first - with no leading clearFlags call it
|
|
||||||
// verifies our expectation of default values as we reset by
|
|
||||||
// clearFlags
|
|
||||||
pkgMap := make(map[string]string)
|
|
||||||
expected := map[string]string{}
|
|
||||||
err := parseReqParam("", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 0: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 0: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(false, "stdin", "", t, 0)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{"google/api/annotations.proto": "github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api"}
|
|
||||||
err = parseReqParam("allow_delete_body,file=./foo.pb,import_prefix=/bar/baz,Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 1: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 1: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(true, "./foo.pb", "/bar/baz", t, 1)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{"google/api/annotations.proto": "github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api"}
|
|
||||||
err = parseReqParam("allow_delete_body=true,file=./foo.pb,import_prefix=/bar/baz,Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 2: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 2: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(true, "./foo.pb", "/bar/baz", t, 2)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{"a/b/c.proto": "github.com/x/y/z", "f/g/h.proto": "github.com/1/2/3/"}
|
|
||||||
err = parseReqParam("allow_delete_body=false,Ma/b/c.proto=github.com/x/y/z,Mf/g/h.proto=github.com/1/2/3/", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 3: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 3: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(false, "stdin", "", t, 3)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{}
|
|
||||||
err = parseReqParam("", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 4: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 4: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(false, "stdin", "", t, 4)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{}
|
|
||||||
err = parseReqParam("unknown_param=17", f, pkgMap)
|
|
||||||
if err == nil {
|
|
||||||
t.Error("Test 5: expected parse error not returned")
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 5: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(false, "stdin", "", t, 5)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{}
|
|
||||||
err = parseReqParam("Mfoo", f, pkgMap)
|
|
||||||
if err == nil {
|
|
||||||
t.Error("Test 6: expected parse error not returned")
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 6: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(false, "stdin", "", t, 6)
|
|
||||||
|
|
||||||
clearFlags()
|
|
||||||
pkgMap = make(map[string]string)
|
|
||||||
expected = map[string]string{}
|
|
||||||
err = parseReqParam("allow_delete_body,file,import_prefix", f, pkgMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test 7: unexpected parse error '%v'", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(pkgMap, expected) {
|
|
||||||
t.Errorf("Test 7: pkgMap parse error, expected '%v', got '%v'", expected, pkgMap)
|
|
||||||
}
|
|
||||||
checkFlags(true, "", "", t, 7)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkFlags(allowDeleteV bool, fileV, importPathV string, t *testing.T, tid int) {
|
|
||||||
if *importPrefix != importPathV {
|
|
||||||
t.Errorf("Test %v: import_prefix misparsed, expected '%v', got '%v'", tid, importPathV, *importPrefix)
|
|
||||||
}
|
|
||||||
if *file != fileV {
|
|
||||||
t.Errorf("Test %v: file misparsed, expected '%v', got '%v'", tid, fileV, *file)
|
|
||||||
}
|
|
||||||
if *allowDeleteBody != allowDeleteV {
|
|
||||||
t.Errorf("Test %v: allow_delete_body misparsed, expected '%v', got '%v'", tid, allowDeleteV, *allowDeleteBody)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func clearFlags() {
|
|
||||||
*importPrefix = ""
|
|
||||||
*file = "stdin"
|
|
||||||
*allowDeleteBody = false
|
|
||||||
}
|
|
187
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go
generated
vendored
187
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go
generated
vendored
@ -1,187 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MetadataHeaderPrefix is the http prefix that represents custom metadata
|
|
||||||
// parameters to or from a gRPC call.
|
|
||||||
const MetadataHeaderPrefix = "Grpc-Metadata-"
|
|
||||||
|
|
||||||
// MetadataPrefix is the prefix for grpc-gateway supplied custom metadata fields.
|
|
||||||
const MetadataPrefix = "grpcgateway-"
|
|
||||||
|
|
||||||
// MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to
|
|
||||||
// HTTP headers in a response handled by grpc-gateway
|
|
||||||
const MetadataTrailerPrefix = "Grpc-Trailer-"
|
|
||||||
|
|
||||||
const metadataGrpcTimeout = "Grpc-Timeout"
|
|
||||||
|
|
||||||
const xForwardedFor = "X-Forwarded-For"
|
|
||||||
const xForwardedHost = "X-Forwarded-Host"
|
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound
|
|
||||||
// header isn't present. If the value is 0 the sent `context` will not have a timeout.
|
|
||||||
DefaultContextTimeout = 0 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
AnnotateContext adds context information such as metadata from the request.
|
|
||||||
|
|
||||||
At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For",
|
|
||||||
except that the forwarded destination is not another HTTP service but rather
|
|
||||||
a gRPC service.
|
|
||||||
*/
|
|
||||||
func AnnotateContext(ctx context.Context, req *http.Request) (context.Context, error) {
|
|
||||||
var pairs []string
|
|
||||||
timeout := DefaultContextTimeout
|
|
||||||
if tm := req.Header.Get(metadataGrpcTimeout); tm != "" {
|
|
||||||
var err error
|
|
||||||
timeout, err = timeoutDecode(tm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, grpc.Errorf(codes.InvalidArgument, "invalid grpc-timeout: %s", tm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, vals := range req.Header {
|
|
||||||
for _, val := range vals {
|
|
||||||
// For backwards-compatibility, pass through 'authorization' header with no prefix.
|
|
||||||
if strings.ToLower(key) == "authorization" {
|
|
||||||
pairs = append(pairs, "authorization", val)
|
|
||||||
}
|
|
||||||
if isPermanentHTTPHeader(key) {
|
|
||||||
pairs = append(pairs, strings.ToLower(fmt.Sprintf("%s%s", MetadataPrefix, key)), val)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(key, MetadataHeaderPrefix) {
|
|
||||||
pairs = append(pairs, key[len(MetadataHeaderPrefix):], val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if host := req.Header.Get(xForwardedHost); host != "" {
|
|
||||||
pairs = append(pairs, strings.ToLower(xForwardedHost), host)
|
|
||||||
} else if req.Host != "" {
|
|
||||||
pairs = append(pairs, strings.ToLower(xForwardedHost), req.Host)
|
|
||||||
}
|
|
||||||
|
|
||||||
if addr := req.RemoteAddr; addr != "" {
|
|
||||||
if remoteIP, _, err := net.SplitHostPort(addr); err == nil {
|
|
||||||
if fwd := req.Header.Get(xForwardedFor); fwd == "" {
|
|
||||||
pairs = append(pairs, strings.ToLower(xForwardedFor), remoteIP)
|
|
||||||
} else {
|
|
||||||
pairs = append(pairs, strings.ToLower(xForwardedFor), fmt.Sprintf("%s, %s", fwd, remoteIP))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
grpclog.Printf("invalid remote addr: %s", addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if timeout != 0 {
|
|
||||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
|
||||||
}
|
|
||||||
if len(pairs) == 0 {
|
|
||||||
return ctx, nil
|
|
||||||
}
|
|
||||||
return metadata.NewContext(ctx, metadata.Pairs(pairs...)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServerMetadata consists of metadata sent from gRPC server.
|
|
||||||
type ServerMetadata struct {
|
|
||||||
HeaderMD metadata.MD
|
|
||||||
TrailerMD metadata.MD
|
|
||||||
}
|
|
||||||
|
|
||||||
type serverMetadataKey struct{}
|
|
||||||
|
|
||||||
// NewServerMetadataContext creates a new context with ServerMetadata
|
|
||||||
func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context {
|
|
||||||
return context.WithValue(ctx, serverMetadataKey{}, md)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServerMetadataFromContext returns the ServerMetadata in ctx
|
|
||||||
func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool) {
|
|
||||||
md, ok = ctx.Value(serverMetadataKey{}).(ServerMetadata)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func timeoutDecode(s string) (time.Duration, error) {
|
|
||||||
size := len(s)
|
|
||||||
if size < 2 {
|
|
||||||
return 0, fmt.Errorf("timeout string is too short: %q", s)
|
|
||||||
}
|
|
||||||
d, ok := timeoutUnitToDuration(s[size-1])
|
|
||||||
if !ok {
|
|
||||||
return 0, fmt.Errorf("timeout unit is not recognized: %q", s)
|
|
||||||
}
|
|
||||||
t, err := strconv.ParseInt(s[:size-1], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return d * time.Duration(t), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func timeoutUnitToDuration(u uint8) (d time.Duration, ok bool) {
|
|
||||||
switch u {
|
|
||||||
case 'H':
|
|
||||||
return time.Hour, true
|
|
||||||
case 'M':
|
|
||||||
return time.Minute, true
|
|
||||||
case 'S':
|
|
||||||
return time.Second, true
|
|
||||||
case 'm':
|
|
||||||
return time.Millisecond, true
|
|
||||||
case 'u':
|
|
||||||
return time.Microsecond, true
|
|
||||||
case 'n':
|
|
||||||
return time.Nanosecond, true
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// isPermanentHTTPHeader checks whether hdr belongs to the list of
|
|
||||||
// permenant request headers maintained by IANA.
|
|
||||||
// http://www.iana.org/assignments/message-headers/message-headers.xml
|
|
||||||
func isPermanentHTTPHeader(hdr string) bool {
|
|
||||||
switch hdr {
|
|
||||||
case
|
|
||||||
"Accept",
|
|
||||||
"Accept-Charset",
|
|
||||||
"Accept-Language",
|
|
||||||
"Accept-Ranges",
|
|
||||||
"Authorization",
|
|
||||||
"Cache-Control",
|
|
||||||
"Content-Type",
|
|
||||||
"Cookie",
|
|
||||||
"Date",
|
|
||||||
"Expect",
|
|
||||||
"From",
|
|
||||||
"Host",
|
|
||||||
"If-Match",
|
|
||||||
"If-Modified-Since",
|
|
||||||
"If-None-Match",
|
|
||||||
"If-Schedule-Tag-Match",
|
|
||||||
"If-Unmodified-Since",
|
|
||||||
"Max-Forwards",
|
|
||||||
"Origin",
|
|
||||||
"Pragma",
|
|
||||||
"Referer",
|
|
||||||
"User-Agent",
|
|
||||||
"Via",
|
|
||||||
"Warning":
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
172
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context_test.go
generated
vendored
172
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context_test.go
generated
vendored
@ -1,172 +0,0 @@
|
|||||||
package runtime_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
emptyForwardMetaCount = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAnnotateContext_WorksWithEmpty(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
request, err := http.NewRequest("GET", "http://www.example.com", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("http.NewRequest(%q, %q, nil) failed with %v; want success", "GET", "http://www.example.com", err)
|
|
||||||
}
|
|
||||||
request.Header.Add("Some-Irrelevant-Header", "some value")
|
|
||||||
annotated, err := runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
md, ok := metadata.FromContext(annotated)
|
|
||||||
if !ok || len(md) != emptyForwardMetaCount {
|
|
||||||
t.Errorf("Expected %d metadata items in context; got %v", emptyForwardMetaCount, md)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAnnotateContext_ForwardsGrpcMetadata(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
request, err := http.NewRequest("GET", "http://www.example.com", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("http.NewRequest(%q, %q, nil) failed with %v; want success", "GET", "http://www.example.com", err)
|
|
||||||
}
|
|
||||||
request.Header.Add("Some-Irrelevant-Header", "some value")
|
|
||||||
request.Header.Add("Grpc-Metadata-FooBar", "Value1")
|
|
||||||
request.Header.Add("Grpc-Metadata-Foo-BAZ", "Value2")
|
|
||||||
request.Header.Add("Grpc-Metadata-foo-bAz", "Value3")
|
|
||||||
request.Header.Add("Authorization", "Token 1234567890")
|
|
||||||
annotated, err := runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
md, ok := metadata.FromContext(annotated)
|
|
||||||
if got, want := len(md), emptyForwardMetaCount+4; !ok || got != want {
|
|
||||||
t.Errorf("metadata items in context = %d want %d: %v", got, want, md)
|
|
||||||
}
|
|
||||||
if got, want := md["foobar"], []string{"Value1"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["grpcgateway-foobar"] = %q; want %q`, got, want)
|
|
||||||
}
|
|
||||||
if got, want := md["foo-baz"], []string{"Value2", "Value3"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["grpcgateway-foo-baz"] = %q want %q`, got, want)
|
|
||||||
}
|
|
||||||
if got, want := md["grpcgateway-authorization"], []string{"Token 1234567890"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["grpcgateway-authorization"] = %q want %q`, got, want)
|
|
||||||
}
|
|
||||||
if got, want := md["authorization"], []string{"Token 1234567890"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["authorization"] = %q want %q`, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAnnotateContext_XForwardedFor(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
request, err := http.NewRequest("GET", "http://bar.foo.example.com", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("http.NewRequest(%q, %q, nil) failed with %v; want success", "GET", "http://bar.foo.example.com", err)
|
|
||||||
}
|
|
||||||
request.Header.Add("X-Forwarded-For", "192.0.2.100") // client
|
|
||||||
request.RemoteAddr = "192.0.2.200:12345" // proxy
|
|
||||||
|
|
||||||
annotated, err := runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
md, ok := metadata.FromContext(annotated)
|
|
||||||
if !ok || len(md) != emptyForwardMetaCount+1 {
|
|
||||||
t.Errorf("Expected %d metadata items in context; got %v", emptyForwardMetaCount+1, md)
|
|
||||||
}
|
|
||||||
if got, want := md["x-forwarded-host"], []string{"bar.foo.example.com"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["host"] = %v; want %v`, got, want)
|
|
||||||
}
|
|
||||||
// Note: it must be in order client, proxy1, proxy2
|
|
||||||
if got, want := md["x-forwarded-for"], []string{"192.0.2.100, 192.0.2.200"}; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf(`md["x-forwarded-for"] = %v want %v`, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAnnotateContext_SupportsTimeouts(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
request, err := http.NewRequest("GET", "http://example.com", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf(`http.NewRequest("GET", "http://example.com", nil failed with %v; want success`, err)
|
|
||||||
}
|
|
||||||
annotated, err := runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, ok := annotated.Deadline(); ok {
|
|
||||||
// no deadline by default
|
|
||||||
t.Errorf("annotated.Deadline() = _, true; want _, false")
|
|
||||||
}
|
|
||||||
|
|
||||||
const acceptableError = 50 * time.Millisecond
|
|
||||||
runtime.DefaultContextTimeout = 10 * time.Second
|
|
||||||
annotated, err = runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
deadline, ok := annotated.Deadline()
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("annotated.Deadline() = _, false; want _, true")
|
|
||||||
}
|
|
||||||
if got, want := deadline.Sub(time.Now()), runtime.DefaultContextTimeout; got-want > acceptableError || got-want < -acceptableError {
|
|
||||||
t.Errorf("deadline.Sub(time.Now()) = %v; want %v; with error %v", got, want, acceptableError)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, spec := range []struct {
|
|
||||||
timeout string
|
|
||||||
want time.Duration
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
timeout: "17H",
|
|
||||||
want: 17 * time.Hour,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: "19M",
|
|
||||||
want: 19 * time.Minute,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: "23S",
|
|
||||||
want: 23 * time.Second,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: "1009m",
|
|
||||||
want: 1009 * time.Millisecond,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: "1000003u",
|
|
||||||
want: 1000003 * time.Microsecond,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: "100000007n",
|
|
||||||
want: 100000007 * time.Nanosecond,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
request.Header.Set("Grpc-Timeout", spec.timeout)
|
|
||||||
annotated, err = runtime.AnnotateContext(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
deadline, ok := annotated.Deadline()
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("annotated.Deadline() = _, false; want _, true; timeout = %q", spec.timeout)
|
|
||||||
}
|
|
||||||
if got, want := deadline.Sub(time.Now()), spec.want; got-want > acceptableError || got-want < -acceptableError {
|
|
||||||
t.Errorf("deadline.Sub(time.Now()) = %v; want %v; with error %v; timeout= %q", got, want, acceptableError, spec.timeout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
58
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go
generated
vendored
58
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go
generated
vendored
@ -1,58 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// String just returns the given string.
|
|
||||||
// It is just for compatibility to other types.
|
|
||||||
func String(val string) (string, error) {
|
|
||||||
return val, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bool converts the given string representation of a boolean value into bool.
|
|
||||||
func Bool(val string) (bool, error) {
|
|
||||||
return strconv.ParseBool(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float64 converts the given string representation into representation of a floating point number into float64.
|
|
||||||
func Float64(val string) (float64, error) {
|
|
||||||
return strconv.ParseFloat(val, 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float32 converts the given string representation of a floating point number into float32.
|
|
||||||
func Float32(val string) (float32, error) {
|
|
||||||
f, err := strconv.ParseFloat(val, 32)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return float32(f), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int64 converts the given string representation of an integer into int64.
|
|
||||||
func Int64(val string) (int64, error) {
|
|
||||||
return strconv.ParseInt(val, 0, 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int32 converts the given string representation of an integer into int32.
|
|
||||||
func Int32(val string) (int32, error) {
|
|
||||||
i, err := strconv.ParseInt(val, 0, 32)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return int32(i), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uint64 converts the given string representation of an integer into uint64.
|
|
||||||
func Uint64(val string) (uint64, error) {
|
|
||||||
return strconv.ParseUint(val, 0, 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uint32 converts the given string representation of an integer into uint32.
|
|
||||||
func Uint32(val string) (uint32, error) {
|
|
||||||
i, err := strconv.ParseUint(val, 0, 32)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return uint32(i), nil
|
|
||||||
}
|
|
5
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go
generated
vendored
5
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go
generated
vendored
@ -1,5 +0,0 @@
|
|||||||
/*
|
|
||||||
Package runtime contains runtime helper functions used by
|
|
||||||
servers which protoc-gen-grpc-gateway generates.
|
|
||||||
*/
|
|
||||||
package runtime
|
|
121
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go
generated
vendored
121
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go
generated
vendored
@ -1,121 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status.
|
|
||||||
func HTTPStatusFromCode(code codes.Code) int {
|
|
||||||
switch code {
|
|
||||||
case codes.OK:
|
|
||||||
return http.StatusOK
|
|
||||||
case codes.Canceled:
|
|
||||||
return http.StatusRequestTimeout
|
|
||||||
case codes.Unknown:
|
|
||||||
return http.StatusInternalServerError
|
|
||||||
case codes.InvalidArgument:
|
|
||||||
return http.StatusBadRequest
|
|
||||||
case codes.DeadlineExceeded:
|
|
||||||
return http.StatusRequestTimeout
|
|
||||||
case codes.NotFound:
|
|
||||||
return http.StatusNotFound
|
|
||||||
case codes.AlreadyExists:
|
|
||||||
return http.StatusConflict
|
|
||||||
case codes.PermissionDenied:
|
|
||||||
return http.StatusForbidden
|
|
||||||
case codes.Unauthenticated:
|
|
||||||
return http.StatusUnauthorized
|
|
||||||
case codes.ResourceExhausted:
|
|
||||||
return http.StatusForbidden
|
|
||||||
case codes.FailedPrecondition:
|
|
||||||
return http.StatusPreconditionFailed
|
|
||||||
case codes.Aborted:
|
|
||||||
return http.StatusConflict
|
|
||||||
case codes.OutOfRange:
|
|
||||||
return http.StatusBadRequest
|
|
||||||
case codes.Unimplemented:
|
|
||||||
return http.StatusNotImplemented
|
|
||||||
case codes.Internal:
|
|
||||||
return http.StatusInternalServerError
|
|
||||||
case codes.Unavailable:
|
|
||||||
return http.StatusServiceUnavailable
|
|
||||||
case codes.DataLoss:
|
|
||||||
return http.StatusInternalServerError
|
|
||||||
}
|
|
||||||
|
|
||||||
grpclog.Printf("Unknown gRPC error code: %v", code)
|
|
||||||
return http.StatusInternalServerError
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// HTTPError replies to the request with the error.
|
|
||||||
// You can set a custom function to this variable to customize error format.
|
|
||||||
HTTPError = DefaultHTTPError
|
|
||||||
// OtherErrorHandler handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest
|
|
||||||
OtherErrorHandler = DefaultOtherErrorHandler
|
|
||||||
)
|
|
||||||
|
|
||||||
type errorBody struct {
|
|
||||||
Error string `protobuf:"bytes,1,name=error" json:"error"`
|
|
||||||
Code int32 `protobuf:"varint,2,name=code" json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
//Make this also conform to proto.Message for builtin JSONPb Marshaler
|
|
||||||
func (e *errorBody) Reset() { *e = errorBody{} }
|
|
||||||
func (e *errorBody) String() string { return proto.CompactTextString(e) }
|
|
||||||
func (*errorBody) ProtoMessage() {}
|
|
||||||
|
|
||||||
// DefaultHTTPError is the default implementation of HTTPError.
|
|
||||||
// If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode.
|
|
||||||
// If otherwise, it replies with http.StatusInternalServerError.
|
|
||||||
//
|
|
||||||
// The response body returned by this function is a JSON object,
|
|
||||||
// which contains a member whose key is "error" and whose value is err.Error().
|
|
||||||
func DefaultHTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, _ *http.Request, err error) {
|
|
||||||
const fallback = `{"error": "failed to marshal error message"}`
|
|
||||||
|
|
||||||
w.Header().Del("Trailer")
|
|
||||||
w.Header().Set("Content-Type", marshaler.ContentType())
|
|
||||||
body := &errorBody{
|
|
||||||
Error: grpc.ErrorDesc(err),
|
|
||||||
Code: int32(grpc.Code(err)),
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, merr := marshaler.Marshal(body)
|
|
||||||
if merr != nil {
|
|
||||||
grpclog.Printf("Failed to marshal error message %q: %v", body, merr)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
if _, err := io.WriteString(w, fallback); err != nil {
|
|
||||||
grpclog.Printf("Failed to write response: %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
md, ok := ServerMetadataFromContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
grpclog.Printf("Failed to extract ServerMetadata from context")
|
|
||||||
}
|
|
||||||
|
|
||||||
handleForwardResponseServerMetadata(w, md)
|
|
||||||
handleForwardResponseTrailerHeader(w, md)
|
|
||||||
st := HTTPStatusFromCode(grpc.Code(err))
|
|
||||||
w.WriteHeader(st)
|
|
||||||
if _, err := w.Write(buf); err != nil {
|
|
||||||
grpclog.Printf("Failed to write response: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
handleForwardResponseTrailer(w, md)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultOtherErrorHandler is the default implementation of OtherErrorHandler.
|
|
||||||
// It simply writes a string representation of the given error into "w".
|
|
||||||
func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) {
|
|
||||||
http.Error(w, msg, code)
|
|
||||||
}
|
|
56
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors_test.go
generated
vendored
56
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors_test.go
generated
vendored
@ -1,56 +0,0 @@
|
|||||||
package runtime_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDefaultHTTPError(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
for _, spec := range []struct {
|
|
||||||
err error
|
|
||||||
status int
|
|
||||||
msg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
err: fmt.Errorf("example error"),
|
|
||||||
status: http.StatusInternalServerError,
|
|
||||||
msg: "example error",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
err: grpc.Errorf(codes.NotFound, "no such resource"),
|
|
||||||
status: http.StatusNotFound,
|
|
||||||
msg: "no such resource",
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
req, _ := http.NewRequest("", "", nil) // Pass in an empty request to match the signature
|
|
||||||
runtime.DefaultHTTPError(ctx, &runtime.JSONBuiltin{}, w, req, spec.err)
|
|
||||||
|
|
||||||
if got, want := w.Header().Get("Content-Type"), "application/json"; got != want {
|
|
||||||
t.Errorf(`w.Header().Get("Content-Type") = %q; want %q; on spec.err=%v`, got, want, spec.err)
|
|
||||||
}
|
|
||||||
if got, want := w.Code, spec.status; got != want {
|
|
||||||
t.Errorf("w.Code = %d; want %d", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := make(map[string]interface{})
|
|
||||||
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
|
|
||||||
t.Errorf("json.Unmarshal(%q, &body) failed with %v; want success", w.Body.Bytes(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if got, want := body["error"].(string), spec.msg; !strings.Contains(got, want) {
|
|
||||||
t.Errorf(`body["error"] = %q; want %q; on spec.err=%v`, got, want, spec.err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
164
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go
generated
vendored
164
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go
generated
vendored
@ -1,164 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/textproto"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime/internal"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ForwardResponseStream forwards the stream from gRPC server to REST client.
|
|
||||||
func ForwardResponseStream(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error) {
|
|
||||||
f, ok := w.(http.Flusher)
|
|
||||||
if !ok {
|
|
||||||
grpclog.Printf("Flush not supported in %T", w)
|
|
||||||
http.Error(w, "unexpected type of web server", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
md, ok := ServerMetadataFromContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
grpclog.Printf("Failed to extract ServerMetadata from context")
|
|
||||||
http.Error(w, "unexpected error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handleForwardResponseServerMetadata(w, md)
|
|
||||||
|
|
||||||
w.Header().Set("Transfer-Encoding", "chunked")
|
|
||||||
w.Header().Set("Content-Type", marshaler.ContentType())
|
|
||||||
if err := handleForwardResponseOptions(ctx, w, nil, opts); err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
f.Flush()
|
|
||||||
for {
|
|
||||||
resp, err := recv()
|
|
||||||
if err == io.EOF {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
handleForwardResponseStreamError(marshaler, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil {
|
|
||||||
handleForwardResponseStreamError(marshaler, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err := marshaler.Marshal(streamChunk(resp, nil))
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Failed to marshal response chunk: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err = fmt.Fprintf(w, "%s\n", buf); err != nil {
|
|
||||||
grpclog.Printf("Failed to send response chunk: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
f.Flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleForwardResponseServerMetadata(w http.ResponseWriter, md ServerMetadata) {
|
|
||||||
for k, vs := range md.HeaderMD {
|
|
||||||
hKey := fmt.Sprintf("%s%s", MetadataHeaderPrefix, k)
|
|
||||||
for i := range vs {
|
|
||||||
w.Header().Add(hKey, vs[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleForwardResponseTrailerHeader(w http.ResponseWriter, md ServerMetadata) {
|
|
||||||
for k := range md.TrailerMD {
|
|
||||||
tKey := textproto.CanonicalMIMEHeaderKey(fmt.Sprintf("%s%s", MetadataTrailerPrefix, k))
|
|
||||||
w.Header().Add("Trailer", tKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleForwardResponseTrailer(w http.ResponseWriter, md ServerMetadata) {
|
|
||||||
for k, vs := range md.TrailerMD {
|
|
||||||
tKey := fmt.Sprintf("%s%s", MetadataTrailerPrefix, k)
|
|
||||||
for i := range vs {
|
|
||||||
w.Header().Add(tKey, vs[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ForwardResponseMessage forwards the message "resp" from gRPC server to REST client.
|
|
||||||
func ForwardResponseMessage(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error) {
|
|
||||||
md, ok := ServerMetadataFromContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
grpclog.Printf("Failed to extract ServerMetadata from context")
|
|
||||||
}
|
|
||||||
|
|
||||||
handleForwardResponseServerMetadata(w, md)
|
|
||||||
handleForwardResponseTrailerHeader(w, md)
|
|
||||||
w.Header().Set("Content-Type", marshaler.ContentType())
|
|
||||||
if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil {
|
|
||||||
HTTPError(ctx, marshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err := marshaler.Marshal(resp)
|
|
||||||
if err != nil {
|
|
||||||
grpclog.Printf("Marshal error: %v", err)
|
|
||||||
HTTPError(ctx, marshaler, w, req, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = w.Write(buf); err != nil {
|
|
||||||
grpclog.Printf("Failed to write response: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
handleForwardResponseTrailer(w, md)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleForwardResponseOptions(ctx context.Context, w http.ResponseWriter, resp proto.Message, opts []func(context.Context, http.ResponseWriter, proto.Message) error) error {
|
|
||||||
if len(opts) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, opt := range opts {
|
|
||||||
if err := opt(ctx, w, resp); err != nil {
|
|
||||||
grpclog.Printf("Error handling ForwardResponseOptions: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleForwardResponseStreamError(marshaler Marshaler, w http.ResponseWriter, err error) {
|
|
||||||
buf, merr := marshaler.Marshal(streamChunk(nil, err))
|
|
||||||
if merr != nil {
|
|
||||||
grpclog.Printf("Failed to marshal an error: %v", merr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, werr := fmt.Fprintf(w, "%s\n", buf); werr != nil {
|
|
||||||
grpclog.Printf("Failed to notify error to client: %v", werr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func streamChunk(result proto.Message, err error) map[string]proto.Message {
|
|
||||||
if err != nil {
|
|
||||||
grpcCode := grpc.Code(err)
|
|
||||||
httpCode := HTTPStatusFromCode(grpcCode)
|
|
||||||
return map[string]proto.Message{
|
|
||||||
"error": &internal.StreamError{
|
|
||||||
GrpcCode: int32(grpcCode),
|
|
||||||
HttpCode: int32(httpCode),
|
|
||||||
Message: err.Error(),
|
|
||||||
HttpStatus: http.StatusText(httpCode),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if result == nil {
|
|
||||||
return streamChunk(nil, fmt.Errorf("empty response"))
|
|
||||||
}
|
|
||||||
return map[string]proto.Message{"result": result}
|
|
||||||
}
|
|
93
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/internal/stream_chunk.pb.go
generated
vendored
93
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/internal/stream_chunk.pb.go
generated
vendored
@ -1,93 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: runtime/internal/stream_chunk.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package internal is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
runtime/internal/stream_chunk.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
StreamError
|
|
||||||
*/
|
|
||||||
package internal
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
// StreamError is a response type which is returned when
|
|
||||||
// streaming rpc returns an error.
|
|
||||||
type StreamError struct {
|
|
||||||
GrpcCode int32 `protobuf:"varint,1,opt,name=grpc_code,json=grpcCode" json:"grpc_code,omitempty"`
|
|
||||||
HttpCode int32 `protobuf:"varint,2,opt,name=http_code,json=httpCode" json:"http_code,omitempty"`
|
|
||||||
Message string `protobuf:"bytes,3,opt,name=message" json:"message,omitempty"`
|
|
||||||
HttpStatus string `protobuf:"bytes,4,opt,name=http_status,json=httpStatus" json:"http_status,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *StreamError) Reset() { *m = StreamError{} }
|
|
||||||
func (m *StreamError) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*StreamError) ProtoMessage() {}
|
|
||||||
func (*StreamError) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *StreamError) GetGrpcCode() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.GrpcCode
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *StreamError) GetHttpCode() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.HttpCode
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *StreamError) GetMessage() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Message
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *StreamError) GetHttpStatus() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.HttpStatus
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*StreamError)(nil), "grpc.gateway.runtime.StreamError")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("runtime/internal/stream_chunk.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 181 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8e, 0xbf, 0xee, 0x82, 0x30,
|
|
||||||
0x14, 0x85, 0xd3, 0xdf, 0x1f, 0x85, 0xcb, 0x46, 0x1c, 0x9a, 0x38, 0x48, 0x74, 0x61, 0x82, 0xc1,
|
|
||||||
0x37, 0xd0, 0xf8, 0x02, 0xb0, 0xb9, 0x90, 0x0a, 0x37, 0x40, 0x94, 0x96, 0xdc, 0x5e, 0x62, 0x5c,
|
|
||||||
0x7d, 0x72, 0xd3, 0x22, 0xe3, 0xf9, 0xbe, 0x73, 0x92, 0x03, 0x07, 0x9a, 0x34, 0xf7, 0x03, 0xe6,
|
|
||||||
0xbd, 0x66, 0x24, 0xad, 0x1e, 0xb9, 0x65, 0x42, 0x35, 0x54, 0x75, 0x37, 0xe9, 0x7b, 0x36, 0x92,
|
|
||||||
0x61, 0x13, 0x6f, 0x5a, 0x1a, 0xeb, 0xac, 0x55, 0x8c, 0x4f, 0xf5, 0xca, 0xbe, 0x8b, 0xfd, 0x5b,
|
|
||||||
0x40, 0x54, 0xfa, 0xf2, 0x85, 0xc8, 0x50, 0xbc, 0x85, 0xd0, 0xf5, 0xaa, 0xda, 0x34, 0x28, 0x45,
|
|
||||||
0x22, 0xd2, 0xff, 0x22, 0x70, 0xe0, 0x6c, 0x1a, 0x74, 0xb2, 0x63, 0x1e, 0x67, 0xf9, 0x33, 0x4b,
|
|
||||||
0x07, 0xbc, 0x94, 0xb0, 0x1e, 0xd0, 0x5a, 0xd5, 0xa2, 0xfc, 0x4d, 0x44, 0x1a, 0x16, 0x4b, 0x8c,
|
|
||||||
0x77, 0x10, 0xf9, 0x99, 0x65, 0xc5, 0x93, 0x95, 0x7f, 0xde, 0x82, 0x43, 0xa5, 0x27, 0x27, 0xb8,
|
|
||||||
0x06, 0xcb, 0xf3, 0xdb, 0xca, 0xbf, 0x3d, 0x7e, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x07, 0x92,
|
|
||||||
0xb6, 0xd4, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
12
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/internal/stream_chunk.proto
generated
vendored
12
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/internal/stream_chunk.proto
generated
vendored
@ -1,12 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package grpc.gateway.runtime;
|
|
||||||
option go_package = "internal";
|
|
||||||
|
|
||||||
// StreamError is a response type which is returned when
|
|
||||||
// streaming rpc returns an error.
|
|
||||||
message StreamError {
|
|
||||||
int32 grpc_code = 1;
|
|
||||||
int32 http_code = 2;
|
|
||||||
string message = 3;
|
|
||||||
string http_status = 4;
|
|
||||||
}
|
|
37
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go
generated
vendored
37
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go
generated
vendored
@ -1,37 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// JSONBuiltin is a Marshaler which marshals/unmarshals into/from JSON
|
|
||||||
// with the standard "encoding/json" package of Golang.
|
|
||||||
// Although it is generally faster for simple proto messages than JSONPb,
|
|
||||||
// it does not support advanced features of protobuf, e.g. map, oneof, ....
|
|
||||||
type JSONBuiltin struct{}
|
|
||||||
|
|
||||||
// ContentType always Returns "application/json".
|
|
||||||
func (*JSONBuiltin) ContentType() string {
|
|
||||||
return "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal marshals "v" into JSON
|
|
||||||
func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error) {
|
|
||||||
return json.Marshal(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal unmarshals JSON data into "v".
|
|
||||||
func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error {
|
|
||||||
return json.Unmarshal(data, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoder returns a Decoder which reads JSON stream from "r".
|
|
||||||
func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder {
|
|
||||||
return json.NewDecoder(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEncoder returns an Encoder which writes JSON stream into "w".
|
|
||||||
func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder {
|
|
||||||
return json.NewEncoder(w)
|
|
||||||
}
|
|
245
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json_test.go
generated
vendored
245
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json_test.go
generated
vendored
@ -1,245 +0,0 @@
|
|||||||
package runtime_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
structpb "github.com/golang/protobuf/ptypes/struct"
|
|
||||||
"github.com/golang/protobuf/ptypes/timestamp"
|
|
||||||
"github.com/golang/protobuf/ptypes/wrappers"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestJSONBuiltinMarshal(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
msg := examplepb.SimpleMessage{
|
|
||||||
Id: "foo",
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err := m.Marshal(&msg)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%v) failed with %v; want success", &msg, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var got examplepb.SimpleMessage
|
|
||||||
if err := json.Unmarshal(buf, &got); err != nil {
|
|
||||||
t.Errorf("json.Unmarshal(%q, &got) failed with %v; want success", buf, err)
|
|
||||||
}
|
|
||||||
if want := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinMarshalField(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinFieldFixtures {
|
|
||||||
buf, err := m.Marshal(fixt.data)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%v) failed with %v; want success", fixt.data, err)
|
|
||||||
}
|
|
||||||
if got, want := string(buf), fixt.json; got != want {
|
|
||||||
t.Errorf("got = %q; want %q; data = %#v", got, want, fixt.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinMarshalFieldKnownErrors(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinKnownErrors {
|
|
||||||
buf, err := m.Marshal(fixt.data)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%v) failed with %v; want success", fixt.data, err)
|
|
||||||
}
|
|
||||||
if got, want := string(buf), fixt.json; got == want {
|
|
||||||
t.Errorf("surprisingly got = %q; as want %q; data = %#v", got, want, fixt.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinsnmarshal(t *testing.T) {
|
|
||||||
var (
|
|
||||||
m runtime.JSONBuiltin
|
|
||||||
got examplepb.SimpleMessage
|
|
||||||
|
|
||||||
data = []byte(`{"id": "foo"}`)
|
|
||||||
)
|
|
||||||
if err := m.Unmarshal(data, &got); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(%q, &got) failed with %v; want success", data, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
want := examplepb.SimpleMessage{
|
|
||||||
Id: "foo",
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want = %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinUnmarshalField(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinFieldFixtures {
|
|
||||||
dest := reflect.New(reflect.TypeOf(fixt.data))
|
|
||||||
if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(%q, dest) failed with %v; want success", fixt.json, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %#v; want = %#v; input = %q", got, want, fixt.json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinUnmarshalFieldKnownErrors(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinKnownErrors {
|
|
||||||
dest := reflect.New(reflect.TypeOf(fixt.data))
|
|
||||||
if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err == nil {
|
|
||||||
t.Errorf("m.Unmarshal(%q, dest) succeeded; want ane error", fixt.json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinEncoder(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
msg := examplepb.SimpleMessage{
|
|
||||||
Id: "foo",
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := m.NewEncoder(&buf)
|
|
||||||
if err := enc.Encode(&msg); err != nil {
|
|
||||||
t.Errorf("enc.Encode(%v) failed with %v; want success", &msg, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var got examplepb.SimpleMessage
|
|
||||||
if err := json.Unmarshal(buf.Bytes(), &got); err != nil {
|
|
||||||
t.Errorf("json.Unmarshal(%q, &got) failed with %v; want success", buf.String(), err)
|
|
||||||
}
|
|
||||||
if want := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinEncoderFields(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinFieldFixtures {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := m.NewEncoder(&buf)
|
|
||||||
if err := enc.Encode(fixt.data); err != nil {
|
|
||||||
t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := buf.String(), fixt.json+"\n"; got != want {
|
|
||||||
t.Errorf("got = %q; want %q; data = %#v", got, want, fixt.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinDecoder(t *testing.T) {
|
|
||||||
var (
|
|
||||||
m runtime.JSONBuiltin
|
|
||||||
got examplepb.SimpleMessage
|
|
||||||
|
|
||||||
data = `{"id": "foo"}`
|
|
||||||
)
|
|
||||||
r := strings.NewReader(data)
|
|
||||||
dec := m.NewDecoder(r)
|
|
||||||
if err := dec.Decode(&got); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(&got) failed with %v; want success", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
want := examplepb.SimpleMessage{
|
|
||||||
Id: "foo",
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want = %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONBuiltinDecoderFields(t *testing.T) {
|
|
||||||
var m runtime.JSONBuiltin
|
|
||||||
for _, fixt := range builtinFieldFixtures {
|
|
||||||
r := strings.NewReader(fixt.json)
|
|
||||||
dec := m.NewDecoder(r)
|
|
||||||
dest := reflect.New(reflect.TypeOf(fixt.data))
|
|
||||||
if err := dec.Decode(dest.Interface()); err != nil {
|
|
||||||
t.Errorf("dec.Decode(dest) failed with %v; want success; data = %q", err, fixt.json)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want = %v; input = %q", got, want, fixt.json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
builtinFieldFixtures = []struct {
|
|
||||||
data interface{}
|
|
||||||
json string
|
|
||||||
}{
|
|
||||||
{data: "", json: `""`},
|
|
||||||
{data: proto.String(""), json: `""`},
|
|
||||||
{data: "foo", json: `"foo"`},
|
|
||||||
{data: proto.String("foo"), json: `"foo"`},
|
|
||||||
{data: int32(-1), json: "-1"},
|
|
||||||
{data: proto.Int32(-1), json: "-1"},
|
|
||||||
{data: int64(-1), json: "-1"},
|
|
||||||
{data: proto.Int64(-1), json: "-1"},
|
|
||||||
{data: uint32(123), json: "123"},
|
|
||||||
{data: proto.Uint32(123), json: "123"},
|
|
||||||
{data: uint64(123), json: "123"},
|
|
||||||
{data: proto.Uint64(123), json: "123"},
|
|
||||||
{data: float32(-1.5), json: "-1.5"},
|
|
||||||
{data: proto.Float32(-1.5), json: "-1.5"},
|
|
||||||
{data: float64(-1.5), json: "-1.5"},
|
|
||||||
{data: proto.Float64(-1.5), json: "-1.5"},
|
|
||||||
{data: true, json: "true"},
|
|
||||||
{data: proto.Bool(true), json: "true"},
|
|
||||||
{data: (*string)(nil), json: "null"},
|
|
||||||
{data: new(empty.Empty), json: "{}"},
|
|
||||||
{data: examplepb.NumericEnum_ONE, json: "1"},
|
|
||||||
{
|
|
||||||
data: (*examplepb.NumericEnum)(proto.Int32(int32(examplepb.NumericEnum_ONE))),
|
|
||||||
json: "1",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
builtinKnownErrors = []struct {
|
|
||||||
data interface{}
|
|
||||||
json string
|
|
||||||
}{
|
|
||||||
{data: examplepb.NumericEnum_ONE, json: "ONE"},
|
|
||||||
{
|
|
||||||
data: (*examplepb.NumericEnum)(proto.Int32(int32(examplepb.NumericEnum_ONE))),
|
|
||||||
json: "ONE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &examplepb.ABitOfEverything_OneofString{OneofString: "abc"},
|
|
||||||
json: `"abc"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: ×tamp.Timestamp{
|
|
||||||
Seconds: 1462875553,
|
|
||||||
Nanos: 123000000,
|
|
||||||
},
|
|
||||||
json: `"2016-05-10T10:19:13.123Z"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.Int32Value{Value: 123},
|
|
||||||
json: "123",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &structpb.Value{
|
|
||||||
Kind: &structpb.Value_StringValue{
|
|
||||||
StringValue: "abc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
json: `"abc"`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
184
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go
generated
vendored
184
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go
generated
vendored
@ -1,184 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/jsonpb"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// JSONPb is a Marshaler which marshals/unmarshals into/from JSON
|
|
||||||
// with the "github.com/golang/protobuf/jsonpb".
|
|
||||||
// It supports fully functionality of protobuf unlike JSONBuiltin.
|
|
||||||
type JSONPb jsonpb.Marshaler
|
|
||||||
|
|
||||||
// ContentType always returns "application/json".
|
|
||||||
func (*JSONPb) ContentType() string {
|
|
||||||
return "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal marshals "v" into JSON
|
|
||||||
// Currently it can marshal only proto.Message.
|
|
||||||
// TODO(yugui) Support fields of primitive types in a message.
|
|
||||||
func (j *JSONPb) Marshal(v interface{}) ([]byte, error) {
|
|
||||||
if _, ok := v.(proto.Message); !ok {
|
|
||||||
return j.marshalNonProtoField(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if err := j.marshalTo(&buf, v); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *JSONPb) marshalTo(w io.Writer, v interface{}) error {
|
|
||||||
p, ok := v.(proto.Message)
|
|
||||||
if !ok {
|
|
||||||
buf, err := j.marshalNonProtoField(v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = w.Write(buf)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return (*jsonpb.Marshaler)(j).Marshal(w, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshalNonProto marshals a non-message field of a protobuf message.
|
|
||||||
// This function does not correctly marshals arbitary data structure into JSON,
|
|
||||||
// but it is only capable of marshaling non-message field values of protobuf,
|
|
||||||
// i.e. primitive types, enums; pointers to primitives or enums; maps from
|
|
||||||
// integer/string types to primitives/enums/pointers to messages.
|
|
||||||
func (j *JSONPb) marshalNonProtoField(v interface{}) ([]byte, error) {
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
for rv.Kind() == reflect.Ptr {
|
|
||||||
if rv.IsNil() {
|
|
||||||
return []byte("null"), nil
|
|
||||||
}
|
|
||||||
rv = rv.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
if rv.Kind() == reflect.Map {
|
|
||||||
m := make(map[string]*json.RawMessage)
|
|
||||||
for _, k := range rv.MapKeys() {
|
|
||||||
buf, err := j.Marshal(rv.MapIndex(k).Interface())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
m[fmt.Sprintf("%v", k.Interface())] = (*json.RawMessage)(&buf)
|
|
||||||
}
|
|
||||||
if j.Indent != "" {
|
|
||||||
return json.MarshalIndent(m, "", j.Indent)
|
|
||||||
}
|
|
||||||
return json.Marshal(m)
|
|
||||||
}
|
|
||||||
if enum, ok := rv.Interface().(protoEnum); ok && !j.EnumsAsInts {
|
|
||||||
return json.Marshal(enum.String())
|
|
||||||
}
|
|
||||||
return json.Marshal(rv.Interface())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal unmarshals JSON "data" into "v"
|
|
||||||
// Currently it can marshal only proto.Message.
|
|
||||||
// TODO(yugui) Support fields of primitive types in a message.
|
|
||||||
func (j *JSONPb) Unmarshal(data []byte, v interface{}) error {
|
|
||||||
return unmarshalJSONPb(data, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoder returns a Decoder which reads JSON stream from "r".
|
|
||||||
func (j *JSONPb) NewDecoder(r io.Reader) Decoder {
|
|
||||||
d := json.NewDecoder(r)
|
|
||||||
return DecoderFunc(func(v interface{}) error { return decodeJSONPb(d, v) })
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEncoder returns an Encoder which writes JSON stream into "w".
|
|
||||||
func (j *JSONPb) NewEncoder(w io.Writer) Encoder {
|
|
||||||
return EncoderFunc(func(v interface{}) error { return j.marshalTo(w, v) })
|
|
||||||
}
|
|
||||||
|
|
||||||
func unmarshalJSONPb(data []byte, v interface{}) error {
|
|
||||||
d := json.NewDecoder(bytes.NewReader(data))
|
|
||||||
return decodeJSONPb(d, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeJSONPb(d *json.Decoder, v interface{}) error {
|
|
||||||
p, ok := v.(proto.Message)
|
|
||||||
if !ok {
|
|
||||||
return decodeNonProtoField(d, v)
|
|
||||||
}
|
|
||||||
unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: true}
|
|
||||||
return unmarshaler.UnmarshalNext(d, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeNonProtoField(d *json.Decoder, v interface{}) error {
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
if rv.Kind() != reflect.Ptr {
|
|
||||||
return fmt.Errorf("%T is not a pointer", v)
|
|
||||||
}
|
|
||||||
for rv.Kind() == reflect.Ptr {
|
|
||||||
if rv.IsNil() {
|
|
||||||
rv.Set(reflect.New(rv.Type().Elem()))
|
|
||||||
}
|
|
||||||
if rv.Type().ConvertibleTo(typeProtoMessage) {
|
|
||||||
unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: true}
|
|
||||||
return unmarshaler.UnmarshalNext(d, rv.Interface().(proto.Message))
|
|
||||||
}
|
|
||||||
rv = rv.Elem()
|
|
||||||
}
|
|
||||||
if rv.Kind() == reflect.Map {
|
|
||||||
if rv.IsNil() {
|
|
||||||
rv.Set(reflect.MakeMap(rv.Type()))
|
|
||||||
}
|
|
||||||
conv, ok := convFromType[rv.Type().Key().Kind()]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("unsupported type of map field key: %v", rv.Type().Key())
|
|
||||||
}
|
|
||||||
|
|
||||||
m := make(map[string]*json.RawMessage)
|
|
||||||
if err := d.Decode(&m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k, v := range m {
|
|
||||||
result := conv.Call([]reflect.Value{reflect.ValueOf(k)})
|
|
||||||
if err := result[1].Interface(); err != nil {
|
|
||||||
return err.(error)
|
|
||||||
}
|
|
||||||
bk := result[0]
|
|
||||||
bv := reflect.New(rv.Type().Elem())
|
|
||||||
if err := unmarshalJSONPb([]byte(*v), bv.Interface()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rv.SetMapIndex(bk, bv.Elem())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if _, ok := rv.Interface().(protoEnum); ok {
|
|
||||||
var repr interface{}
|
|
||||||
if err := d.Decode(&repr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch repr.(type) {
|
|
||||||
case string:
|
|
||||||
// TODO(yugui) Should use proto.StructProperties?
|
|
||||||
return fmt.Errorf("unmarshaling of symbolic enum %q not supported: %T", repr, rv.Interface())
|
|
||||||
case float64:
|
|
||||||
rv.Set(reflect.ValueOf(int32(repr.(float64))).Convert(rv.Type()))
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("cannot assign %#v into Go type %T", repr, rv.Interface())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d.Decode(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
type protoEnum interface {
|
|
||||||
fmt.Stringer
|
|
||||||
EnumDescriptor() ([]byte, []int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var typeProtoMessage = reflect.TypeOf((*proto.Message)(nil)).Elem()
|
|
606
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb_test.go
generated
vendored
606
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb_test.go
generated
vendored
@ -1,606 +0,0 @@
|
|||||||
package runtime_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/jsonpb"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes/duration"
|
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
|
||||||
structpb "github.com/golang/protobuf/ptypes/struct"
|
|
||||||
"github.com/golang/protobuf/ptypes/timestamp"
|
|
||||||
"github.com/golang/protobuf/ptypes/wrappers"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestJSONPbMarshal(t *testing.T) {
|
|
||||||
msg := examplepb.ABitOfEverything{
|
|
||||||
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
Nested: []*examplepb.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Amount: 12345,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Uint64Value: 0xFFFFFFFFFFFFFFFF,
|
|
||||||
EnumValue: examplepb.NumericEnum_ONE,
|
|
||||||
OneofValue: &examplepb.ABitOfEverything_OneofString{
|
|
||||||
OneofString: "bar",
|
|
||||||
},
|
|
||||||
MapValue: map[string]examplepb.NumericEnum{
|
|
||||||
"a": examplepb.NumericEnum_ONE,
|
|
||||||
"b": examplepb.NumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, spec := range []struct {
|
|
||||||
enumsAsInts, emitDefaults bool
|
|
||||||
indent string
|
|
||||||
origName bool
|
|
||||||
verifier func(json string)
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
verifier: func(json string) {
|
|
||||||
if strings.ContainsAny(json, " \t\r\n") {
|
|
||||||
t.Errorf("strings.ContainsAny(%q, %q) = true; want false", json, " \t\r\n")
|
|
||||||
}
|
|
||||||
if !strings.Contains(json, "ONE") {
|
|
||||||
t.Errorf(`strings.Contains(%q, "ONE") = false; want true`, json)
|
|
||||||
}
|
|
||||||
if want := "uint64Value"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enumsAsInts: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if strings.Contains(json, "ONE") {
|
|
||||||
t.Errorf(`strings.Contains(%q, "ONE") = true; want false`, json)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
emitDefaults: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := `"sfixed32Value"`; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indent: "\t\t",
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := "\t\t\"amount\":"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
origName: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := "uint64_value"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
m := runtime.JSONPb{
|
|
||||||
EnumsAsInts: spec.enumsAsInts,
|
|
||||||
EmitDefaults: spec.emitDefaults,
|
|
||||||
Indent: spec.indent,
|
|
||||||
OrigName: spec.origName,
|
|
||||||
}
|
|
||||||
buf, err := m.Marshal(&msg)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%v) failed with %v; want success; spec=%v", &msg, err, spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
var got examplepb.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(string(buf), &got); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%q, &got) failed with %v; want success; spec=%v", string(buf), err, spec)
|
|
||||||
}
|
|
||||||
if want := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want %v; spec=%v", &got, &want, spec)
|
|
||||||
}
|
|
||||||
if spec.verifier != nil {
|
|
||||||
spec.verifier(string(buf))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbMarshalFields(t *testing.T) {
|
|
||||||
var m runtime.JSONPb
|
|
||||||
for _, spec := range []struct {
|
|
||||||
val interface{}
|
|
||||||
want string
|
|
||||||
}{} {
|
|
||||||
buf, err := m.Marshal(spec.val)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%#v) failed with %v; want success", spec.val, err)
|
|
||||||
}
|
|
||||||
if got, want := string(buf), spec.want; got != want {
|
|
||||||
t.Errorf("m.Marshal(%#v) = %q; want %q", spec.val, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.EnumsAsInts = true
|
|
||||||
buf, err := m.Marshal(examplepb.NumericEnum_ONE)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%#v) failed with %v; want success", examplepb.NumericEnum_ONE, err)
|
|
||||||
}
|
|
||||||
if got, want := string(buf), "1"; got != want {
|
|
||||||
t.Errorf("m.Marshal(%#v) = %q; want %q", examplepb.NumericEnum_ONE, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbUnmarshal(t *testing.T) {
|
|
||||||
var (
|
|
||||||
m runtime.JSONPb
|
|
||||||
got examplepb.ABitOfEverything
|
|
||||||
)
|
|
||||||
for _, data := range []string{
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": 18446744073709551615,
|
|
||||||
"enumValue": "ONE",
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": "18446744073709551615",
|
|
||||||
"enumValue": "ONE",
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": 18446744073709551615,
|
|
||||||
"enumValue": 1,
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
} {
|
|
||||||
if err := m.Unmarshal([]byte(data), &got); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(%q, &got) failed with %v; want success", data, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
want := examplepb.ABitOfEverything{
|
|
||||||
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
Nested: []*examplepb.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Amount: 12345,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Uint64Value: 0xFFFFFFFFFFFFFFFF,
|
|
||||||
EnumValue: examplepb.NumericEnum_ONE,
|
|
||||||
OneofValue: &examplepb.ABitOfEverything_OneofString{
|
|
||||||
OneofString: "bar",
|
|
||||||
},
|
|
||||||
MapValue: map[string]examplepb.NumericEnum{
|
|
||||||
"a": examplepb.NumericEnum_ONE,
|
|
||||||
"b": examplepb.NumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want = %v", &got, &want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbUnmarshalFields(t *testing.T) {
|
|
||||||
var m runtime.JSONPb
|
|
||||||
for _, fixt := range fieldFixtures {
|
|
||||||
if fixt.skipUnmarshal {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
dest := reflect.New(reflect.TypeOf(fixt.data))
|
|
||||||
if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(%q, %T) failed with %v; want success", fixt.json, dest.Interface(), err)
|
|
||||||
}
|
|
||||||
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("dest = %#v; want %#v; input = %v", got, want, fixt.json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbEncoder(t *testing.T) {
|
|
||||||
msg := examplepb.ABitOfEverything{
|
|
||||||
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
Nested: []*examplepb.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Amount: 12345,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Uint64Value: 0xFFFFFFFFFFFFFFFF,
|
|
||||||
OneofValue: &examplepb.ABitOfEverything_OneofString{
|
|
||||||
OneofString: "bar",
|
|
||||||
},
|
|
||||||
MapValue: map[string]examplepb.NumericEnum{
|
|
||||||
"a": examplepb.NumericEnum_ONE,
|
|
||||||
"b": examplepb.NumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, spec := range []struct {
|
|
||||||
enumsAsInts, emitDefaults bool
|
|
||||||
indent string
|
|
||||||
origName bool
|
|
||||||
verifier func(json string)
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
verifier: func(json string) {
|
|
||||||
if strings.ContainsAny(json, " \t\r\n") {
|
|
||||||
t.Errorf("strings.ContainsAny(%q, %q) = true; want false", json, " \t\r\n")
|
|
||||||
}
|
|
||||||
if strings.Contains(json, "ONE") {
|
|
||||||
t.Errorf(`strings.Contains(%q, "ONE") = true; want false`, json)
|
|
||||||
}
|
|
||||||
if want := "uint64Value"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enumsAsInts: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if strings.Contains(json, "ONE") {
|
|
||||||
t.Errorf(`strings.Contains(%q, "ONE") = true; want false`, json)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
emitDefaults: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := `"sfixed32Value"`; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indent: "\t\t",
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := "\t\t\"amount\":"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
origName: true,
|
|
||||||
verifier: func(json string) {
|
|
||||||
if want := "uint64_value"; !strings.Contains(json, want) {
|
|
||||||
t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
m := runtime.JSONPb{
|
|
||||||
EnumsAsInts: spec.enumsAsInts,
|
|
||||||
EmitDefaults: spec.emitDefaults,
|
|
||||||
Indent: spec.indent,
|
|
||||||
OrigName: spec.origName,
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := m.NewEncoder(&buf)
|
|
||||||
if err := enc.Encode(&msg); err != nil {
|
|
||||||
t.Errorf("enc.Encode(%v) failed with %v; want success; spec=%v", &msg, err, spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
var got examplepb.ABitOfEverything
|
|
||||||
if err := jsonpb.UnmarshalString(buf.String(), &got); err != nil {
|
|
||||||
t.Errorf("jsonpb.UnmarshalString(%q, &got) failed with %v; want success; spec=%v", buf.String(), err, spec)
|
|
||||||
}
|
|
||||||
if want := msg; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want %v; spec=%v", &got, &want, spec)
|
|
||||||
}
|
|
||||||
if spec.verifier != nil {
|
|
||||||
spec.verifier(buf.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbEncoderFields(t *testing.T) {
|
|
||||||
var m runtime.JSONPb
|
|
||||||
for _, fixt := range fieldFixtures {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := m.NewEncoder(&buf)
|
|
||||||
if err := enc.Encode(fixt.data); err != nil {
|
|
||||||
t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
|
|
||||||
}
|
|
||||||
if got, want := buf.String(), fixt.json; got != want {
|
|
||||||
t.Errorf("enc.Encode(%#v) = %q; want %q", fixt.data, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.EnumsAsInts = true
|
|
||||||
buf, err := m.Marshal(examplepb.NumericEnum_ONE)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("m.Marshal(%#v) failed with %v; want success", examplepb.NumericEnum_ONE, err)
|
|
||||||
}
|
|
||||||
if got, want := string(buf), "1"; got != want {
|
|
||||||
t.Errorf("m.Marshal(%#v) = %q; want %q", examplepb.NumericEnum_ONE, got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbDecoder(t *testing.T) {
|
|
||||||
var (
|
|
||||||
m runtime.JSONPb
|
|
||||||
got examplepb.ABitOfEverything
|
|
||||||
)
|
|
||||||
for _, data := range []string{
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": 18446744073709551615,
|
|
||||||
"enumValue": "ONE",
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": "18446744073709551615",
|
|
||||||
"enumValue": "ONE",
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
`{
|
|
||||||
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
"nested": [
|
|
||||||
{"name": "foo", "amount": 12345}
|
|
||||||
],
|
|
||||||
"uint64Value": 18446744073709551615,
|
|
||||||
"enumValue": 1,
|
|
||||||
"oneofString": "bar",
|
|
||||||
"mapValue": {
|
|
||||||
"a": 1,
|
|
||||||
"b": 0
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
} {
|
|
||||||
r := strings.NewReader(data)
|
|
||||||
dec := m.NewDecoder(r)
|
|
||||||
if err := dec.Decode(&got); err != nil {
|
|
||||||
t.Errorf("m.Unmarshal(&got) failed with %v; want success; data=%q", err, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
want := examplepb.ABitOfEverything{
|
|
||||||
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
|
|
||||||
Nested: []*examplepb.ABitOfEverything_Nested{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Amount: 12345,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Uint64Value: 0xFFFFFFFFFFFFFFFF,
|
|
||||||
EnumValue: examplepb.NumericEnum_ONE,
|
|
||||||
OneofValue: &examplepb.ABitOfEverything_OneofString{
|
|
||||||
OneofString: "bar",
|
|
||||||
},
|
|
||||||
MapValue: map[string]examplepb.NumericEnum{
|
|
||||||
"a": examplepb.NumericEnum_ONE,
|
|
||||||
"b": examplepb.NumericEnum_ZERO,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("got = %v; want = %v; data = %v", &got, &want, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJSONPbDecoderFields(t *testing.T) {
|
|
||||||
var m runtime.JSONPb
|
|
||||||
for _, fixt := range fieldFixtures {
|
|
||||||
if fixt.skipUnmarshal {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
dest := reflect.New(reflect.TypeOf(fixt.data))
|
|
||||||
dec := m.NewDecoder(strings.NewReader(fixt.json))
|
|
||||||
if err := dec.Decode(dest.Interface()); err != nil {
|
|
||||||
t.Errorf("dec.Decode(%T) failed with %v; want success; input = %q", dest.Interface(), err, fixt.json)
|
|
||||||
}
|
|
||||||
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
|
|
||||||
t.Errorf("dest = %#v; want %#v; input = %v", got, want, fixt.json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
fieldFixtures = []struct {
|
|
||||||
data interface{}
|
|
||||||
json string
|
|
||||||
skipUnmarshal bool
|
|
||||||
}{
|
|
||||||
{data: int32(1), json: "1"},
|
|
||||||
{data: proto.Int32(1), json: "1"},
|
|
||||||
{data: int64(1), json: "1"},
|
|
||||||
{data: proto.Int64(1), json: "1"},
|
|
||||||
{data: uint32(1), json: "1"},
|
|
||||||
{data: proto.Uint32(1), json: "1"},
|
|
||||||
{data: uint64(1), json: "1"},
|
|
||||||
{data: proto.Uint64(1), json: "1"},
|
|
||||||
{data: "abc", json: `"abc"`},
|
|
||||||
{data: proto.String("abc"), json: `"abc"`},
|
|
||||||
{data: float32(1.5), json: "1.5"},
|
|
||||||
{data: proto.Float32(1.5), json: "1.5"},
|
|
||||||
{data: float64(1.5), json: "1.5"},
|
|
||||||
{data: proto.Float64(1.5), json: "1.5"},
|
|
||||||
{data: true, json: "true"},
|
|
||||||
{data: false, json: "false"},
|
|
||||||
{data: (*string)(nil), json: "null"},
|
|
||||||
{
|
|
||||||
data: examplepb.NumericEnum_ONE,
|
|
||||||
json: `"ONE"`,
|
|
||||||
// TODO(yugui) support unmarshaling of symbolic enum
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: (*examplepb.NumericEnum)(proto.Int32(int32(examplepb.NumericEnum_ONE))),
|
|
||||||
json: `"ONE"`,
|
|
||||||
// TODO(yugui) support unmarshaling of symbolic enum
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
data: map[string]int32{
|
|
||||||
"foo": 1,
|
|
||||||
},
|
|
||||||
json: `{"foo":1}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: map[string]*examplepb.SimpleMessage{
|
|
||||||
"foo": {Id: "bar"},
|
|
||||||
},
|
|
||||||
json: `{"foo":{"id":"bar"}}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: map[int32]*examplepb.SimpleMessage{
|
|
||||||
1: {Id: "foo"},
|
|
||||||
},
|
|
||||||
json: `{"1":{"id":"foo"}}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: map[bool]*examplepb.SimpleMessage{
|
|
||||||
true: {Id: "foo"},
|
|
||||||
},
|
|
||||||
json: `{"true":{"id":"foo"}}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &duration.Duration{
|
|
||||||
Seconds: 123,
|
|
||||||
Nanos: 456000000,
|
|
||||||
},
|
|
||||||
json: `"123.456s"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: ×tamp.Timestamp{
|
|
||||||
Seconds: 1462875553,
|
|
||||||
Nanos: 123000000,
|
|
||||||
},
|
|
||||||
json: `"2016-05-10T10:19:13.123Z"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: new(empty.Empty),
|
|
||||||
json: "{}",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO(yugui) Enable unmarshaling of the following examples
|
|
||||||
// once jsonpb supports them.
|
|
||||||
{
|
|
||||||
data: &structpb.Value{
|
|
||||||
Kind: new(structpb.Value_NullValue),
|
|
||||||
},
|
|
||||||
json: "null",
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &structpb.Value{
|
|
||||||
Kind: &structpb.Value_NumberValue{
|
|
||||||
NumberValue: 123.4,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
json: "123.4",
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &structpb.Value{
|
|
||||||
Kind: &structpb.Value_StringValue{
|
|
||||||
StringValue: "abc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
json: `"abc"`,
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &structpb.Value{
|
|
||||||
Kind: &structpb.Value_BoolValue{
|
|
||||||
BoolValue: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
json: "true",
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &structpb.Struct{
|
|
||||||
Fields: map[string]*structpb.Value{
|
|
||||||
"foo_bar": {
|
|
||||||
Kind: &structpb.Value_BoolValue{
|
|
||||||
BoolValue: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
json: `{"foo_bar":true}`,
|
|
||||||
skipUnmarshal: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
data: &wrappers.BoolValue{Value: true},
|
|
||||||
json: "true",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.DoubleValue{Value: 123.456},
|
|
||||||
json: "123.456",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.FloatValue{Value: 123.456},
|
|
||||||
json: "123.456",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.Int32Value{Value: -123},
|
|
||||||
json: "-123",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.Int64Value{Value: -123},
|
|
||||||
json: `"-123"`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.UInt32Value{Value: 123},
|
|
||||||
json: "123",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: &wrappers.UInt64Value{Value: 123},
|
|
||||||
json: `"123"`,
|
|
||||||
},
|
|
||||||
// TODO(yugui) Add other well-known types once jsonpb supports them
|
|
||||||
}
|
|
||||||
)
|
|
42
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go
generated
vendored
42
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go
generated
vendored
@ -1,42 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
|
|
||||||
type Marshaler interface {
|
|
||||||
// Marshal marshals "v" into byte sequence.
|
|
||||||
Marshal(v interface{}) ([]byte, error)
|
|
||||||
// Unmarshal unmarshals "data" into "v".
|
|
||||||
// "v" must be a pointer value.
|
|
||||||
Unmarshal(data []byte, v interface{}) error
|
|
||||||
// NewDecoder returns a Decoder which reads byte sequence from "r".
|
|
||||||
NewDecoder(r io.Reader) Decoder
|
|
||||||
// NewEncoder returns an Encoder which writes bytes sequence into "w".
|
|
||||||
NewEncoder(w io.Writer) Encoder
|
|
||||||
// ContentType returns the Content-Type which this marshaler is responsible for.
|
|
||||||
ContentType() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decoder decodes a byte sequence
|
|
||||||
type Decoder interface {
|
|
||||||
Decode(v interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encoder encodes gRPC payloads / fields into byte sequence.
|
|
||||||
type Encoder interface {
|
|
||||||
Encode(v interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecoderFunc adapts an decoder function into Decoder.
|
|
||||||
type DecoderFunc func(v interface{}) error
|
|
||||||
|
|
||||||
// Decode delegates invocations to the underlying function itself.
|
|
||||||
func (f DecoderFunc) Decode(v interface{}) error { return f(v) }
|
|
||||||
|
|
||||||
// EncoderFunc adapts an encoder function into Encoder
|
|
||||||
type EncoderFunc func(v interface{}) error
|
|
||||||
|
|
||||||
// Encode delegates invocations to the underlying function itself.
|
|
||||||
func (f EncoderFunc) Encode(v interface{}) error { return f(v) }
|
|
91
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go
generated
vendored
91
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go
generated
vendored
@ -1,91 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MIMEWildcard is the fallback MIME type used for requests which do not match
|
|
||||||
// a registered MIME type.
|
|
||||||
const MIMEWildcard = "*"
|
|
||||||
|
|
||||||
var (
|
|
||||||
acceptHeader = http.CanonicalHeaderKey("Accept")
|
|
||||||
contentTypeHeader = http.CanonicalHeaderKey("Content-Type")
|
|
||||||
|
|
||||||
defaultMarshaler = &JSONPb{OrigName: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// MarshalerForRequest returns the inbound/outbound marshalers for this request.
|
|
||||||
// It checks the registry on the ServeMux for the MIME type set by the Content-Type header.
|
|
||||||
// If it isn't set (or the request Content-Type is empty), checks for "*".
|
|
||||||
// If there are multiple Content-Type headers set, choose the first one that it can
|
|
||||||
// exactly match in the registry.
|
|
||||||
// Otherwise, it follows the above logic for "*"/InboundMarshaler/OutboundMarshaler.
|
|
||||||
func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler) {
|
|
||||||
for _, acceptVal := range r.Header[acceptHeader] {
|
|
||||||
if m, ok := mux.marshalers.mimeMap[acceptVal]; ok {
|
|
||||||
outbound = m
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, contentTypeVal := range r.Header[contentTypeHeader] {
|
|
||||||
if m, ok := mux.marshalers.mimeMap[contentTypeVal]; ok {
|
|
||||||
inbound = m
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if inbound == nil {
|
|
||||||
inbound = mux.marshalers.mimeMap[MIMEWildcard]
|
|
||||||
}
|
|
||||||
if outbound == nil {
|
|
||||||
outbound = inbound
|
|
||||||
}
|
|
||||||
|
|
||||||
return inbound, outbound
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshalerRegistry is a mapping from MIME types to Marshalers.
|
|
||||||
type marshalerRegistry struct {
|
|
||||||
mimeMap map[string]Marshaler
|
|
||||||
}
|
|
||||||
|
|
||||||
// add adds a marshaler for a case-sensitive MIME type string ("*" to match any
|
|
||||||
// MIME type).
|
|
||||||
func (m marshalerRegistry) add(mime string, marshaler Marshaler) error {
|
|
||||||
if len(mime) == 0 {
|
|
||||||
return errors.New("empty MIME type")
|
|
||||||
}
|
|
||||||
|
|
||||||
m.mimeMap[mime] = marshaler
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// makeMarshalerMIMERegistry returns a new registry of marshalers.
|
|
||||||
// It allows for a mapping of case-sensitive Content-Type MIME type string to runtime.Marshaler interfaces.
|
|
||||||
//
|
|
||||||
// For example, you could allow the client to specify the use of the runtime.JSONPb marshaler
|
|
||||||
// with a "applicaton/jsonpb" Content-Type and the use of the runtime.JSONBuiltin marshaler
|
|
||||||
// with a "application/json" Content-Type.
|
|
||||||
// "*" can be used to match any Content-Type.
|
|
||||||
// This can be attached to a ServerMux with the marshaler option.
|
|
||||||
func makeMarshalerMIMERegistry() marshalerRegistry {
|
|
||||||
return marshalerRegistry{
|
|
||||||
mimeMap: map[string]Marshaler{
|
|
||||||
MIMEWildcard: defaultMarshaler,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMarshalerOption returns a ServeMuxOption which associates inbound and outbound
|
|
||||||
// Marshalers to a MIME type in mux.
|
|
||||||
func WithMarshalerOption(mime string, marshaler Marshaler) ServeMuxOption {
|
|
||||||
return func(mux *ServeMux) {
|
|
||||||
if err := mux.marshalers.add(mime, marshaler); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
107
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry_test.go
generated
vendored
107
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry_test.go
generated
vendored
@ -1,107 +0,0 @@
|
|||||||
package runtime_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMarshalerForRequest(t *testing.T) {
|
|
||||||
r, err := http.NewRequest("GET", "http://example.com", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf(`http.NewRequest("GET", "http://example.com", nil) failed with %v; want success`, err)
|
|
||||||
}
|
|
||||||
r.Header.Set("Accept", "application/x-out")
|
|
||||||
r.Header.Set("Content-Type", "application/x-in")
|
|
||||||
|
|
||||||
mux := runtime.NewServeMux()
|
|
||||||
|
|
||||||
in, out := runtime.MarshalerForRequest(mux, r)
|
|
||||||
if _, ok := in.(*runtime.JSONPb); !ok {
|
|
||||||
t.Errorf("in = %#v; want a runtime.JSONPb", in)
|
|
||||||
}
|
|
||||||
if _, ok := out.(*runtime.JSONPb); !ok {
|
|
||||||
t.Errorf("out = %#v; want a runtime.JSONPb", in)
|
|
||||||
}
|
|
||||||
|
|
||||||
var marshalers [3]dummyMarshaler
|
|
||||||
specs := []struct {
|
|
||||||
opt runtime.ServeMuxOption
|
|
||||||
|
|
||||||
wantIn runtime.Marshaler
|
|
||||||
wantOut runtime.Marshaler
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
opt: runtime.WithMarshalerOption(runtime.MIMEWildcard, &marshalers[0]),
|
|
||||||
wantIn: &marshalers[0],
|
|
||||||
wantOut: &marshalers[0],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
opt: runtime.WithMarshalerOption("application/x-in", &marshalers[1]),
|
|
||||||
wantIn: &marshalers[1],
|
|
||||||
wantOut: &marshalers[0],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
opt: runtime.WithMarshalerOption("application/x-out", &marshalers[2]),
|
|
||||||
wantIn: &marshalers[1],
|
|
||||||
wantOut: &marshalers[2],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for i, spec := range specs {
|
|
||||||
var opts []runtime.ServeMuxOption
|
|
||||||
for _, s := range specs[:i+1] {
|
|
||||||
opts = append(opts, s.opt)
|
|
||||||
}
|
|
||||||
mux = runtime.NewServeMux(opts...)
|
|
||||||
|
|
||||||
in, out = runtime.MarshalerForRequest(mux, r)
|
|
||||||
if got, want := in, spec.wantIn; got != want {
|
|
||||||
t.Errorf("in = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
if got, want := out, spec.wantOut; got != want {
|
|
||||||
t.Errorf("out = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Header.Set("Content-Type", "application/x-another")
|
|
||||||
in, out = runtime.MarshalerForRequest(mux, r)
|
|
||||||
if got, want := in, &marshalers[1]; got != want {
|
|
||||||
t.Errorf("in = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
if got, want := out, &marshalers[0]; got != want {
|
|
||||||
t.Errorf("out = %#v; want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type dummyMarshaler struct{}
|
|
||||||
|
|
||||||
func (dummyMarshaler) ContentType() string { return "" }
|
|
||||||
func (dummyMarshaler) Marshal(interface{}) ([]byte, error) {
|
|
||||||
return nil, errors.New("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dummyMarshaler) Unmarshal([]byte, interface{}) error {
|
|
||||||
return errors.New("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dummyMarshaler) NewDecoder(r io.Reader) runtime.Decoder {
|
|
||||||
return dummyDecoder{}
|
|
||||||
}
|
|
||||||
func (dummyMarshaler) NewEncoder(w io.Writer) runtime.Encoder {
|
|
||||||
return dummyEncoder{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type dummyDecoder struct{}
|
|
||||||
|
|
||||||
func (dummyDecoder) Decode(interface{}) error {
|
|
||||||
return errors.New("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
type dummyEncoder struct{}
|
|
||||||
|
|
||||||
func (dummyEncoder) Encode(interface{}) error {
|
|
||||||
return errors.New("not implemented")
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user