diff --git a/cmd/root.go b/cmd/root.go index a17b584..82f84d2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,6 +35,6 @@ func Execute() { func init() { rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on") rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories") - rootCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "also write output to stdout") - rootCmd.Flags().SetInterspersed(false) + rootCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "log accessed files to stdout") + rootCmd.Flags().SetInterspersed(true) } diff --git a/cmd/version.go b/cmd/version.go index 36e8470..027b143 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.3.1" +var Version = "0.4.0" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 58e5268..fb036a6 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -68,6 +68,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro } if matchesPrefix == false { + if Verbose { + log.Println("Failed to serve file outside specified path(s): " + filePath) + } + http.NotFound(w, &r) return nil @@ -75,6 +79,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro _, err = os.Stat(filePath) if errors.Is(err, os.ErrNotExist) { + if Verbose { + log.Println("Failed to serve non-existent file: " + filePath) + } + http.NotFound(w, &r) return nil @@ -89,6 +97,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro w.Write(buf) + if Verbose { + log.Println("Served file: " + filePath) + } + return nil }