diff options
| author | Elizabeth <elizabeth@simponic.xyz> | 2024-04-09 18:39:14 -0400 |
|---|---|---|
| committer | simponic <simponic@hatecomputers.club> | 2024-04-09 18:39:14 -0400 |
| commit | 1d75bf7489527925217bd5611ba7910c0ffe077c (patch) | |
| tree | 3b6e6056912648a88e1e42c1e42ed7e58e2d4701 /adapters/files/filesystem | |
| parent | ee49015cc90e6c136ad94243fffc9241b9506a36 (diff) | |
| download | hatecomputers.club-1d75bf7489527925217bd5611ba7910c0ffe077c.tar.gz hatecomputers.club-1d75bf7489527925217bd5611ba7910c0ffe077c.zip | |
profiles (#7)
Reviewed-on: https://git.hatecomputers.club/hatecomputers/hatecomputers.club/pulls/7
Co-authored-by: Elizabeth <elizabeth@simponic.xyz>
Co-committed-by: Elizabeth <elizabeth@simponic.xyz>
Diffstat (limited to 'adapters/files/filesystem')
| -rw-r--r-- | adapters/files/filesystem/filesystem.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/adapters/files/filesystem/filesystem.go b/adapters/files/filesystem/filesystem.go new file mode 100644 index 0000000..726a588 --- /dev/null +++ b/adapters/files/filesystem/filesystem.go @@ -0,0 +1,37 @@ +package filesystem + +import ( + "io" + "os" + "path/filepath" +) + +type FilesystemAdapter struct { + BasePath string + Permissions os.FileMode +} + +func (f *FilesystemAdapter) CreateFile(path string, content io.Reader) (string, error) { + fullPath := f.BasePath + path + dir := filepath.Dir(fullPath) + if _, err := os.Stat(dir); os.IsNotExist(err) { + os.MkdirAll(dir, f.Permissions) + } + + file, err := os.Create(f.BasePath + path) + if err != nil { + return "", err + } + defer file.Close() + + _, err = io.Copy(file, content) + if err != nil { + return "", err + } + + return path, nil +} + +func (f *FilesystemAdapter) DeleteFile(path string) error { + return os.Remove(f.BasePath + path) +} |
