drop storage interface (only one implementation)
1 file changed, 16 insertions(+), 17 deletions(-)
changed files
M shared/storage/files/writer.go → shared/storage/writer.go
@@ -1,4 +1,4 @@ -package files +package storage import ( "compress/gzip"@@ -14,10 +14,9 @@ "github.com/klauspost/compress/zstd" "alin.ovh/homestead/domain/content" "alin.ovh/homestead/shared/file" - "alin.ovh/homestead/shared/storage" ) -type Files struct { +type Writer struct { outputDirectory string options *Options log *log.Logger@@ -32,15 +31,15 @@ gzipLevel = 6 brotliLevel = 9 ) -func NewWriter(outputDirectory string, logger *log.Logger, opts *Options) (*Files, error) { - return &Files{ +func NewWriter(outputDirectory string, logger *log.Logger, opts *Options) (*Writer, error) { + return &Writer{ outputDirectory: outputDirectory, options: opts, log: logger, }, nil } -func (f *Files) OpenRead(filename string) (io.ReadCloser, error) { +func (f *Writer) OpenRead(filename string) (io.ReadCloser, error) { file, err := os.Open(f.join(filename)) if err != nil { return nil, fault.Wrap(err)@@ -49,11 +48,11 @@ return file, nil } -func (f *Files) OpenWrite(filename string) (io.WriteCloser, error) { +func (f *Writer) OpenWrite(filename string) (io.WriteCloser, error) { return openFileWrite(f.join(filename)) } -func (f *Files) WritePost(post *content.Post, wt io.WriterTo) error { +func (f *Writer) WritePost(post *content.Post, wt io.WriterTo) error { fd, err := f.write(post.URL, wt) if err != nil { return err@@ -75,7 +74,7 @@ return nil } -func (f *Files) Write(pathname string, _ string, wt io.WriterTo) error { +func (f *Writer) Write(pathname string, _ string, wt io.WriterTo) error { fd, err := f.write(pathname, wt) if err != nil { return err@@ -88,15 +87,15 @@ return nil } -func (f *Files) NewFileFromPost(post *content.Post) *storage.File { - return &storage.File{ +func (f *Writer) NewFileFromPost(post *content.Post) *File { + return &File{ Path: post.URL, FSPath: pathNameToFileName(post.URL), Encodings: map[string]*os.File{}, } } -func (f *Files) CopyFile(file *storage.File, src *os.File) error { +func (f *Writer) CopyFile(file *File, src *os.File) error { dst, err := f.write(file.Path, src) if err != nil { return err@@ -109,11 +108,11 @@ return nil } -func (f *Files) WriteFile(file *storage.File, wt io.WriterTo) error { +func (f *Writer) WriteFile(file *File, wt io.WriterTo) error { return f.Write(file.Path, file.Title, wt) } -func (f *Files) OpenFileAndVariants(filename string) (file.FileLike, error) { +func (f *Writer) OpenFileAndVariants(filename string) (file.FileLike, error) { if f.options.Compress { return multiOpenFile(f.join(filename)) }@@ -121,7 +120,7 @@ return openFileWrite(f.join(filename)) } -func (f *Files) Mkdirp(dir string) error { +func (f *Writer) Mkdirp(dir string) error { err := os.MkdirAll(f.join(dir), 0o750) if err != nil { return fault.Wrap(err, fmsg.With("could not create directory"))@@ -130,7 +129,7 @@ return nil } -func (f *Files) write( +func (f *Writer) write( pathname string, writer io.WriterTo, ) (file.FileLike, error) {@@ -224,6 +223,6 @@ return file.NewMultiFile(r, gz, br, zst), nil } -func (f *Files) join(filename string) string { +func (f *Writer) join(filename string) string { return filepath.Join(f.outputDirectory, pathNameToFileName(filename)) }