Removed extraneous check in getRefreshInterval(), inverted value check in getSortOrder(), replaced string concatenation with strings.Builder in generateFilePath()

This commit is contained in:
Seednode 2022-11-11 09:19:53 -06:00
parent c30c966ee3
commit d3c063017d
2 changed files with 13 additions and 14 deletions

View File

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

View File

@ -89,11 +89,8 @@ func notFound(w http.ResponseWriter, r *http.Request, filePath string) error {
func getRefreshInterval(r *http.Request) string { func getRefreshInterval(r *http.Request) string {
refreshInterval := r.URL.Query().Get("refresh") refreshInterval := r.URL.Query().Get("refresh")
if refreshInterval == "" {
refreshInterval = "0"
}
num, err := strconv.Atoi(refreshInterval) num, err := strconv.Atoi(refreshInterval)
if err != nil || num < 0 { if err != nil || num < 0 {
refreshInterval = "0" refreshInterval = "0"
} }
@ -103,11 +100,11 @@ func getRefreshInterval(r *http.Request) string {
func getSortOrder(r *http.Request) string { func getSortOrder(r *http.Request) string {
sortOrder := r.URL.Query().Get("sort") sortOrder := r.URL.Query().Get("sort")
if !(sortOrder == "asc" || sortOrder == "desc") { if sortOrder == "asc" || sortOrder == "desc" {
sortOrder = "" return sortOrder
} }
return sortOrder return ""
} }
func splitQueryParams(query string, regexes *Regexes) []string { func splitQueryParams(query string, regexes *Regexes) []string {
@ -188,13 +185,15 @@ func stripQueryParams(u string) (string, error) {
} }
func generateFilePath(filePath string) string { func generateFilePath(filePath string) string {
htmlBody := Prefix var htmlBody strings.Builder
if runtime.GOOS == "windows" {
htmlBody += "/"
}
htmlBody += filePath
return htmlBody htmlBody.WriteString(Prefix)
if runtime.GOOS == "windows" {
htmlBody.WriteString(`/`)
}
htmlBody.WriteString(filePath)
return htmlBody.String()
} }
func refererToUri(referer string) string { func refererToUri(referer string) string {