Replaced log.Print with fmt.Printf to allow finer control of newlines
This commit is contained in:
parent
bbe919be3b
commit
35b46ed9e8
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "0.4.1"
|
var Version = "0.4.2"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
14
cmd/web.go
14
cmd/web.go
|
@ -6,6 +6,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -13,8 +14,11 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const LOGDATE string = "2006-01-02T15:04:05.000000000-07:00"
|
||||||
|
|
||||||
func generatePageHtml(w http.ResponseWriter, r http.Request, paths []string) error {
|
func generatePageHtml(w http.ResponseWriter, r http.Request, paths []string) error {
|
||||||
fileList, err := getFileList(paths)
|
fileList, err := getFileList(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -69,7 +73,7 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
|
|
||||||
if matchesPrefix == false {
|
if matchesPrefix == false {
|
||||||
if Verbose {
|
if Verbose {
|
||||||
log.Println("Failed to serve file outside specified path(s): " + filePath)
|
fmt.Printf("%v Failed to serve file outside specified path(s): %v", time.Now().Format(LOGDATE), filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.NotFound(w, &r)
|
http.NotFound(w, &r)
|
||||||
|
@ -80,7 +84,7 @@ 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 {
|
if Verbose {
|
||||||
log.Println("Failed to serve non-existent file: " + filePath)
|
fmt.Printf("%v Failed to serve non-existent file: %v", time.Now().Format(LOGDATE), filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.NotFound(w, &r)
|
http.NotFound(w, &r)
|
||||||
|
@ -90,6 +94,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Verbose {
|
||||||
|
fmt.Printf("%v Serving file: %v", time.Now().Format(LOGDATE), filePath)
|
||||||
|
}
|
||||||
|
|
||||||
buf, err := os.ReadFile(filePath)
|
buf, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -98,7 +106,7 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
|
||||||
w.Write(buf)
|
w.Write(buf)
|
||||||
|
|
||||||
if Verbose {
|
if Verbose {
|
||||||
log.Println("Served file: " + filePath)
|
fmt.Println(" - DONE")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue