filebrowser/delete.go
2016-06-11 10:08:33 +01:00

32 lines
559 B
Go

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
}