1
0
Fork 0

Big ol' gofmt.

This commit is contained in:
Solderpunk 2023-02-10 17:19:21 +01:00
parent 56d8dde14a
commit 5258b29c6b
4 changed files with 43 additions and 43 deletions

View file

@ -2,50 +2,50 @@ package main
import ( import (
"errors" "errors"
"github.com/BurntSushi/toml"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/BurntSushi/toml"
) )
type Config struct { type Config struct {
Port int Port int
Hostname string Hostname string
CertPath string CertPath string
KeyPath string KeyPath string
DocBase string DocBase string
HomeDocBase string HomeDocBase string
GeminiExt string GeminiExt string
DefaultLang string DefaultLang string
DefaultEncoding string DefaultEncoding string
AccessLog string AccessLog string
ErrorLog string ErrorLog string
ReadMollyFiles bool ReadMollyFiles bool
TempRedirects map[string]string TempRedirects map[string]string
PermRedirects map[string]string PermRedirects map[string]string
MimeOverrides map[string]string MimeOverrides map[string]string
CGIPaths []string CGIPaths []string
SCGIPaths map[string]string SCGIPaths map[string]string
CertificateZones map[string][]string CertificateZones map[string][]string
DirectorySort string DirectorySort string
DirectorySubdirsFirst bool DirectorySubdirsFirst bool
DirectoryReverse bool DirectoryReverse bool
DirectoryTitles bool DirectoryTitles bool
} }
type MollyFile struct { type MollyFile struct {
GeminiExt string GeminiExt string
TempRedirects map[string]string TempRedirects map[string]string
PermRedirects map[string]string PermRedirects map[string]string
MimeOverrides map[string]string MimeOverrides map[string]string
CertificateZones map[string][]string CertificateZones map[string][]string
DefaultLang string DefaultLang string
DefaultEncoding string DefaultEncoding string
DirectorySort string DirectorySort string
DirectorySubdirsFirst bool DirectorySubdirsFirst bool
DirectoryReverse bool DirectoryReverse bool
DirectoryTitles bool DirectoryTitles bool
} }
func getConfig(filename string) (Config, error) { func getConfig(filename string) (Config, error) {
@ -93,7 +93,7 @@ func getConfig(filename string) (Config, error) {
} }
// Absolutise DocBase // Absolutise DocBase
if(!filepath.IsAbs(config.DocBase)) { if !filepath.IsAbs(config.DocBase) {
abs, err := filepath.Abs(config.DocBase) abs, err := filepath.Abs(config.DocBase)
if err != nil { if err != nil {
return config, err return config, err
@ -103,7 +103,7 @@ func getConfig(filename string) (Config, error) {
// Absolutise CGI paths // Absolutise CGI paths
for index, cgiPath := range config.CGIPaths { for index, cgiPath := range config.CGIPaths {
if(!filepath.IsAbs(cgiPath)) { if !filepath.IsAbs(cgiPath) {
config.CGIPaths[index] = filepath.Join(config.DocBase, cgiPath) config.CGIPaths[index] = filepath.Join(config.DocBase, cgiPath)
} }
} }
@ -121,7 +121,7 @@ func getConfig(filename string) (Config, error) {
// Absolutise SCGI paths // Absolutise SCGI paths
for index, scgiPath := range config.SCGIPaths { for index, scgiPath := range config.SCGIPaths {
if(!filepath.IsAbs(scgiPath)) { if !filepath.IsAbs(scgiPath) {
config.SCGIPaths[index] = filepath.Join(config.DocBase, scgiPath) config.SCGIPaths[index] = filepath.Join(config.DocBase, scgiPath)
} }
} }

View file

@ -51,7 +51,7 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string,
return false // Should not happen return false // Should not happen
}) })
// Sort directories before file // Sort directories before file
if(config.DirectorySubdirsFirst) { if config.DirectorySubdirsFirst {
sort.SliceStable(files, func(i, j int) bool { sort.SliceStable(files, func(i, j int) bool {
// If i is a dir and j is a file, i < j // If i is a dir and j is a file, i < j
if files[i].IsDir() && !files[j].IsDir() { if files[i].IsDir() && !files[j].IsDir() {

View file

@ -262,11 +262,11 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo
mimeType = "application/octet-stream" mimeType = "application/octet-stream"
} }
// Add charset parameter // Add charset parameter
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultEncoding != "" { if strings.HasPrefix(mimeType, "text/gemini") && config.DefaultEncoding != "" {
mimeType += "; charset=" + config.DefaultEncoding mimeType += "; charset=" + config.DefaultEncoding
} }
// Add lang parameter // Add lang parameter
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultLang != "" { if strings.HasPrefix(mimeType, "text/gemini") && config.DefaultLang != "" {
mimeType += "; lang=" + config.DefaultLang mimeType += "; lang=" + config.DefaultLang
} }

10
main.go
View file

@ -52,7 +52,7 @@ func main() {
} }
defer errorLogFile.Close() defer errorLogFile.Close()
} }
errorLog := log.New(errorLogFile, "", log.Ldate | log.Ltime) errorLog := log.New(errorLogFile, "", log.Ldate|log.Ltime)
var accessLogFile *os.File var accessLogFile *os.File
// TODO: Find a more elegant/portable way to disable logging // TODO: Find a more elegant/portable way to disable logging
@ -139,10 +139,10 @@ func main() {
go handleGeminiRequest(conn, config, accessLogEntries, errorLog, &wg) go handleGeminiRequest(conn, config, accessLogEntries, errorLog, &wg)
} else { } else {
select { select {
case <-shutdown: case <-shutdown:
running = false running = false
default: default:
errorLog.Println("Error accepting connection: " + err.Error()) errorLog.Println("Error accepting connection: " + err.Error())
} }
} }
} }