package api import ( "fmt" "os" "path/filepath" ) type Storage struct { Path string } const ( StorageTmp = "tmp" StorageUpload = "upload" ) func (s *Storage) Join(paths ...string) string { return filepath.Join(s.Path, filepath.Join(paths...)) } func (s *Storage) Create(paths ...string) error { return os.MkdirAll(s.Join(paths...), 0755) } func (s *Storage) Exists(paths ...string) bool { f, err := os.Stat(s.Join(paths...)) if err != nil { return false } return f.IsDir() } func (s *Storage) Delete(paths ...string) error { if s.Exists(paths...) { return os.RemoveAll(s.Join(paths...)) } else { return fmt.Errorf("%s doesn't exists", s.Join(paths...)) } }