1

I want to use a custom Handler( Specifically want to use a chi router) in gRPC. I have tried to search on the internet but don’t found help to set a custom handler in the gRPC server.

Below is the code for my chi handler and I want to set it in gRPC server.

func (app *Config) routes() http.Handler {
    mux := chi.NewRouter()

    // specify who is allowed to connect
    mux.Use(cors.Handler(cors.Options{
        AllowedOrigins:   []string{"https://*", "http://*"},
        AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
        AllowedHeaders:   []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
        ExposedHeaders:   []string{"Link"},
        AllowCredentials: true,
        MaxAge:           300,
    }))
    mux.Use(middleware.Heartbeat("/ping"))

    mux.Get("/", app.RequestCome)
    mux.Post("/authenticate", app.Authenticate)
    return mux
}

Thanks

Girish Bhutiya
  • 3,111
  • 5
  • 31
  • 50
  • 3
    chi is an HTTP router that facilitates the handling of REST requests, where REST itself is a convention for client-server communication based on the stateless HTTP protocol. In gRPC, as in other RPC systems, services are provided with remotely callable methods (with defined parameters and return types). Clients invoke these via a stub that provides the same methods as the server. Both pursue a similar objective but are two fundamentally different approaches. Therefore, it is unclear to me what you actually want to achieve. – Stephan Schlecht Jan 22 '23 at 09:51
  • I want to use chi as a handler but if not possible then I will try the gRPC default way as per official documentation. – Girish Bhutiya Jan 22 '23 at 11:48

0 Answers0