Restructure variable initializations

This commit is contained in:
Seednode 2023-12-17 05:16:46 -06:00
parent eaed4f11ef
commit e9a3ae5e58
3 changed files with 21 additions and 23 deletions

View File

@ -327,14 +327,8 @@ Poll:
func scanPaths(paths []string, sort string, index *fileIndex, formats types.Types) ([]string, error) {
startTime := time.Now()
var list []string
var filesMatched int
var filesSkipped int
var directoriesMatched int
var directoriesSkipped int
var wg sync.WaitGroup
var filesMatched, filesSkipped int
var directoriesMatched, directoriesSkipped int
fileChannel := make(chan string)
errorChannel := make(chan error)
@ -347,6 +341,8 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
directoriesSkipped: make(chan int),
}
var list []string
go func() {
for {
select {
@ -402,6 +398,8 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
}
}()
var wg sync.WaitGroup
for i := 0; i < len(paths); i++ {
wg.Add(1)

View File

@ -20,8 +20,6 @@ import (
)
func paginateIndex(page int, fileCount int, ending bool) string {
var html strings.Builder
var firstPage int = 1
var lastPage int
@ -51,6 +49,8 @@ func paginateIndex(page int, fileCount int, ending bool) string {
nextPage = fileCount / PageLength
}
var html strings.Builder
if ending {
html.WriteString("<tr><td style=\"border-bottom:none;\">")
} else {
@ -82,10 +82,10 @@ func paginateIndex(page int, fileCount int, ending bool) string {
func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "text/html")
startTime := time.Now()
w.Header().Set("Content-Type", "text/html")
indexDump := index.List()
fileCount := len(indexDump)
@ -159,10 +159,10 @@ func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httpro
func serveIndexJson(args []string, index *fileIndex, errorChannel chan<- error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "application/json")
startTime := time.Now()
w.Header().Set("Content-Type", "application/json")
indexedFiles := index.List()
fileCount := len(indexedFiles)
@ -217,10 +217,10 @@ func serveIndexJson(args []string, index *fileIndex, errorChannel chan<- error)
func serveAvailableExtensions(errorChannel chan<- error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "text/plain")
startTime := time.Now()
w.Header().Set("Content-Type", "text/plain")
written, err := w.Write([]byte(types.SupportedFormats.GetExtensions()))
if err != nil {
errorChannel <- err
@ -239,10 +239,10 @@ func serveAvailableExtensions(errorChannel chan<- error) httprouter.Handle {
func serveEnabledExtensions(formats types.Types, errorChannel chan<- error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "text/plain")
startTime := time.Now()
w.Header().Set("Content-Type", "text/plain")
written, err := w.Write([]byte(formats.GetExtensions()))
if err != nil {
errorChannel <- err
@ -261,10 +261,10 @@ func serveEnabledExtensions(formats types.Types, errorChannel chan<- error) http
func serveAvailableMediaTypes(errorChannel chan<- error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "text/plain")
startTime := time.Now()
w.Header().Set("Content-Type", "text/plain")
written, err := w.Write([]byte(types.SupportedFormats.GetMediaTypes()))
if err != nil {
errorChannel <- err
@ -283,10 +283,10 @@ func serveAvailableMediaTypes(errorChannel chan<- error) httprouter.Handle {
func serveEnabledMediaTypes(formats types.Types, errorChannel chan<- error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Content-Type", "text/plain")
startTime := time.Now()
w.Header().Set("Content-Type", "text/plain")
written, err := w.Write([]byte(formats.GetMediaTypes()))
if err != nil {
errorChannel <- err

View File

@ -12,7 +12,7 @@ import (
)
const (
ReleaseVersion string = "3.3.0"
ReleaseVersion string = "3.3.1"
)
var (