Elektromarket/market.go
2018-10-24 11:38:03 +02:00

27 lines
563 B
Go

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