-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add method middleware via gateway-specific method annotations #305
Conversation
add middleware support
ac3daff
to
91abef3
Compare
@shilkin Thank you for your contribution. This is quite interesting. Can you please sign the Google CLA? This merits some wider discussion and better documentation but in general I'm open to the approach. A few questions that immediately come to mind:
|
} | ||
|
||
// Register{{$svc.GetName}}HandlerFromEndpointMiddlware is same as Register{{$svc.GetName}}HandlerMiddleware but | ||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should document this difference and spell 'Middlware' correctly.
Perhaps instead with would introduce a more general WithOptions call or extend Register{{$svc.GetName}}Handler to support variadic options functions.
@@ -0,0 +1,4 @@ | |||
package runtime | |||
|
|||
// Middleware is an interface which allows to create chains of handler functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is grammatically kind of awkward.
@@ -62,12 +62,13 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. | |||
} | |||
``` | |||
2. Add a [custom option](https://cloud.google.com/service-management/reference/rpc/google.api#http) to the .proto file | |||
|
|||
Also you can customize every http handler with middleware. Just add gengo.grpc.gateway.middleware option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document this in a distinct section and keep the original example simple.
@@ -0,0 +1,11 @@ | |||
syntax = "proto3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file might more appropriately be named something more general in the context of attaching additional annotations to methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most appropriate is 'options' but this name is busy and deprecated.
I can move this extension to options.proto
What can you suggest?
Anyway we can declare different options in different files.
First of all excuse me for my english:-)
If I undestand you correctly we speaking about things like this or this.
Well quick answer on the first question: I don't know:-) But we can use more complex data structure for method option (instead of simple string). This structure may be a point of extension.
I think we shouldn't. I prefer to think about exactly method options. If some day we will need to extend service or file options, we will have to declare a new structures. |
UCS-183 | merge ucs-183 updates
…iddleware-ucs-183
Pr middleware ucs 183
UCS-183 | method options refactoring
UCS-183 | fix descriptor unit tests
@shilkin : Thanks for making this generic. I tried to run the instructions you have in README, I think you need to change |
@tmc Please, look at current versoin. |
@shilkin, thanks for sending in your thoughts! I'm excited to see new ideas propagating through the grpc ecosystem. I have a couple of questions about this change as well. I spent some time thinking about your change in the context of a project I'm working on and had a few questions.
I really like the idea of having a better story for middleware, but I wonder if we can make a more idiomatic go interface for doing it. For example, in gRPC, grpc.NewServer takes an optional set of ServerOptions. These provide a very flexible point fo extending the gRPC server. As a strawman example of what that might look like. What do you think about something like
One of the things I like about this is that it gives us an obvious path forward for HTTP extensibility. You could use this not just for middleware but for getting monitoring hooks into the internals of the gRPC-gateway runtime. |
Hello! I need to have a reverse proxy with custom middleware for some http handlres. I hope I implemented it in a generic manner. My version of generated code is backward compatible. May be it would be usefull for other developers. Thanks!
Unit tests +
Documentation +
Backward compatibility +