Stop http.ListenAndServe gRPCEndpoint

Hello, such a problem, I can’t figure out how to correctly stop the proxy server for gRPC by signal os.Interrupt, I stop the server myself like this:

   c := make(chan os.Signal)
   signal.Notify(c, os.Interrupt)

go func() {
	<-c

	log.Printf("Stopping the Result-Server %s:%d", conf.Host, conf.Port)
	serv.GracefulStop()
	lis.Close()

	close(c)
}()

but how can I do the same with http proxe for gRPC I can not understand, please tell me how can I do this? Shutdown (context.TODO ()) I can’t use here

func NewHTTPServerStart(conf config.GRPCConfig, httpConf config.HTTPConfig) error {
mux := runtime.NewServeMux()

opts := []grpc.DialOption{grpc.WithInsecure()}

gRPCEndpoint := fmt.Sprintf("%s:%d", conf.Host, conf.Port)

err := pb.RegisterResultServiceHandlerFromEndpoint(context.Background(), mux, gRPCEndpoint, opts)
if err != nil {
	return err
}

log.Printf("HTTP Proxy-server started on: %s:%d", httpConf.Host, httpConf.Port)
   //here is how I complete it if a signal Interrupt is transmitted
return http.ListenAndServe(fmt.Sprintf("%s:%d", httpConf.Host, httpConf.Port), mux)
}

This more code in https://github.com/8n0kkw1n/testcmd/pull/1/files

use close net.Listener, example:

// listen
ln, err := net.Listen("tcp","...")
... if err

go func() {
    // accept signal
    ln.Close()
}()
// start server
http.Serve(ln, mux)

Thank you very much, you helped me

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.