Renamed functions for consistency

This commit is contained in:
Seednode 2022-09-16 14:45:54 -05:00
parent 4e74d99019
commit 26981c9669
2 changed files with 9 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.6.0" var Version = "0.6.1"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)

View File

@ -22,7 +22,7 @@ const LOGDATE string = "2006-01-02T15:04:05.000000000-07:00"
const PREFIX string = "/src" 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) fileName := filepath.Base(filePath)
w.Header().Add("Content-Type", "text/html") 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) { return func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/" { if r.RequestURI == "/" {
filePath, err := pickFile(paths) filePath, err := pickFile(paths)
@ -138,12 +138,11 @@ func servePageHandler(paths []string) http.HandlerFunc {
isImage, err := checkIfImage(filePath) isImage, err := checkIfImage(filePath)
if err != nil { if err != nil {
fmt.Println(err)
http.NotFound(w, r) http.NotFound(w, r)
} }
if isImage { if isImage {
err := generatePageHtml(w, *r, filePath) err := serveHtml(w, *r, filePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -163,11 +162,14 @@ func ServePage(args []string) {
for _, i := range paths { for _, i := range paths {
fmt.Println("Paths: " + i) fmt.Println("Paths: " + i)
} }
http.HandleFunc("/", servePageHandler(paths)) http.HandleFunc("/", serveHtmlHandler(paths))
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
http.HandleFunc("/favicon.ico", doNothing) http.HandleFunc("/favicon.ico", doNothing)
port := strconv.Itoa(Port) port := strconv.Itoa(Port)
log.Fatal(http.ListenAndServe(":"+port, nil)) err = http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal(err)
}
} }