diff options
Diffstat (limited to 'handler.go')
-rw-r--r-- | handler.go | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -23,7 +23,7 @@ type Recipe struct { func indexGet(w http.ResponseWriter, r *http.Request) { - entries, err := os.ReadDir("data/storage/recipes") + entries, err := os.ReadDir(filepath.Join(config.Data, "recipes")) if err != nil { http.Error(w, "Could not list recipes!", 500) return @@ -41,7 +41,7 @@ func indexGet(w http.ResponseWriter, r *http.Request) { continue } - textpath := fmt.Sprintf("data/storage/recipes/%s/text", v.Name()) + textpath := filepath.Join(config.Data, "recipes", v.Name(), "text") data, _ := ioutil.ReadFile(textpath) markup := Markup(data) @@ -66,7 +66,7 @@ func recipeGet(w http.ResponseWriter, r *http.Request) { } idStr := ids[0] - textpath := fmt.Sprintf("data/storage/recipes/%s/text", idStr) + textpath := filepath.Join(config.Data, "recipes", idStr, "text") data, _ := ioutil.ReadFile(textpath) markup := Markup(data) @@ -90,7 +90,7 @@ func recipeEditGet(w http.ResponseWriter, r *http.Request) { } idStr := ids[0] - textpath := fmt.Sprintf("data/storage/recipes/%s/text", idStr) + textpath := filepath.Join(config.Data, "recipes", idStr, "text") data, _ := ioutil.ReadFile(textpath) recipe := Recipe{ @@ -124,7 +124,7 @@ func recipeEditPost(w http.ResponseWriter, r *http.Request) { return } - textpath := fmt.Sprintf("data/storage/recipes/%s/text", idStr) + textpath := filepath.Join(config.Data, "recipes", idStr, "text") err = ioutil.WriteFile(textpath, buffer, 0644) if err != nil { http.Error(w, "Could not save new text for recipe.", 500) @@ -152,7 +152,7 @@ func recipeConfirmDeletionPost(w http.ResponseWriter, r *http.Request) { return } - recipedir := fmt.Sprintf("data/storage/recipes/%s", ids[0]) + recipedir := filepath.Join(config.Data, "recipes", ids[0]) err := os.RemoveAll(recipedir) if err != nil { http.Error(w, "Could not delete recipe.", 500) @@ -164,7 +164,7 @@ func recipeConfirmDeletionPost(w http.ResponseWriter, r *http.Request) { func addRecipesGet(w http.ResponseWriter, r *http.Request) { - entries, err := os.ReadDir("data/storage/recipes") + entries, err := os.ReadDir(filepath.Join(config.Data, "recipes")) if err != nil { http.Error(w, "Could not get list of existing recipes!", 500) return @@ -188,15 +188,16 @@ func addRecipesGet(w http.ResponseWriter, r *http.Request) { } newId := biggest + 1 + newIdStr := strconv.Itoa(newId) - recipedir := fmt.Sprintf("data/storage/recipes/%d", newId) + recipedir := filepath.Join(config.Data, "recipes", newIdStr) err = os.Mkdir(recipedir, 0755) if err != nil { http.Error(w, "Could not create new recipe!", 500) return } - textpath := fmt.Sprintf("data/storage/recipes/%d/text", newId) + textpath := filepath.Join(config.Data, "recipes", newIdStr, "text") err = os.WriteFile(textpath, make([]byte, 0), 0644) if err != nil { http.Error(w, "Could not create new recipe!", 500) |