Add first page & page handling

This commit is contained in:
mikgor 2018-10-24 11:38:03 +02:00
parent 8414087ca2
commit ecbe0ad93e
2 changed files with 29 additions and 0 deletions

26
market.go Normal file
View File

@ -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)
}

3
templates/index.html Normal file
View File

@ -0,0 +1,3 @@
[logo]
{{ .test }}
[categories]