You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
// client sidereq:=connect.NewRequest(&pingv1.PingRequest{})
req.Header().Set("hello", "wourld")
resp, err:=Ping(context.Background(), req)
headers:=resp.Header().Values("hello")
trailers:=resp.Trailer().Values()
// do something with headers and trailers
// server sidefunc (p*pingServer) Ping(ctx context.Context, req*connect.Request[pingv1.PingRequest]) (*connect.Response[pingv1.PingResponse], error) {
headers:=req.Headers().Values("hello")
// do something with headersresponse:=connect.NewResponse(
&pingv1.PingResponse{},
)
// return headers and trailersresponse.Header().Set(handlerHeader, headerValue)
response.Trailer().Set(handlerTrailer, trailerValue)
returnresponse, nil
}
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:
func (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 trailers
func (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 directlytriple.Send(ctx, http.Header{"hi", "triple"})
}
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: