remove duplicate files #8
@@ -1,42 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Enpoint that returns a list of articles given search terms in the post
|
|
||||||
// request of a search form. Uses the content template.
|
|
||||||
func (app *App) Article(w http.ResponseWriter, req *http.Request) {
|
|
||||||
// get id
|
|
||||||
id, err := strconv.ParseUint(req.PathValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
http.NotFound(w, req)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// get articles
|
|
||||||
article, err := app.articles.ById(int(id))
|
|
||||||
if err != nil {
|
|
||||||
// treat as no result
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// render template
|
|
||||||
t := template.Must(template.ParseFiles(
|
|
||||||
"assets/templates/articlePage.html",
|
|
||||||
"assets/templates/layout.html",
|
|
||||||
))
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"SelectedNavItemArticle": false,
|
|
||||||
"ArticlePageVM": article.PageViewModel(),
|
|
||||||
}
|
|
||||||
err = t.ExecuteTemplate(w, "base", data)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Failed to render template", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user