Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace our own custom option with the one defined by Google #12

Merged
merged 29 commits into from
May 9, 2015
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ea9f6ac
Import a definition of a custom option from github.com/google/googleapis
yugui Apr 23, 2015
9bf40a9
Generate Go files from the new annotation .proto files.
yugui Apr 23, 2015
d08615b
Implement runtime pattern matcher
yugui Apr 24, 2015
ae7afe3
Support verb part of the template pattern
yugui Apr 24, 2015
3daa1df
Add String() to runtime.Pattern.
yugui Apr 25, 2015
a8d4491
Export opcodes in internal/ package.
yugui Apr 26, 2015
e407fb1
Add path template parser
yugui Apr 26, 2015
34560be
Implement compiler from AST to opcodes
yugui Apr 27, 2015
2b41609
Fix golint and go tool vet errors
yugui Apr 27, 2015
0ad57f7
Export bound fields from httprule.Template
yugui Apr 27, 2015
d8bcb11
Add Pattern-based request multiplexer
yugui Apr 28, 2015
f709571
Add intermediate representation of services and messages
yugui May 4, 2015
af1c482
Reimplement code generator with httprule and descriptor packages.
yugui May 4, 2015
5783729
Update examples with the new protoc plugin
yugui May 4, 2015
85ef5cf
Deprecate the old custom option
yugui May 4, 2015
415c655
Update README.md
yugui May 4, 2015
9b048b1
Extract go package reservation from descriptor loader to code generator
yugui May 4, 2015
8cfb28f
Remove test files from the list of plugin sources
yugui May 4, 2015
b807c97
Renumber an ordered list
yugui May 4, 2015
d8399af
Fix golint and go vet errors in runtime/
yugui May 4, 2015
a584b49
Fix a golint error in internal/
yugui May 4, 2015
adba95a
Fix golint and go vet errrors in descriptor/
yugui May 4, 2015
8308b8f
Fix golint and go vet errors in gengateway
yugui May 4, 2015
169d51e
Fix go vet errors in generated codes
yugui May 4, 2015
17fee9f
Merge branch 'master' into feature/google-http-rule
yugui May 4, 2015
593bfcc
Adjust log verbosity
yugui May 4, 2015
0691d05
Correct example codes
yugui May 5, 2015
9b03271
Remove decoder configurtion from descriptor.Body
yugui May 5, 2015
334e625
Update README.md
yugui May 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ GO_PLUGIN=bin/protoc-gen-go
GO_PLUGIN_PKG=github.com/golang/protobuf/protoc-gen-go
GATEWAY_PLUGIN=bin/protoc-gen-grpc-gateway
GATEWAY_PLUGIN_PKG=$(PKG)/protoc-gen-grpc-gateway
GATEWAY_PLUGIN_SRC=protoc-gen-grpc-gateway/main.go \
protoc-gen-grpc-gateway/generator.go
OPTIONS_GO=options/options.pb.go
OPTIONS_PROTO=options/options.proto
GATEWAY_PLUGIN_SRC= protoc-gen-grpc-gateway/descriptor/name.go \
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/gengateway/generator.go \
protoc-gen-grpc-gateway/gengateway/template.go \
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

GOOGLEAPIS_DIR=third_party/googleapis
OPTIONS_PROTO=$(GOOGLEAPIS_DIR)/google/api/annotations.proto $(GOOGLEAPIS_DIR)/google/api/http.proto
OPTIONS_GO=$(OPTIONS_PROTO:.proto=.pb.go)

PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mexamples/sub/message.proto=$(PKG)/examples/sub
EXAMPLES=examples/echo_service.proto \
examples/a_bit_of_everything.proto
Expand All @@ -25,21 +36,22 @@ $(GO_PLUGIN):
go build -o $@ $(GO_PLUGIN_PKG)

$(OPTIONS_GO): $(OPTIONS_PROTO) $(GO_PLUGIN)
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP):. $(OPTIONS_PROTO)
protoc -I $(PROTOC_INC_PATH) -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP):$(GOOGLEAPIS_DIR) $(OPTIONS_PROTO)

$(GATEWAY_PLUGIN): $(OPTIONS_GO) $(GATEWAY_PLUGIN_SRC)
go build -o $@ $(GATEWAY_PLUGIN_PKG)

$(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc:. $(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)
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc:. $(EXAMPLE_DEPS)
$(EXAMPLE_GWSRCS): $(GATEWAY_PLUGIN) $(EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GATEWAY_PLUGIN) --grpc-gateway_out=logtostderr=true,import_prefix=$(PKG):. $(EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GATEWAY_PLUGIN) --grpc-gateway_out=logtostderr=true,$(PKGMAP):. $(EXAMPLES)

test: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS)
go test $(PKG)/...

clean distclean:
realclean:
rm -f $(OPTIONS_GO)
rm -f $(EXAMPLE_SVCSRCS) $(EXAMPLE_DEPSRCS)
Expand Down
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
```diff
syntax = "proto3";
package example;
+import "github.com/gengo/grpc-gateway/options/options.proto";
+
+import "github.com/gengo/grpc-gateway/third_party/googleapis/google/api/annnotations.proto";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One too many n's in annotations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. thx

+
message StringMessage {
string value = 1;
}

service YourService {
- rpc Echo(StringMessage) returns (StringMessage) {}
+ rpc Echo(StringMessage) returns (StringMessage) {
+ option (gengo.grpc.gateway.ApiMethodOptions.api_options) = {
+ option (google.api.http) = {
+ path: "/v1/example/echo"
+ method: "POST"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this part of the example need to be updated to match the Google api definitions?

If I understand correctly, it should now be:

post: "/v1/example/echo"
body: "*"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

+ };
Expand All @@ -86,8 +86,21 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
```

It will generate a stub file `path/to/your_service.pb.go`.
Now you can implement your service on top of the stub.
4. Generate reverse-proxy
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 --ruby_out=. \
path/to/your/service_proto

protoc -I/usr/local/include -I. -I$GOPATH/src \
--plugin=protoc-gen-grpc-ruby=grpc_ruby_plugin \
--grpc-ruby_out=. \
path/to/your/service.proto
```
2. Implement your service
5. Generate reverse-proxy

```sh
protoc -I/usr/local/include -I. -I$GOPATH/src \
Expand All @@ -96,7 +109,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
```

It will generate a reverse proxy `path/to/your_service.pb.gw.go`.
5. Write an entrypoint
6. Write an entrypoint

Now you need to write an entrypoint of the proxy server.
```go
Expand All @@ -106,8 +119,8 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
"net/http"

"github.com/golang/glog"
"github.com/zenazn/goji/web"
"golang.org/x/net/context"
"github.com/gengo/grpc-gateway/runtime"

gw "path/to/your_service_package"
)
Expand All @@ -121,7 +134,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
ctx, cancel := context.WithCancel(ctx)
defer cancel()

mux := web.New()
mux := runtime.NewServeMux()
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion examples/a_bit_of_everything.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading