From 5258b29c6b190eceab0b622851b9426be47c6442 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Fri, 10 Feb 2023 17:19:21 +0100 Subject: [PATCH] Big ol' gofmt. --- config.go | 70 +++++++++++++++++++++++++++--------------------------- dirlist.go | 2 +- handler.go | 4 ++-- main.go | 10 ++++---- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/config.go b/config.go index cd5710c..5ec24b2 100644 --- a/config.go +++ b/config.go @@ -2,50 +2,50 @@ package main import ( "errors" + "github.com/BurntSushi/toml" "log" "os" "path/filepath" "strings" - "github.com/BurntSushi/toml" ) type Config struct { - Port int - Hostname string - CertPath string - KeyPath string - DocBase string - HomeDocBase string - GeminiExt string - DefaultLang string - DefaultEncoding string - AccessLog string - ErrorLog string - ReadMollyFiles bool - TempRedirects map[string]string - PermRedirects map[string]string - MimeOverrides map[string]string - CGIPaths []string - SCGIPaths map[string]string - CertificateZones map[string][]string - DirectorySort string + Port int + Hostname string + CertPath string + KeyPath string + DocBase string + HomeDocBase string + GeminiExt string + DefaultLang string + DefaultEncoding string + AccessLog string + ErrorLog string + ReadMollyFiles bool + TempRedirects map[string]string + PermRedirects map[string]string + MimeOverrides map[string]string + CGIPaths []string + SCGIPaths map[string]string + CertificateZones map[string][]string + DirectorySort string DirectorySubdirsFirst bool - DirectoryReverse bool - DirectoryTitles bool + DirectoryReverse bool + DirectoryTitles bool } type MollyFile struct { - GeminiExt string - TempRedirects map[string]string - PermRedirects map[string]string - MimeOverrides map[string]string - CertificateZones map[string][]string - DefaultLang string - DefaultEncoding string - DirectorySort string + GeminiExt string + TempRedirects map[string]string + PermRedirects map[string]string + MimeOverrides map[string]string + CertificateZones map[string][]string + DefaultLang string + DefaultEncoding string + DirectorySort string DirectorySubdirsFirst bool - DirectoryReverse bool - DirectoryTitles bool + DirectoryReverse bool + DirectoryTitles bool } func getConfig(filename string) (Config, error) { @@ -93,7 +93,7 @@ func getConfig(filename string) (Config, error) { } // Absolutise DocBase - if(!filepath.IsAbs(config.DocBase)) { + if !filepath.IsAbs(config.DocBase) { abs, err := filepath.Abs(config.DocBase) if err != nil { return config, err @@ -103,7 +103,7 @@ func getConfig(filename string) (Config, error) { // Absolutise CGI paths for index, cgiPath := range config.CGIPaths { - if(!filepath.IsAbs(cgiPath)) { + if !filepath.IsAbs(cgiPath) { config.CGIPaths[index] = filepath.Join(config.DocBase, cgiPath) } } @@ -121,7 +121,7 @@ func getConfig(filename string) (Config, error) { // Absolutise SCGI paths for index, scgiPath := range config.SCGIPaths { - if(!filepath.IsAbs(scgiPath)) { + if !filepath.IsAbs(scgiPath) { config.SCGIPaths[index] = filepath.Join(config.DocBase, scgiPath) } } diff --git a/dirlist.go b/dirlist.go index 0acea49..09ecd62 100644 --- a/dirlist.go +++ b/dirlist.go @@ -51,7 +51,7 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string, return false // Should not happen }) // Sort directories before file - if(config.DirectorySubdirsFirst) { + if config.DirectorySubdirsFirst { sort.SliceStable(files, func(i, j int) bool { // If i is a dir and j is a file, i < j if files[i].IsDir() && !files[j].IsDir() { diff --git a/handler.go b/handler.go index 9971b33..970133b 100644 --- a/handler.go +++ b/handler.go @@ -262,11 +262,11 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo mimeType = "application/octet-stream" } // Add charset parameter - if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultEncoding != "" { + if strings.HasPrefix(mimeType, "text/gemini") && config.DefaultEncoding != "" { mimeType += "; charset=" + config.DefaultEncoding } // Add lang parameter - if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultLang != "" { + if strings.HasPrefix(mimeType, "text/gemini") && config.DefaultLang != "" { mimeType += "; lang=" + config.DefaultLang } diff --git a/main.go b/main.go index 5b5e050..8c68b74 100644 --- a/main.go +++ b/main.go @@ -52,7 +52,7 @@ func main() { } defer errorLogFile.Close() } - errorLog := log.New(errorLogFile, "", log.Ldate | log.Ltime) + errorLog := log.New(errorLogFile, "", log.Ldate|log.Ltime) var accessLogFile *os.File // TODO: Find a more elegant/portable way to disable logging @@ -139,10 +139,10 @@ func main() { go handleGeminiRequest(conn, config, accessLogEntries, errorLog, &wg) } else { select { - case <-shutdown: - running = false - default: - errorLog.Println("Error accepting connection: " + err.Error()) + case <-shutdown: + running = false + default: + errorLog.Println("Error accepting connection: " + err.Error()) } } }