diff options
-rw-r--r-- | main.go | 2 | ||||
-rw-r--r-- | pages.go | 28 | ||||
-rw-r--r-- | tpls/chat.html | 9 | ||||
-rw-r--r-- | tpls/home.html | 9 |
4 files changed, 48 insertions, 0 deletions
@@ -24,6 +24,8 @@ func main() { log.Fatalln("flag perroom must not be 0") } + PrepTemplates() + r := mux.NewRouter() r.HandleFunc("/", Home) r.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(*staticpath)))) diff --git a/pages.go b/pages.go new file mode 100644 index 0000000..40c2c21 --- /dev/null +++ b/pages.go @@ -0,0 +1,28 @@ +package main + +import ( + "html/template" + "net/http" + "path" +) + +var ( + TplHome, TplChat *template.Template +) + +type ChatpageData struct { + Websock string +} + +func PrepTemplates() { + TplHome = template.Must(template.ParseFiles(path.Join(*tplpath, "home.html"))) + TplChat = template.Must(template.ParseFiles(path.Join(*tplpath, "chat.html"))) +} + +func Home(rw http.ResponseWriter, req *http.Request) { + TplHome.Execute(rw, nil) // TODO: Should we log the error? +} + +func Chatpage(rw http.ResponseWriter, req *http.Request) { + TplChat.Execute(rw, ChatpageData{"ws://" + req.Host + req.URL.Path + "socket"}) +} diff --git a/tpls/chat.html b/tpls/chat.html new file mode 100644 index 0000000..c107b49 --- /dev/null +++ b/tpls/chat.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> +<head> + <title></title> +</head> +<body> +{{ .Websock }} +</body> +</html>
\ No newline at end of file diff --git a/tpls/home.html b/tpls/home.html new file mode 100644 index 0000000..c559109 --- /dev/null +++ b/tpls/home.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> +<head> + <title></title> +</head> +<body> +Test +</body> +</html>
\ No newline at end of file |