From d768201553a117bff967e8b5de44ff20d831856f Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sun, 19 Nov 2023 14:08:57 +0100 Subject: [PATCH] Fix various cosmetics `staticcheck` and friends reported various smaller issues. This commit addresses some of them. --- cmd/knut/main.go | 2 +- internal/pkg/knut/helper.go | 2 +- internal/pkg/knut/tar.go | 2 +- internal/pkg/knut/tls.go | 1 - internal/pkg/knut/upload.go | 5 ++--- internal/pkg/knut/zip.go | 9 +++++++-- internal/pkg/knut/zipfs.go | 6 +++--- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/knut/main.go b/cmd/knut/main.go index 2224516..0e92808 100644 --- a/cmd/knut/main.go +++ b/cmd/knut/main.go @@ -92,7 +92,7 @@ func main() { flag.Usage = usage flag.Parse() - if opts.doPrintVersion == true { + if opts.doPrintVersion { fmt.Println(Version, GitHash, BuildDate) os.Exit(0) } diff --git a/internal/pkg/knut/helper.go b/internal/pkg/knut/helper.go index 944f207..bd0b5a5 100644 --- a/internal/pkg/knut/helper.go +++ b/internal/pkg/knut/helper.go @@ -17,7 +17,7 @@ var ( errEmptyPairParts = fmt.Errorf("empty pair parts") ) -// getWindowAndTree splits "arg" at the ':' seperator. in the context +// getWindowAndTree splits "arg" at the ':' separator. in the context // of *knut* the first part is called "window" (it is the url-endpoint, // essentially), the part after the first ':' is called "the tree", it's // the content that will be delivered. diff --git a/internal/pkg/knut/tar.go b/internal/pkg/knut/tar.go index 9c4cd49..6b796dd 100644 --- a/internal/pkg/knut/tar.go +++ b/internal/pkg/knut/tar.go @@ -75,7 +75,7 @@ func (entry *tarEntry) TarFileEventually(name string) { } tf := entry.header.Typeflag - if tf == tar.TypeReg || tf == tar.TypeRegA || tf == tar.TypeLink { + if tf == tar.TypeReg || tf == tar.TypeLink { entry.TarFile(name) } } diff --git a/internal/pkg/knut/tls.go b/internal/pkg/knut/tls.go index d851895..d0450eb 100644 --- a/internal/pkg/knut/tls.go +++ b/internal/pkg/knut/tls.go @@ -114,7 +114,6 @@ func (ot *OnetimeTLS) fillTLSConfig() { ot.tlsConfig.NextProtos = []string{"http/1.1"} ot.tlsConfig.MinVersion = tls.VersionTLS11 ot.tlsConfig.CurvePreferences = []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256} - ot.tlsConfig.PreferServerCipherSuites = true ot.tlsConfig.SessionTicketsDisabled = true ot.tlsConfig.Certificates = make([]tls.Certificate, 1) ot.tlsConfig.Certificates[0], ot.err = tls.X509KeyPair(ot.certBytes, ot.privKeyBytes) diff --git a/internal/pkg/knut/upload.go b/internal/pkg/knut/upload.go index 89f4e07..6c02c9e 100644 --- a/internal/pkg/knut/upload.go +++ b/internal/pkg/knut/upload.go @@ -6,7 +6,6 @@ package knut import ( "fmt" "io" - "io/ioutil" "log" "mime/multipart" "net" @@ -78,7 +77,7 @@ input[type="submit"] { margin-top: 1em } } fmt.Fprintln(w, htmlDoc) - fmt.Fprintf(w, "ok, received %d bytes over %s", nBytes, time.Now().Sub(startTime)) + fmt.Fprintf(w, "ok, received %d bytes over %s", nBytes, time.Since(startTime)) }) } @@ -97,7 +96,7 @@ func storeFormFile(prefix, dir string, fh *multipart.FileHeader) (int64, error) } defer postedFile.Close() - osFile, err := ioutil.TempFile(dir, prefix) + osFile, err := os.CreateTemp(dir, prefix) if err != nil { return 0, err } diff --git a/internal/pkg/knut/zip.go b/internal/pkg/knut/zip.go index e68ce9e..dbeee3d 100644 --- a/internal/pkg/knut/zip.go +++ b/internal/pkg/knut/zip.go @@ -39,6 +39,11 @@ func ZipDirectory(w io.Writer, dir, prefix string, store bool) error { return nil } + // skip "error" entries + if err == nil { + return nil + } + f, err := os.Open(path) if err != nil { fmt.Fprintf(os.Stderr, "warning: problem open file %s for reading: %v\n", @@ -82,10 +87,10 @@ func zipEntry(zw *zip.Writer, name string, fi os.FileInfo, store bool) (io.Write } fh.Name = name + fh.Method = zip.Deflate + if store { fh.Method = zip.Store - } else { - fh.Method = zip.Deflate } return zw.CreateHeader(fh) diff --git a/internal/pkg/knut/zipfs.go b/internal/pkg/knut/zipfs.go index 52a8d7f..bbaf543 100644 --- a/internal/pkg/knut/zipfs.go +++ b/internal/pkg/knut/zipfs.go @@ -43,7 +43,7 @@ func ZipFSHandler(name, prefix, index string) http.Handler { if strings.HasSuffix(r.URL.Path, "/") { if index == "" { w.Header().Set("Content-Type", "text/html; charset=utf8") - indexFolderEntries(w, z.Reader, name) + indexFolderEntries(w, &z.Reader, name) return } r.URL.Path = path.Join(r.URL.Path, index) @@ -99,7 +99,7 @@ func serveZipEntry(w http.ResponseWriter, zFile *zip.File) { // indexFolderEntries creates an index pages page of all the file entries // in the given "folder" -func indexFolderEntries(w http.ResponseWriter, zreader zip.Reader, folder string) { +func indexFolderEntries(w http.ResponseWriter, zreader *zip.Reader, folder string) { fmt.Fprint(w, "
")
 	defer fmt.Fprint(w, "
") @@ -114,7 +114,7 @@ func indexFolderEntries(w http.ResponseWriter, zreader zip.Reader, folder string } } -func listFolderEntries(zreader zip.Reader, folder string) []string { +func listFolderEntries(zreader *zip.Reader, folder string) []string { entries := make([]string, 0) for _, file := range zreader.File {