From c61eeb004a23f57f19c55840e3c6d51fcc122a52 Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 8 Sep 2022 16:05:07 -0500 Subject: [PATCH] Readded missing exit-handling function --- cmd/root.go | 5 ++--- cmd/web.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 083f80d..8deeac5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,7 @@ Copyright © 2022 Seednode package cmd import ( - "fmt" + "log" "github.com/spf13/cobra" ) @@ -26,8 +26,7 @@ var rootCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { - fmt.Println(err) - panic(Exit{1}) + log.Fatal(err) } } diff --git a/cmd/web.go b/cmd/web.go index f068a52..2270853 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -16,6 +16,17 @@ import ( "strings" ) +type Exit struct{ Code int } + +func HandleExit() { + if e := recover(); e != nil { + if exit, ok := e.(Exit); ok == true { + os.Exit(exit.Code) + } + panic(e) + } +} + func generatePageHtml(w http.ResponseWriter, paths []string) error { fileList, err := getFileList(paths) if err != nil {