refactoring

This commit is contained in:
Settel 2021-08-05 00:40:31 +02:00
parent 8d06d702fd
commit 406c58352b
7 changed files with 26 additions and 8 deletions

View File

@ -18,8 +18,8 @@ func (app Application) loadGames() error {
if gm, err := game.NewGameFromFile(fileName); err != nil {
return err
} else {
gm.Id = file.Name()
app.games[gm.Id] = gm
gm.SetId(file.Name())
app.games[gm.GetId()] = gm
}
}

View File

@ -18,8 +18,8 @@ func (app Application) loadUsers() error {
if usr, err := user.NewUserFromFile(fileName); err != nil {
return err
} else {
usr.Id = file.Name()[0:6]
app.users[usr.Id] = usr
usr.SetId(file.Name()[0:6])
app.users[usr.GetId()] = usr
}
}

View File

@ -19,3 +19,11 @@ func NewGameFromFile(fileName string) (*Game, error) {
return &gm, nil
}
}
func (gm *Game) SetId(id string) {
gm.id = id
}
func (gm *Game) GetId() string {
return gm.id
}

View File

@ -1,6 +1,8 @@
package game
import ()
type Game struct {
Id string `json:"id"`
id string
Players []string `json:"players"`
}

View File

@ -31,7 +31,7 @@ func (authMux *AuthMux) Login(w http.ResponseWriter, r *http.Request) {
}
cookie := authMux.createCookie()
cookie.Value = usr.Id
cookie.Value = usr.GetId()
cookie.MaxAge = 0
http.SetCookie(w, cookie)
w.Header().Add("Content-Type", "text/plain")

View File

@ -7,7 +7,7 @@ const (
)
type User struct {
Id string `json:"id"`
id string
Name string `json:"name"`
Role string `json:"role"`
}

View File

@ -8,7 +8,7 @@ import (
func NewUser(id, name, role string) *User {
return &User{
Id: id,
id: id,
Name: name,
Role: role,
}
@ -28,6 +28,14 @@ func NewUserFromFile(fileName string) (*User, error) {
}
}
func (user *User) SetId(id string) {
user.id = id
}
func (user *User) GetId() string {
return user.id
}
func (user *User) IsPlayer() bool {
return true
}