ADD: added raw structure

This commit is contained in:
2025-05-18 20:14:40 +02:00
parent a43af99699
commit 214ab55ad2
27 changed files with 16731 additions and 0 deletions

27
backend/cmd/main.go Normal file
View File

@@ -0,0 +1,27 @@
package main
import (
"fmt"
"volleyball/internal/database"
)
func main() {
// Initialize the database connection
var db = database.New("localhost", 5432, "user", "password", "dbname")
db.Connect()
// Initialize the server
// server := server.New(db)
// server.Start()
// Initialize the router
// router := router.New()
// router.Start()
// Initialize the logger
// logger := logger.New()
// logger.Start()
// Initialize the config
// config := config.New()
fmt.Println("Hello, World!")
}

3
backend/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module volleyball
go 1.19

View File

@@ -0,0 +1,49 @@
package database
import (
"database/sql"
"fmt"
"log"
)
type database struct {
host string
port int
user string
password string
dbname string
db *sql.DB // Pointer to sql.DB
}
func New(host string, port int, user, password, dbname string) *database {
return &database{
host: host,
port: port,
user: user,
password: password,
dbname: dbname,
db: nil,
}
}
func (d *database) Connect() error {
fmt.Println("Connecting to the database...")
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
d.host, d.port, d.user, d.password, d.dbname)
// Construct the connection string
db, err := sql.Open("postgres", psqlInfo)
// Open a new database connection
if err != nil {
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)
}
log.Println("Connected to the database successfully")
d.db = db
return nil
}

View File

@@ -0,0 +1 @@
package database