ADD: added initial page with login

This commit is contained in:
hwinkel
2025-05-20 22:58:31 +02:00
parent 214ab55ad2
commit a330291456
25 changed files with 1064 additions and 35 deletions

View File

@@ -4,6 +4,8 @@ import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq" // Import the PostgreSQL driver
)
type database struct {
@@ -35,12 +37,14 @@ func (d *database) Connect() error {
db, err := sql.Open("postgres", psqlInfo)
// Open a new database connection
if err != nil {
return fmt.Errorf("failed to open database: %w", err)
panic("failed to open database: " + err.Error())
// return fmt.Errorf("failed to open database: %w", err)
}
// Test the connection
if err := db.Ping(); err != nil {
return fmt.Errorf("failed to ping database: %w", err)
panic("failed to ping database: " + err.Error())
// return fmt.Errorf("failed to ping database: %w", err)
}
log.Println("Connected to the database successfully")

View File

@@ -1 +1,32 @@
package database
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq" // Import the PostgreSQL driver
)
const playerTable = `
CREATE TABLE IF NOT EXISTS players (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
age INT NOT NULL,
birthday DATE NOT NULL
);
`
func InitTables(db *sql.DB) {
tables := []string{
playerTable,
}
for _, table := range tables {
if _, err := db.Exec(table); err != nil {
log.Fatalf("Error creating table: %v", err)
}
}
fmt.Println("Tables initialized successfully.")
}