summaryrefslogtreecommitdiff
path: root/pages.go
blob: 886f1d64e423da20e2d230e97e520b0afb25da75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	"github.com/gorilla/mux"
	"html/template"
	"net/http"
	"path"
)

var (
	TplHome, TplChat *template.Template
)

type ChatpageData struct {
	Websock, Roomname 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) {
	vars := mux.Vars(req)
	TplChat.Execute(rw, ChatpageData{"ws://" + req.Host + req.URL.Path + "socket", vars["chatroom"]})
}