Skip to content

Commit

Permalink
Fix various cosmetics
Browse files Browse the repository at this point in the history
`staticcheck` and friends reported various smaller issues. This commit
addresses some of them.
  • Loading branch information
mgumz committed Nov 19, 2023
1 parent b9bedef commit d768201
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/knut/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/knut/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/knut/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/knut/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/knut/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package knut
import (
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net"
Expand Down Expand Up @@ -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))
})
}

Expand All @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions internal/pkg/knut/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/knut/zipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, "<pre>")
defer fmt.Fprint(w, "</pre>")
Expand All @@ -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 {

Expand Down

0 comments on commit d768201

Please sign in to comment.