Run gofmt on everything for the first time ever!

This commit is contained in:
Solderpunk 2020-06-10 21:31:13 +02:00
parent 3e80488f92
commit b0b18971f4
5 changed files with 79 additions and 80 deletions

View File

@ -22,9 +22,9 @@ func handleCGI(config Config, path string, URL *url.URL, log *LogEntry, conn net
// Set environment variables // Set environment variables
vars := prepareCGIVariables(config, URL, conn, path) vars := prepareCGIVariables(config, URL, conn, path)
cmd.Env = []string{ } cmd.Env = []string{}
for key, value := range vars { for key, value := range vars {
cmd.Env = append(cmd.Env, key + "=" + value) cmd.Env = append(cmd.Env, key+"="+value)
} }
response, err := cmd.Output() response, err := cmd.Output()
@ -65,13 +65,13 @@ func handleSCGI(socket_path string, config Config, URL *url.URL, log *LogEntry,
// Send variables // Send variables
vars := prepareSCGIVariables(config, URL, conn) vars := prepareSCGIVariables(config, URL, conn)
length := 0 length := 0
for key, value := range(vars) { for key, value := range vars {
length += len(key) length += len(key)
length += len(value) length += len(value)
length += 2 length += 2
} }
socket.Write([]byte(strconv.Itoa(length) + ":")) socket.Write([]byte(strconv.Itoa(length) + ":"))
for key, value := range(vars) { for key, value := range vars {
socket.Write([]byte(key + "\x00")) socket.Write([]byte(key + "\x00"))
socket.Write([]byte(value + "\x00")) socket.Write([]byte(value + "\x00"))
} }
@ -139,7 +139,7 @@ func prepareGatewayVariables(config Config, URL *url.URL, conn net.Conn) map[str
// Add TLS variables // Add TLS variables
var tlsConn (*tls.Conn) = conn.(*tls.Conn) var tlsConn (*tls.Conn) = conn.(*tls.Conn)
connState := tlsConn.ConnectionState() connState := tlsConn.ConnectionState()
// vars["TLS_CIPHER"] = CipherSuiteName(connState.CipherSuite) // vars["TLS_CIPHER"] = CipherSuiteName(connState.CipherSuite)
// Add client cert variables // Add client cert variables
clientCerts := connState.PeerCertificates clientCerts := connState.PeerCertificates

View File

@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"github.com/BurntSushi/toml"
"io/ioutil" "io/ioutil"
"log" "log"
"mime" "mime"
@ -15,7 +16,6 @@ import (
"regexp" "regexp"
"strings" "strings"
"time" "time"
"github.com/BurntSushi/toml"
) )
func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) { func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) {
@ -127,7 +127,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
} }
// Don't serve Molly files // Don't serve Molly files
if ! info.IsDir() && filepath.Base(path) == ".molly" { if !info.IsDir() && filepath.Base(path) == ".molly" {
conn.Write([]byte("51 Not found!\r\n")) conn.Write([]byte("51 Not found!\r\n"))
log.Status = 51 log.Status = 51
return return
@ -146,7 +146,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
return return
} }
// Check for index.gmi if path is a directory // Check for index.gmi if path is a directory
index_path := filepath.Join(path, "index." + config.GeminiExt) index_path := filepath.Join(path, "index."+config.GeminiExt)
index_info, err := os.Stat(index_path) index_info, err := os.Stat(index_path)
if err == nil && uint64(index_info.Mode().Perm())&0444 == 0444 { if err == nil && uint64(index_info.Mode().Perm())&0444 == 0444 {
serveFile(index_path, &log, conn, config) serveFile(index_path, &log, conn, config)
@ -160,8 +160,8 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
} }
// If this file is executable, get dynamic content // If this file is executable, get dynamic content
if info.Mode().Perm() & 0111 == 0111 { if info.Mode().Perm()&0111 == 0111 {
for _, cgiPath := range(config.CGIPaths) { for _, cgiPath := range config.CGIPaths {
inCGIPath, err := regexp.Match(cgiPath, []byte(path)) inCGIPath, err := regexp.Match(cgiPath, []byte(path))
if err == nil && inCGIPath { if err == nil && inCGIPath {
handleCGI(config, path, URL, &log, conn) handleCGI(config, path, URL, &log, conn)
@ -228,7 +228,7 @@ func resolvePath(path string, config Config) (string, os.FileInfo, error) {
func parseMollyFiles(path string, info os.FileInfo, config *Config) { func parseMollyFiles(path string, info os.FileInfo, config *Config) {
// Build list of directories to check // Build list of directories to check
dirs := make([]string, 16) dirs := make([]string, 16)
if ! info.IsDir() { if !info.IsDir() {
path = filepath.Dir(path) path = filepath.Dir(path)
} }
dirs = append(dirs, path) dirs = append(dirs, path)
@ -242,7 +242,7 @@ func parseMollyFiles(path string, info os.FileInfo, config *Config) {
} }
// Parse files // Parse files
var mollyFile MollyFile var mollyFile MollyFile
for i := len(dirs)-1; i >= 0; i-- { for i := len(dirs) - 1; i >= 0; i-- {
dir := dirs[i] dir := dirs[i]
mollyPath := filepath.Join(dir, ".molly") mollyPath := filepath.Join(dir, ".molly")
_, err := os.Stat(mollyPath) _, err := os.Stat(mollyPath)
@ -299,13 +299,13 @@ func generatePrettyFileLabel(info os.FileInfo) string {
} else if info.Size() < 1024 { } else if info.Size() < 1024 {
size = fmt.Sprintf("%4d B", info.Size()) size = fmt.Sprintf("%4d B", info.Size())
} else if info.Size() < (1024 << 10) { } else if info.Size() < (1024 << 10) {
size = fmt.Sprintf("%4d KiB", info.Size() >> 10) size = fmt.Sprintf("%4d KiB", info.Size()>>10)
} else if info.Size() < 1024 << 20 { } else if info.Size() < 1024<<20 {
size = fmt.Sprintf("%4d MiB", info.Size() >> 20) size = fmt.Sprintf("%4d MiB", info.Size()>>20)
} else if info.Size() < 1024 << 30 { } else if info.Size() < 1024<<30 {
size = fmt.Sprintf("%4d GiB", info.Size() >> 30) size = fmt.Sprintf("%4d GiB", info.Size()>>30)
} else if info.Size() < 1024 << 40 { } else if info.Size() < 1024<<40 {
size = fmt.Sprintf("%4d TiB", info.Size() >> 40) size = fmt.Sprintf("%4d TiB", info.Size()>>40)
} else { } else {
size = "GIGANTIC" size = "GIGANTIC"
} }
@ -326,7 +326,7 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) {
// Get MIME type of files // Get MIME type of files
ext := filepath.Ext(path) ext := filepath.Ext(path)
var mimeType string var mimeType string
if ext == "." + config.GeminiExt { if ext == "."+config.GeminiExt {
mimeType = "text/gemini" mimeType = "text/gemini"
} else { } else {
mimeType = mime.TypeByExtension(ext) mimeType = mime.TypeByExtension(ext)
@ -349,4 +349,3 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) {
log.Status = 20 log.Status = 20
conn.Write(contents) conn.Write(contents)
} }

View File

@ -44,7 +44,7 @@ func main() {
} }
// Create TLS listener // Create TLS listener
listener, err := tls.Listen("tcp", ":" + strconv.Itoa(config.Port), tlscfg) listener, err := tls.Listen("tcp", ":"+strconv.Itoa(config.Port), tlscfg)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -52,9 +52,9 @@ func main() {
// Start log handling routine // Start log handling routine
logEntries := make(chan LogEntry, 10) logEntries := make(chan LogEntry, 10)
go func () { go func() {
for { for {
entry := <- logEntries entry := <-logEntries
writeLogEntry(logfile, entry) writeLogEntry(logfile, entry)
} }
}() }()