How to use Chi with connect-go? #738
-
Hello, I have a simple application based on the ubiquitous Greeter example at grpc's website. After generating, building, and running the server using Chi's mux, curl, grpcurl, and 'buf curl' requests all fail. However, when I replace Chi's mux with a ServeMux, they work. I'd appreciate any ideas on correcting this error so I can use Chi and its middleware with a Connect app. I've posted the source at the bottom of the post. I am using buf v1.32, Go go1.22.3 darwin/amd64, and Chi v5.0.12. Thank you for your time and suggestions! Here are the commands and results: // GRPC ERROR: // HTTP // CONNECT // SOURCE CODE
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is more a chi question. Chi's mux.Handle doesn't have the same behavior as net/http's mux.Handle. The mux.Mount(helloworldv1connect.NewGreeterServiceHandler(&GreeterServer{})) |
Beta Was this translation helpful? Give feedback.
This is more a chi question. Chi's mux.Handle doesn't have the same behavior as net/http's mux.Handle. The
net/http
handler treats the first argument as a prefix. Chi treats the first argument as a pattern. Therefore, you can't use the result ofNewGreeterServiceHandler
as the arguments to chi's mux.Handle function. However, chi does have a separate method,mux.Mount
(https://pkg.go.dev/github.com/go-chi/chi/v5#Mux.Mount) that has a similar behavior tonet/http
's mux.Handle.