From d3c063017d728e9128d2ba9bddd3a62cdcd195a8 Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 11 Nov 2022 09:19:53 -0600 Subject: [PATCH] Removed extraneous check in getRefreshInterval(), inverted value check in getSortOrder(), replaced string concatenation with strings.Builder in generateFilePath() --- cmd/version.go | 2 +- cmd/web.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 1dbb81a..f5c13ed 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.26.0" +var Version = "0.26.1" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index e3d156f..4020732 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -89,11 +89,8 @@ func notFound(w http.ResponseWriter, r *http.Request, filePath string) error { func getRefreshInterval(r *http.Request) string { refreshInterval := r.URL.Query().Get("refresh") - if refreshInterval == "" { - refreshInterval = "0" - } - num, err := strconv.Atoi(refreshInterval) + if err != nil || num < 0 { refreshInterval = "0" } @@ -103,11 +100,11 @@ func getRefreshInterval(r *http.Request) string { func getSortOrder(r *http.Request) string { sortOrder := r.URL.Query().Get("sort") - if !(sortOrder == "asc" || sortOrder == "desc") { - sortOrder = "" + if sortOrder == "asc" || sortOrder == "desc" { + return sortOrder } - return sortOrder + return "" } func splitQueryParams(query string, regexes *Regexes) []string { @@ -188,13 +185,15 @@ func stripQueryParams(u string) (string, error) { } func generateFilePath(filePath string) string { - htmlBody := Prefix - if runtime.GOOS == "windows" { - htmlBody += "/" - } - htmlBody += filePath + var htmlBody strings.Builder - return htmlBody + htmlBody.WriteString(Prefix) + if runtime.GOOS == "windows" { + htmlBody.WriteString(`/`) + } + htmlBody.WriteString(filePath) + + return htmlBody.String() } func refererToUri(referer string) string {