Rename to craban
This commit is contained in:
parent
38767a78d3
commit
ca0bfa2398
217 changed files with 23 additions and 23 deletions
49
server/model/config.go
Normal file
49
server/model/config.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultPort = 8080
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabasePath *string `yaml:"database_path"`
|
||||
Port *int `yaml:"port"`
|
||||
}
|
||||
|
||||
func (c *Config) SetDefaults() {
|
||||
if c.Port == nil {
|
||||
c.Port = NewInt(DefaultPort)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) IsValid() error {
|
||||
if c.DatabasePath == nil || *c.DatabasePath == "" {
|
||||
return fmt.Errorf("database_path cannot be empty")
|
||||
}
|
||||
|
||||
if c.Port == nil || *c.Port == 0 {
|
||||
return fmt.Errorf("port cannot be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadConfig(path string) (*Config, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := yaml.Unmarshal(b, &config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
7
server/model/game.go
Normal file
7
server/model/game.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package model
|
||||
|
||||
type Game struct {
|
||||
ID int
|
||||
UserID int
|
||||
Name string
|
||||
}
|
12
server/model/game_member.go
Normal file
12
server/model/game_member.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package model
|
||||
|
||||
const (
|
||||
RoleGameMaster = "role_game_master"
|
||||
RolePlayer = "role_player"
|
||||
)
|
||||
|
||||
type GameMember struct {
|
||||
GameID int
|
||||
UserID int
|
||||
Role string
|
||||
}
|
33
server/model/user.go
Normal file
33
server/model/user.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int
|
||||
Name string
|
||||
Mail string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (u *User) IsValid() error {
|
||||
if u.Name == "" {
|
||||
return fmt.Errorf("name must not be empty")
|
||||
}
|
||||
|
||||
if u.Mail == "" {
|
||||
return fmt.Errorf("mail must not be empty")
|
||||
}
|
||||
|
||||
if u.Username == "" {
|
||||
return fmt.Errorf("username must not be empty")
|
||||
}
|
||||
|
||||
if u.Password == "" {
|
||||
return fmt.Errorf("password must not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
12
server/model/utils.go
Normal file
12
server/model/utils.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func NewString(s string) *string { return &s }
|
||||
func NewInt(i int) *int { return &i }
|
||||
|
||||
func NewID() string {
|
||||
return uuid.New().String()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue