games inits itself
parent
f40fdd60da
commit
306295ba1c
|
|
@ -32,27 +32,6 @@ func NewDB(ctx context.Context, scheme, conn string) (DB, error) {
|
||||||
}
|
}
|
||||||
defer sql.Close()
|
defer sql.Close()
|
||||||
|
|
||||||
if _, err := sql.ExecContext(ctx, `
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
uuid TEXT,
|
|
||||||
name TEXT
|
|
||||||
);
|
|
||||||
CREATE TABLE IF NOT EXISTS games (
|
|
||||||
uuid TEXT
|
|
||||||
);
|
|
||||||
CREATE TABLE IF NOT EXISTS players (
|
|
||||||
user_uuid TEXT,
|
|
||||||
game_uuid TEXT
|
|
||||||
);
|
|
||||||
CREATE TABLE IF NOT EXISTS events (
|
|
||||||
game_uuid TEXT,
|
|
||||||
timestamp DATETIME,
|
|
||||||
payload TEXT
|
|
||||||
);
|
|
||||||
`); err != nil {
|
|
||||||
return DB{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, err
|
return db, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,29 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
type Games struct {
|
type Games struct {
|
||||||
db DB
|
db DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGames(db DB) Games {
|
func NewGames(ctx context.Context, db DB) (Games, error) {
|
||||||
return Games{db: db}
|
err := db.Exec(ctx, `
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
uuid TEXT,
|
||||||
|
name TEXT
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS games (
|
||||||
|
uuid TEXT
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS players (
|
||||||
|
user_uuid TEXT,
|
||||||
|
game_uuid TEXT
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS events (
|
||||||
|
game_uuid TEXT,
|
||||||
|
timestamp DATETIME,
|
||||||
|
payload TEXT
|
||||||
|
);
|
||||||
|
`)
|
||||||
|
return Games{db: db}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,16 @@ func run(ctx context.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
games, err := NewGames(ctx, db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
S := &S{
|
S := &S{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
limiter: rate.NewLimiter(10, 10),
|
limiter: rate.NewLimiter(10, 10),
|
||||||
config: config,
|
config: config,
|
||||||
games: NewGames(db),
|
games: games,
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue