file.go 747 B

1234567891011121314151617181920212223242526272829
  1. package repositories
  2. //go:generate mkdir -p mocks
  3. //go:generate rm -rf ./mocks/*_minimock.go
  4. //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/interfaces.FileRepository -o ./mocks/ -s "_minimock.go"
  5. import (
  6. "mime/multipart"
  7. "os"
  8. "git.dmitriygnatenko.ru/dima/homethings/internal/interfaces"
  9. "github.com/gofiber/fiber/v2"
  10. )
  11. const uploadPath = "../../web/public"
  12. type fileRepository struct{}
  13. func InitFileRepository() interfaces.FileRepository {
  14. return fileRepository{}
  15. }
  16. func (r fileRepository) Save(fctx *fiber.Ctx, header *multipart.FileHeader, path string) error {
  17. return fctx.SaveFile(header, uploadPath+path)
  18. }
  19. func (r fileRepository) Delete(path string) error {
  20. return os.RemoveAll(uploadPath + path)
  21. }