diff options
author | Alan Pearce | 2024-06-25 09:14:56 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-25 09:14:56 +0200 |
commit | becede4bfead952239b9cf7c8eb9fb96d01534ec (patch) | |
tree | 20cf7d880487d89bc7d1d2e09912409e1a8f4489 /internal/builder/files.go | |
parent | 4f5ca39f582d83ded08a6e1cbf1a195141623b1c (diff) | |
download | website-becede4bfead952239b9cf7c8eb9fb96d01534ec.tar.lz website-becede4bfead952239b9cf7c8eb9fb96d01534ec.tar.zst website-becede4bfead952239b9cf7c8eb9fb96d01534ec.zip |
refactor/format
Diffstat (limited to 'internal/builder/files.go')
-rw-r--r-- | internal/builder/files.go | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/internal/builder/files.go b/internal/builder/files.go index 20fedf9..a9046d7 100644 --- a/internal/builder/files.go +++ b/internal/builder/files.go @@ -32,6 +32,7 @@ func (mw *MultiWriteCloser) Close() error { lastErr = err } } + return lastErr } @@ -45,6 +46,7 @@ func openFileGz(filename string) (*gzip.Writer, error) { if err != nil { return nil, err } + return gzip.NewWriterLevel(f, gzipLevel) } @@ -54,6 +56,7 @@ func openFileBrotli(filename string) (*brotli.Writer, error) { if err != nil { return nil, err } + return brotli.NewWriterLevel(f, brotliLevel), nil } @@ -70,6 +73,7 @@ func multiOpenFile(filename string) (*MultiWriteCloser, error) { if err != nil { return nil, err } + return &MultiWriteCloser{ writers: []io.WriteCloser{r, gz, br}, multiWriter: io.MultiWriter(r, gz, br), @@ -79,34 +83,38 @@ func multiOpenFile(filename string) (*MultiWriteCloser, error) { func openFileAndVariants(filename string) (io.WriteCloser, error) { if compressFiles { return multiOpenFile(filename) - } else { - return openFileWrite(filename) } + + return openFileWrite(filename) } func copyRecursive(src, dst string) error { return filepath.WalkDir(src, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } rel, err := filepath.Rel(src, path) if err != nil { return err } if d.IsDir() { return mkdirp(dst, rel) - } else { - sf, err := os.Open(path) - if err != nil { - return err - } - defer sf.Close() - df, err := openFileAndVariants(filepath.Join(dst, rel)) - if err != nil { - return err - } - defer df.Close() - if _, err := io.Copy(df, sf); err != nil { - return err - } } + + sf, err := os.Open(path) + if err != nil { + return err + } + defer sf.Close() + df, err := openFileAndVariants(filepath.Join(dst, rel)) + if err != nil { + return err + } + defer df.Close() + if _, err := io.Copy(df, sf); err != nil { + return err + } + return nil }) } |