Added option for -v|--verbose, to log file accesses to stdout
This commit is contained in:
parent
fbd4357afe
commit
469cb96883
|
@ -35,6 +35,6 @@ func Execute() {
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on")
|
rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on")
|
||||||
rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories")
|
rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories")
|
||||||
rootCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "also write output to stdout")
|
rootCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "log accessed files to stdout")
|
||||||
rootCmd.Flags().SetInterspersed(false)
|
rootCmd.Flags().SetInterspersed(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "0.3.1"
|
var Version = "0.4.0"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
12
cmd/web.go
12
cmd/web.go
|
@ -68,6 +68,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
if matchesPrefix == false {
|
if matchesPrefix == false {
|
||||||
|
if Verbose {
|
||||||
|
log.Println("Failed to serve file outside specified path(s): " + filePath)
|
||||||
|
}
|
||||||
|
|
||||||
http.NotFound(w, &r)
|
http.NotFound(w, &r)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -75,6 +79,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
|
|
||||||
_, err = os.Stat(filePath)
|
_, err = os.Stat(filePath)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
if Verbose {
|
||||||
|
log.Println("Failed to serve non-existent file: " + filePath)
|
||||||
|
}
|
||||||
|
|
||||||
http.NotFound(w, &r)
|
http.NotFound(w, &r)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -89,6 +97,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
|
|
||||||
w.Write(buf)
|
w.Write(buf)
|
||||||
|
|
||||||
|
if Verbose {
|
||||||
|
log.Println("Served file: " + filePath)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue