Replaced some value passing with pointers, per suggestions from copyfighter

This commit is contained in:
Seednode 2022-10-19 19:41:42 -05:00
parent 5d9a815bf2
commit fa7177849e
3 changed files with 11 additions and 10 deletions

View File

@ -71,7 +71,7 @@ func appendPaths(m map[string][]string, path string, filters *Filters) (map[stri
return m, nil return m, nil
} }
func getFirstFile(p Path) (string, error) { func getFirstFile(p *Path) (string, error) {
p.Number = 1 p.Number = 1
fileName, err := tryExtensions(p) fileName, err := tryExtensions(p)
@ -82,7 +82,7 @@ func getFirstFile(p Path) (string, error) {
return fileName, nil return fileName, nil
} }
func getLastFile(p Path) (string, error) { func getLastFile(p *Path) (string, error) {
var fileName string var fileName string
var err error var err error
@ -111,7 +111,7 @@ func getLastFile(p Path) (string, error) {
return fileName, nil return fileName, nil
} }
func getNextFile(p Path) (string, error) { func getNextFile(p *Path) (string, error) {
p.Increment() p.Increment()
fileName, err := tryExtensions(p) fileName, err := tryExtensions(p)
@ -122,7 +122,7 @@ func getNextFile(p Path) (string, error) {
return fileName, err return fileName, err
} }
func getPreviousFile(p Path) (string, error) { func getPreviousFile(p *Path) (string, error) {
p.Decrement() p.Decrement()
fileName, err := tryExtensions(p) fileName, err := tryExtensions(p)
@ -133,7 +133,7 @@ func getPreviousFile(p Path) (string, error) {
return fileName, err return fileName, err
} }
func splitPath(path string) (Path, error) { func splitPath(path string) (*Path, error) {
p := Path{} p := Path{}
var err error var err error
@ -142,22 +142,22 @@ func splitPath(path string) (Path, error) {
split := re.FindAllStringSubmatch(path, -1) split := re.FindAllStringSubmatch(path, -1)
if len(split) < 1 || len(split[0]) < 3 { if len(split) < 1 || len(split[0]) < 3 {
return Path{}, nil return &Path{}, nil
} }
p.Base = split[0][1] p.Base = split[0][1]
p.Number, err = strconv.Atoi(split[0][2]) p.Number, err = strconv.Atoi(split[0][2])
if err != nil { if err != nil {
return Path{}, err return &Path{}, err
} }
p.Extension = split[0][3] p.Extension = split[0][3]
return p, nil return &p, nil
} }
func tryExtensions(p Path) (string, error) { func tryExtensions(p *Path) (string, error) {
extensions := [6]string{p.Extension, ".jpg", ".jpeg", ".png", ".gif", ".webp"} extensions := [6]string{p.Extension, ".jpg", ".jpeg", ".png", ".gif", ".webp"}
var fileName string var fileName string

View File

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

View File

@ -173,6 +173,7 @@ func serveHtmlHandler(paths []string) appHandler {
filters := Filters{} filters := Filters{}
filters.Includes = parseQueryParams(r.URL.Query().Get("include")) filters.Includes = parseQueryParams(r.URL.Query().Get("include"))
filters.Excludes = parseQueryParams(r.URL.Query().Get("exclude")) filters.Excludes = parseQueryParams(r.URL.Query().Get("exclude"))
sort := r.URL.Query().Get("sort") sort := r.URL.Query().Get("sort")
switch { switch {