-
Notifications
You must be signed in to change notification settings - Fork 945
Triple header/trailer usage pattern proposal #2422
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
Comments
client-side sending headersctx := triple.NewOutgoingContext(context.Background(), http.Header{"hello", "triple"})
resp, err := cli.Greet(ctx, &v1.GreetRequest{})
// or
ctx := triple.NewOutgoingContext(context.Background(), http.Header{"hello", "triple"})
ctx = triple.AppendToOutgoingContext(ctx, "hello", "dubbo", "hey", "hessian")
resp, err := cli.Greet(ctx, &v1.GreetRequest{})
// headers would be hello: triple, dubbo; hey: hessian. client-side receiving headers and trailersWIP server-side receiving headersfunc (srv *Server) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
headers, ok := triple.FromIncomingContext(ctx)
// do something with headers and ok flag
} server-side sending headers and trailersfunc (srv *Server) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
triple.SetHeader(ctx, http.Header{"hi", "triple"})
triple.SetTrailer(ctx, http.Header("end", "end"))
}
func (srv *Server) GreetStream(ctx context.Context, stream greet.GreetService_GreetStreamServer) error {
// stream could also make use of triple.SetHeader and triple.SetTrailer
// headers would be sent in the first call of stream.Send
// in some scenarios, users would hope to send headers directly
triple.Send(ctx, http.Header{"hi", "triple"})
} |
Refer to (https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md) for more information. |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New Triple is based on connect-go (https://github.com/connectrpc/connect-go) which makes use of Golang generic feature. For instance, client and server side code of unary invocation would be like this:
Users could inject or receive headers and trailers directly from Request and Response just like this:
This pattern is very uniform and easy to understand. But since we decided not to use generics API for compatibility, new Triple has to make use of some grpc-like pattern to send and receive headers and trailers.
The text was updated successfully, but these errors were encountered: