Skip to content

Commit 9c5e46d

Browse files
committed
fix: resolve lint issues and update gitignore
- Fix gofmt formatting in internal/flashduty/server.go - Replace os.Exit with error return in RunHTTPServer to allow defers to run - Add bin/ to .gitignore to exclude local lint tools
1 parent ababe88 commit 9c5e46d

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
bin/
23

34
# VSCode
45
.vscode/*

internal/flashduty/server.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func extractAppKey(r *http.Request) string {
347347
// httpContextFunc extracts configuration from the HTTP request and injects it into the context.
348348
func httpContextFunc(ctx context.Context, r *http.Request, defaultBaseURL string) context.Context {
349349
queryParams := r.URL.Query()
350-
350+
351351
var enabledToolsets []string
352352
if toolsets := queryParams.Get("toolsets"); toolsets != "" {
353353
enabledToolsets = strings.Split(toolsets, ",")
@@ -396,8 +396,7 @@ func RunHTTPServer(cfg HTTPServerConfig) error {
396396
EnabledToolsets: []string{"all"},
397397
})
398398
if err != nil {
399-
logger.Error("failed to create MCP server", "error", err)
400-
os.Exit(1)
399+
return fmt.Errorf("failed to create MCP server: %w", err)
401400
}
402401

403402
httpServer := server.NewStreamableHTTPServer(
@@ -434,6 +433,7 @@ func RunHTTPServer(cfg HTTPServerConfig) error {
434433
MaxHeaderBytes: 128 * 1024, // 128KB
435434
}
436435

436+
errC := make(chan error, 1)
437437
go func() {
438438
logger.Info("Server listening",
439439
"addr", "http://0.0.0.0:"+cfg.Port,
@@ -442,25 +442,27 @@ func RunHTTPServer(cfg HTTPServerConfig) error {
442442
"date", cfg.Date,
443443
)
444444
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
445-
logger.Error("listen failed", "error", err)
446-
os.Exit(1)
445+
errC <- err
447446
}
448447
}()
449448

450449
// Graceful shutdown
451450
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
452451
defer stop()
453452

454-
<-ctx.Done()
455-
456-
logger.Info("Shutting down server...")
453+
// Wait for shutdown signal or server error
454+
select {
455+
case <-ctx.Done():
456+
logger.Info("Shutting down server...")
457+
case err := <-errC:
458+
return fmt.Errorf("listen failed: %w", err)
459+
}
457460

458461
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
459462
defer cancel()
460463

461464
if err := srv.Shutdown(shutdownCtx); err != nil {
462-
logger.Error("Server shutdown failed", "error", err)
463-
os.Exit(1)
465+
return fmt.Errorf("server shutdown failed: %w", err)
464466
}
465467

466468
logger.Info("Server exited properly")

0 commit comments

Comments
 (0)