/
app.go
34 lines (29 loc) · 820 Bytes
/
app.go
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
31
32
33
34
package controllers
import (
"fmt"
"github.com/revel/revel"
"github.com/tiagozini/go_tictactoe_online/gameroom"
)
type App struct {
*revel.Controller
}
func (c App) Index() revel.Result {
greeting := "Welcome to Tic-Tac-Toe Combat"
return c.Render(greeting)
}
func (c App) Welcome() revel.Result {
greeting := "Welcome to my place"
id := c.Params.Get("id")
return c.Render(greeting, id)
}
func (c App) EnterGame(nickname string) revel.Result {
c.Validation.Required(nickname).Message("Your nickname is required!")
c.Validation.MinSize(nickname, 3).Message("Your nickname is not long enough!")
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(App.Index)
}
user := gameroom.AddUser(nickname)
return c.Redirect(fmt.Sprintf("/Refresh/Room?userId=%d", user.Id))
}