Esempio n. 1
0
func MainHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	playerList := model.GetPlayerList()
	if playerList.Len() == 0 {
		DeleteCookie(w, r, CLIENT_COOKIE)
		DeleteCookie(w, r, OPPOSITE_COOKIE)
	}
	t, _ := template.ParseFiles(MAIN_TEMPLATE)

	if playerList.Len() > 0 {
		resultArr := model.ListToArr(playerList)
		t.Execute(w, resultArr)
	} else {
		t.Execute(w, 0)

	}
}
Esempio n. 2
0
func UpdatePlayersHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	playerList := model.GetPlayerList()
	clientName := GetCookie(r, CLIENT_COOKIE)
	type Page1 struct {
		Val  string
		List []model.Player
	}

	page := Page1{clientName, model.ListToArr(playerList)}
	template.ParseFiles()
	t, _ := template.ParseFiles(PLAYERS_TEMPLATE)
	//fmt.Println(page.List)

	t.ExecuteTemplate(w, "T", page)

}