connectrpc / connect-go

The Go implementation of Connect: Protobuf RPC that works.
https://connectrpc.com
Apache License 2.0
2.76k stars 90 forks source link

Any non mux router support for connectrpc? #752

Closed tahadostifam closed 2 weeks ago

tahadostifam commented 2 weeks ago

Hi, Recently i've been using connectrpc to handle my json-rpc gateway and i realized connectrpc does not support non http.ServeMux router, right?

Let me know i'm wrong!

emcfarlane commented 2 weeks ago

Connect-go does support any router that implements the net/http Handler method. For example in the docs for routing the generated handler return the route prefix and a http.Handler which can be directly passed to a server mux. See the generated NewPingServiceHandler for reference to the type signature. Closing, but feel free to ask more questions about specific routers.

tahadostifam commented 2 weeks ago

So is there any solution to handle my connectrpc with gin? Sorry but i'm a little confused😅

emcfarlane commented 2 weeks ago

For gin use the WrapH to register to the gin handler. This will look something like:

router := gin.Default()
pingServiceRoute, pingServiceHandler := pingv1connect.NewPingServiceHandler()
router.POST(pingServiceRoute, gin.WrapH(pingServiceHandler))
tahadostifam commented 2 weeks ago

I got it. Thank you so much Edward😄❤️🤌🏿