Combined declare/initialize steps for structs
This commit is contained in:
parent
d3c063017d
commit
f9d7be008d
22
cmd/files.go
22
cmd/files.go
|
@ -485,17 +485,23 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string)
|
|||
if Cache && len(*fileCache) != 0 {
|
||||
fileList = *fileCache
|
||||
} else {
|
||||
files := Files{}
|
||||
files.List = make(map[string][]string)
|
||||
files := &Files{
|
||||
List: make(map[string][]string),
|
||||
}
|
||||
|
||||
stats := Stats{}
|
||||
stats := &Stats{
|
||||
FilesMatched: 0,
|
||||
FilesSkipped: 0,
|
||||
DirectoriesMatched: 0,
|
||||
}
|
||||
|
||||
concurrency := Concurrency{}
|
||||
concurrency.DirectoryScans = make(chan int, maxDirectoryScans)
|
||||
concurrency.FileScans = make(chan int, maxFileScans)
|
||||
concurrency := &Concurrency{
|
||||
DirectoryScans: make(chan int, maxDirectoryScans),
|
||||
FileScans: make(chan int, maxFileScans),
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
getFileList(args, &files, filters, &stats, &concurrency)
|
||||
getFileList(args, files, filters, stats, concurrency)
|
||||
runTime := time.Since(startTime)
|
||||
|
||||
if Verbose {
|
||||
|
@ -508,7 +514,7 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string)
|
|||
)
|
||||
}
|
||||
|
||||
fileList = prepareDirectories(&files, sort)
|
||||
fileList = prepareDirectories(files, sort)
|
||||
|
||||
if Cache {
|
||||
*fileCache = append(*fileCache, fileList...)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.26.1"
|
||||
var Version = "0.26.2"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
31
cmd/web.go
31
cmd/web.go
|
@ -321,9 +321,10 @@ func serveHtmlHandler(paths []string, regexes *Regexes, fileCache *[]string) htt
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
filters := Filters{}
|
||||
filters.Includes = splitQueryParams(r.URL.Query().Get("include"), regexes)
|
||||
filters.Excludes = splitQueryParams(r.URL.Query().Get("exclude"), regexes)
|
||||
filters := &Filters{
|
||||
Includes: splitQueryParams(r.URL.Query().Get("include"), regexes),
|
||||
Excludes: splitQueryParams(r.URL.Query().Get("exclude"), regexes),
|
||||
}
|
||||
|
||||
sortOrder := getSortOrder(r)
|
||||
|
||||
|
@ -341,7 +342,7 @@ func serveHtmlHandler(paths []string, regexes *Regexes, fileCache *[]string) htt
|
|||
}
|
||||
|
||||
if filePath == "" {
|
||||
filePath, err = getNewFile(paths, &filters, sortOrder, regexes, fileCache)
|
||||
filePath, err = getNewFile(paths, filters, sortOrder, regexes, fileCache)
|
||||
switch {
|
||||
case err != nil && err == ErrNoImagesFound:
|
||||
notFound(w, r, filePath)
|
||||
|
@ -352,7 +353,7 @@ func serveHtmlHandler(paths []string, regexes *Regexes, fileCache *[]string) htt
|
|||
}
|
||||
}
|
||||
|
||||
queryParams := generateQueryParams(&filters, sortOrder, refreshInterval)
|
||||
queryParams := generateQueryParams(filters, sortOrder, refreshInterval)
|
||||
|
||||
newUrl := fmt.Sprintf("http://%v%v%v",
|
||||
r.Host,
|
||||
|
@ -392,7 +393,7 @@ func serveHtmlHandler(paths []string, regexes *Regexes, fileCache *[]string) htt
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = serveHtml(w, r, filePath, dimensions, &filters)
|
||||
err = serveHtml(w, r, filePath, dimensions, filters)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -402,15 +403,6 @@ func serveHtmlHandler(paths []string, regexes *Regexes, fileCache *[]string) htt
|
|||
|
||||
func doNothing(http.ResponseWriter, *http.Request) {}
|
||||
|
||||
func generateRegularExpressions() *Regexes {
|
||||
r := Regexes{}
|
||||
|
||||
r.Filename = regexp.MustCompile(`(.+)([0-9]{3})(\..+)`)
|
||||
r.Alphanumeric = regexp.MustCompile(`^[a-zA-Z0-9]*$`)
|
||||
|
||||
return &r
|
||||
}
|
||||
|
||||
func ServePage(args []string) error {
|
||||
fmt.Printf("roulette v%v\n\n", Version)
|
||||
|
||||
|
@ -419,13 +411,16 @@ func ServePage(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
regexes := generateRegularExpressions()
|
||||
regexes := &Regexes{
|
||||
Filename: regexp.MustCompile(`(.+)([0-9]{3})(\..+)`),
|
||||
Alphanumeric: regexp.MustCompile(`^[a-zA-Z0-9]*$`),
|
||||
}
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
fileCache := []string{}
|
||||
fileCache := &[]string{}
|
||||
|
||||
http.Handle("/", serveHtmlHandler(paths, regexes, &fileCache))
|
||||
http.Handle("/", serveHtmlHandler(paths, regexes, fileCache))
|
||||
http.Handle(Prefix+"/", http.StripPrefix(Prefix, serveStaticFileHandler(paths)))
|
||||
http.HandleFunc("/favicon.ico", doNothing)
|
||||
|
||||
|
|
Loading…
Reference in New Issue