fix: serve Ctrl-C stop

This commit is contained in:
Kaden
2026-06-16 23:26:52 +08:00
parent 602f4dfa40
commit c85745b230
2 changed files with 14 additions and 2 deletions
+6 -1
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"time"
"github.com/spf13/cobra"
)
@@ -61,7 +62,11 @@ func runServe(ctx context.Context, dir, addr string) error {
return err
}
case <-ctx.Done():
_ = srv.Close()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := srv.Shutdown(shutdownCtx); err != nil {
_ = srv.Close()
}
if err := <-srvErr; err != nil && err != http.ErrServerClosed {
return err
}