From ecbe0ad93e9c08b7c1212aafb2e612f959301616 Mon Sep 17 00:00:00 2001 From: mikgor Date: Wed, 24 Oct 2018 11:38:03 +0200 Subject: [PATCH] Add first page & page handling --- market.go | 26 ++++++++++++++++++++++++++ templates/index.html | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 market.go create mode 100644 templates/index.html diff --git a/market.go b/market.go new file mode 100644 index 0000000..0b2576e --- /dev/null +++ b/market.go @@ -0,0 +1,26 @@ +package main + +import ( + "net/http" + "html/template" +) + +type Page struct { + Path string + Template string + Data map[string]interface{} +} + +func (p Page) HandlePage(w http.ResponseWriter, r *http.Request) { + t, _ := template.ParseFiles(p.Template) + t.Execute(w, p.Data) +} + +func main() { + var pages map[string]Page = make(map[string]Page) + pages["index"] = Page{Path: "/", Template: "templates/index.html", Data: map[string]interface{}{"test": "1"}} + for k := range pages { + http.HandleFunc(pages[k].Path, pages[k].HandlePage) + } + http.ListenAndServe(":8000", nil) +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8f0d151 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,3 @@ +[logo] +{{ .test }} +[categories]