|
@@ -48,6 +48,25 @@ func contacts(cs *ContactsStore) http.HandlerFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+@app.route("/contacts/new", methods=['GET']) (1)
|
|
|
+def contacts_new_get():
|
|
|
+
|
|
|
+ return render_template("new.html", contact=Contact()
|
|
|
+*/
|
|
|
+func contactsNewGet(cs *ContactsStore) http.HandlerFunc {
|
|
|
+ tpl := makeTemplate(
|
|
|
+ "layout",
|
|
|
+ "new",
|
|
|
+ )
|
|
|
+ return func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ c := cs.New()
|
|
|
+ if err := tpl.ExecuteTemplate(w, "layout.html", c); err != nil {
|
|
|
+ http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func makeTemplate(first string, others ...string) *template.Template {
|
|
|
paths := append([]string{first}, others...)
|
|
|
for i, path := range paths {
|
|
@@ -63,8 +82,9 @@ func setupRoutes(mux *http.ServeMux, cs *ContactsStore) {
|
|
|
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
|
|
http.ServeFile(w, r, "./static/img/favicon.ico")
|
|
|
})
|
|
|
- mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
|
|
- mux.Handle("/contacts", contacts(cs))
|
|
|
+ mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
|
|
+ mux.Handle("GET /contacts", contacts(cs))
|
|
|
+ mux.Handle("GET /contacts/new", contactsNewGet(cs))
|
|
|
}
|
|
|
|
|
|
func main() {
|