From 26981c966920498e4b157285b6dd61c220e1aea7 Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 16 Sep 2022 14:45:54 -0500 Subject: [PATCH] Renamed functions for consistency --- cmd/version.go | 2 +- cmd/web.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 0d0e08b..7dccb2a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.6.0" +var Version = "0.6.1" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 9ed5d5d..fb4c355 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -22,7 +22,7 @@ const LOGDATE string = "2006-01-02T15:04:05.000000000-07:00" const PREFIX string = "/src" -func generatePageHtml(w http.ResponseWriter, r http.Request, filePath string) error { +func serveHtml(w http.ResponseWriter, r http.Request, filePath string) error { fileName := filepath.Base(filePath) w.Header().Add("Content-Type", "text/html") @@ -120,7 +120,7 @@ func serveStaticFileHandler(paths []string) http.HandlerFunc { } } -func servePageHandler(paths []string) http.HandlerFunc { +func serveHtmlHandler(paths []string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.RequestURI == "/" { filePath, err := pickFile(paths) @@ -138,12 +138,11 @@ func servePageHandler(paths []string) http.HandlerFunc { isImage, err := checkIfImage(filePath) if err != nil { - fmt.Println(err) http.NotFound(w, r) } if isImage { - err := generatePageHtml(w, *r, filePath) + err := serveHtml(w, *r, filePath) if err != nil { log.Fatal(err) } @@ -163,11 +162,14 @@ func ServePage(args []string) { for _, i := range paths { fmt.Println("Paths: " + i) } - http.HandleFunc("/", servePageHandler(paths)) + http.HandleFunc("/", serveHtmlHandler(paths)) http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) http.HandleFunc("/favicon.ico", doNothing) port := strconv.Itoa(Port) - log.Fatal(http.ListenAndServe(":"+port, nil)) + err = http.ListenAndServe(":"+port, nil) + if err != nil { + log.Fatal(err) + } }