#245 shutdown gateway graceful too

This commit is contained in:
smallnest
2018-08-15 18:17:48 +08:00
parent b643917a3e
commit c205a7da6f
2 changed files with 46 additions and 24 deletions

View File

@@ -38,11 +38,24 @@ func (s *Server) startHTTP1APIGateway(ln net.Listener) {
router.GET("/*servicePath", s.handleGatewayRequest)
router.PUT("/*servicePath", s.handleGatewayRequest)
if err := http.Serve(ln, router); err != nil {
s.mu.Lock()
s.gatewayHTTPServer = &http.Server{Handler: router}
s.mu.Unlock()
if err := s.gatewayHTTPServer.Serve(ln); err != nil {
log.Errorf("error in gateway Serve: %s", err)
}
}
func (s *Server) closeHTTP1APIGateway(ctx context.Context) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.gatewayHTTPServer != nil {
return s.gatewayHTTPServer.Shutdown(ctx)
}
return nil
}
func (s *Server) handleGatewayRequest(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if r.Header.Get(XServicePath) == "" {
servicePath := params.ByName("servicePath")