aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2016-06-20 15:33:30 +0200
committerclsr <clsr@clsr.net>2016-06-20 15:33:30 +0200
commit26c6e8e8fb3a37344fba8438af54e2947a5e5b0b (patch)
tree9b251c11686b28acf19e585182ea93e82910a267
parent0861d561839407ce63ccc56317ea74e52c457381 (diff)
downloadgomf-26c6e8e8fb3a37344fba8438af54e2947a5e5b0b.tar.gz
gomf-26c6e8e8fb3a37344fba8438af54e2947a5e5b0b.zip
Handle empty /static/grill dirsv0.2.5
-rw-r--r--website.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/website.go b/website.go
index be962e6..7cc32c1 100644
--- a/website.go
+++ b/website.go
@@ -100,7 +100,9 @@ func handleGrill(w http.ResponseWriter, r *http.Request) {
grills, err := ioutil.ReadDir("static/grill/")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
- return
+ } else if len(grills) == 0 {
+ http.Error(w, "files not found", http.StatusNotFound)
+ } else {
+ http.Redirect(w, r, "/static/grill/"+grills[rand.Intn(len(grills))].Name(), http.StatusFound)
}
- http.Redirect(w, r, "/static/grill/"+grills[rand.Intn(len(grills))].Name(), http.StatusFound)
}