diff options
Diffstat (limited to 'handler.go')
-rw-r--r-- | handler.go | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -17,7 +17,7 @@ const ( VALID_ID_REGEX = `^[0-9]+$` ) -func indexGet(w http.ResponseWriter, r *http.Request, db *Database, templateRoot string) { +func indexGet(w http.ResponseWriter, r *http.Request, db *Database) { // get data from database cmd := "SELECT id,title FROM recipes ORDER BY title;" @@ -49,11 +49,11 @@ func indexGet(w http.ResponseWriter, r *http.Request, db *Database, templateRoot } // render and return template - path := filepath.Join(templateRoot, "index.html") + path := filepath.Join(config.Http.Templates, "index.html") ServeTemplate(w, "index", path, elements) } -func recipeGet(w http.ResponseWriter, r *http.Request, db *Database, templateRoot string) { +func recipeGet(w http.ResponseWriter, r *http.Request, db *Database) { // get id from URL parameters ids := r.URL.Query()["id"] @@ -116,7 +116,7 @@ func recipeGet(w http.ResponseWriter, r *http.Request, db *Database, templateRoo elements[0].RenderedDescriptionMarkdown = buf.String() // render and return template - path := filepath.Join(templateRoot, "recipe.html") + path := filepath.Join(config.Http.Templates, "recipe.html") ServeTemplate(w, "recipe", path, elements[0]) } @@ -144,7 +144,7 @@ func recipePost(w http.ResponseWriter, r *http.Request, db *Database) { updateRecipe(db, body, idStr) } -func recipeEditGet(w http.ResponseWriter, r *http.Request, db *Database, templateRoot string) { +func recipeEditGet(w http.ResponseWriter, r *http.Request, db *Database) { // get id from URL parameters ids := r.URL.Query()["id"] @@ -201,7 +201,7 @@ func recipeEditGet(w http.ResponseWriter, r *http.Request, db *Database, templat } // render and return template - path := filepath.Join(templateRoot, "recipe_edit.html") + path := filepath.Join(config.Http.Templates, "recipe_edit.html") ServeTemplate(w, "recipe", path, elements[0]) } @@ -245,7 +245,7 @@ func updateRecipe(db *Database, body string, idStr string) { return } -func recipeImageGet(w http.ResponseWriter, r *http.Request, storage string) { +func recipeImageGet(w http.ResponseWriter, r *http.Request) { // get ID ids := r.URL.Query()["id"] @@ -264,13 +264,13 @@ func recipeImageGet(w http.ResponseWriter, r *http.Request, storage string) { // serve image path := fmt.Sprintf("recipes/image/%s.jpg", idStr) - ServeStorage(w, r, storage, path) + ServeStorage(w, r, config.Http.Storage, path) } -func addRecipesGet(w http.ResponseWriter, r *http.Request, static string) { +func addRecipesGet(w http.ResponseWriter, r *http.Request) { filename := "add.html" - path := filepath.Join(static, filename) + path := filepath.Join(config.Http.Static, filename) log.Printf("Trying to serve: %s", path) http.ServeFile(w, r, path) } @@ -299,9 +299,9 @@ func addRecipesPost(w http.ResponseWriter, r *http.Request, db *Database) { } } -func staticGet(w http.ResponseWriter, r *http.Request, filename string, staticRoot string) { +func staticGet(w http.ResponseWriter, r *http.Request, filename string) { - path := filepath.Join(staticRoot, filename) + path := filepath.Join(config.Http.Static, filename) log.Printf("Trying to serve: %s\n", path) http.ServeFile(w, r, path) } |