Replies: 3 comments 4 replies
-
I can understand why you might want this, especially if you like layered architecture. I'll spend a little time prototyping in We had a fairly elaborate version of this earlier in Connect's development: it went even further than you're suggesting and allowed you to choose on a method-by-method basis whether you'd rather implement the raw or generic version of each RPC. We dropped it because it required quite a bit more code generation, and feedback from early users was that the generics weren't a problem. If you'd like to get started with something today, you can use a generic function to convert any single func generify[Req any, Res any](
f func(context.Context, *Req) (*Res, error),
) func(context.Context, *connect.Request[Req]) (*connect.Response[Res], error) {
return func(ctx context.Context, req *connect.Request[Req]) (*connect.Response[Res], error) {
res, err := f(ctx, req.Msg)
if err != nil {
return nil, err
}
return connect.NewResponse(res), nil
}
} That helps a little, but you'll still end up writing a lot of boilerplate structs. It's possible that some of the boilerplate could be removed with a combination of Go and Protobuf reflection, but I'd need to spend some time figuring out how. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'd like to add that this generics is a stopper for the easy switch to connect-go. I have a project which used 3 transport implementation for grpc: pure grpc, improbable-eng/grpc-web and gprc over web-rtc data channel. All transports supports the classic service interfaces in backend. It allows to switch transport or support multiple transports per one service. |
Beta Was this translation helpful? Give feedback.
-
What you think about creating the wrapper methods with option provided? This is a deal breaker honestly. Any updates on this? is vanguard a good solution for this problem? is there any tradoffs for using vanguard? like perf? etc |
Beta Was this translation helpful? Give feedback.
-
I am currently evaluating the usage of connect-go. I understand the advantages of having generics for request and response objects which allow accessing HTTP headers and I also understand that they are required for streaming.
In my use-case however, about 99% of the calls are non-streaming and require no access to HTTP headers. In fact, since I would like to use connect-go in the application layer and I do not want to have things like HTTP headers (or even connect-go) in the application layer, I would prefer to be just able to implement the raw service interfaces (similar to GRPC). This would it also make it easier to call functions from non-HTTP contexts (e.g. a CLI) or other functions, since someone does not have to create fake connect.Requests to do that.
So, basically I would like something like:
What do you think? Is there any other way to achieve a similar result?
Beta Was this translation helpful? Give feedback.
All reactions