some updates

This commit is contained in:
Henrique Dias
2016-06-11 10:08:33 +01:00
parent 9b25214272
commit 4163aeae40
6 changed files with 256 additions and 234 deletions

31
delete.go Normal file
View File

@@ -0,0 +1,31 @@
package filemanager
import (
"net/http"
"os"
)
// Delete handles the delete requests
func Delete(path string, info os.FileInfo) (int, error) {
var err error
// If it's dir, remove all of the content inside
if info.IsDir() {
err = os.RemoveAll(path)
} else {
err = os.Remove(path)
}
// Check for errors
if err != nil {
switch {
case os.IsPermission(err):
return http.StatusForbidden, err
case os.IsExist(err):
return http.StatusGone, err
default:
return http.StatusInternalServerError, err
}
}
return http.StatusOK, nil
}