Removed extraneous check in getRefreshInterval(), inverted value check in getSortOrder(), replaced string concatenation with strings.Builder in generateFilePath()
This commit is contained in:
parent
c30c966ee3
commit
d3c063017d
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.26.0"
|
||||
var Version = "0.26.1"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
25
cmd/web.go
25
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 {
|
||||
|
|
Loading…
Reference in New Issue