Stop stops the embedded HTTP server.
()
| 226 | |
| 227 | // Stop stops the embedded HTTP server. |
| 228 | func (s *Server) Stop() error { |
| 229 | s.mu.Lock() |
| 230 | defer s.mu.Unlock() |
| 231 | |
| 232 | if !s.running || s.httpServer == nil { |
| 233 | s.logger.Debug("HTTP server not running, no action needed") |
| 234 | |
| 235 | return nil |
| 236 | } |
| 237 | |
| 238 | s.logger.Info("Stopping HTTP server on port %d", s.port) |
| 239 | |
| 240 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 241 | defer cancel() |
| 242 | |
| 243 | err := s.httpServer.Shutdown(ctx) |
| 244 | if err != nil { |
| 245 | s.logger.Error("Failed to shutdown HTTP server gracefully: %v", err) |
| 246 | } else { |
| 247 | s.logger.Debug("HTTP server shutdown gracefully") |
| 248 | } |
| 249 | |
| 250 | s.running = false |
| 251 | s.httpServer = nil |
| 252 | s.proxy = nil |
| 253 | |
| 254 | s.logger.Info("HTTP server stopped successfully") |
| 255 | |
| 256 | return err |
| 257 | } |
| 258 | |
| 259 | // GetPort returns the port the server is running on. |
| 260 | func (s *Server) GetPort() int { |
no test coverage detected