This commit is contained in:
Henrique Dias 2016-02-27 14:10:06 +00:00
parent f41a8764d1
commit 5dcc44a1ca
1 changed files with 8 additions and 2 deletions

View File

@ -34,14 +34,20 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
return http.StatusNotAcceptable, errors.New("File format not supported.") return http.StatusNotAcceptable, errors.New("File format not supported.")
} }
// Check if the file exists. If it doesn't, send a "Not Found" message // Check if the file exists.
if _, err := os.Stat(filename); os.IsNotExist(err) { if _, err := os.Stat(filename); os.IsNotExist(err) {
return http.StatusNotFound, nil return http.StatusNotFound, nil
} else if os.IsPermission(err) {
return http.StatusForbidden, nil
} else if err != nil {
return http.StatusInternalServerError, err
} }
// Open the file and check if there was some error while opening // Open the file and check if there was some error while opening
file, err := ioutil.ReadFile(filename) file, err := ioutil.ReadFile(filename)
if err != nil { if os.IsPermission(err) {
return http.StatusForbidden, nil
} else if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }