some updates
This commit is contained in:
31
delete.go
Normal file
31
delete.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user