Add first page & page handling
This commit is contained in:
parent
8414087ca2
commit
ecbe0ad93e
26
market.go
Normal file
26
market.go
Normal 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
3
templates/index.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[logo]
|
||||||
|
{{ .test }}
|
||||||
|
[categories]
|
Loading…
Reference in New Issue
Block a user