Stop gracefully stops the HTTP server. It is safe to call multiple times.
(ctx context.Context)
| 627 | |
| 628 | // Stop gracefully stops the HTTP server. It is safe to call multiple times. |
| 629 | func (s *Server) Stop(ctx context.Context) error { |
| 630 | var err error |
| 631 | s.stopOnce.Do(func() { |
| 632 | s.shutdown() |
| 633 | |
| 634 | // Clean up temporary directory |
| 635 | s.cleanupTempDir() |
| 636 | |
| 637 | if s.srv != nil { |
| 638 | if err = s.srv.Shutdown(ctx); errors.Is(err, http.ErrServerClosed) { |
| 639 | err = nil |
| 640 | } |
| 641 | } |
| 642 | }) |
| 643 | return err |
| 644 | } |
| 645 | |
| 646 | // cleanupTempDir removes the temporary directory and all its contents |
| 647 | func (s *Server) cleanupTempDir() { |