Add initial project structure with database connection and routing setup

- Create .env.example and .gitignore to manage environment variables
- Implement database connection logic in bd.go
- Define project model and data retrieval functions in projet.go
- Set up HTTP routes for project management in routes/projet.go
- Add main entry point in main.go to start the server
This commit is contained in:
=
2025-09-23 09:35:10 +02:00
commit 4335fd5cae
8 changed files with 193 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package bd
import (
"database/sql"
"log"
"os"
"github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
)
var db *sql.DB
func GetDB() *sql.DB {
if db == nil {
errenv := godotenv.Load()
if errenv != nil {
log.Fatal("Error loading .env file")
}
// Capture connection properties.
cfg := mysql.NewConfig()
cfg.User = os.Getenv("DB_USER")
cfg.Passwd = os.Getenv("DB_PASS")
cfg.Net = "tcp"
cfg.Addr = os.Getenv("DB_HOST")
cfg.DBName = os.Getenv("DB_NAME")
// Get a database handle.
var err error
db, err = sql.Open("mysql", cfg.FormatDSN())
if err != nil {
log.Fatal(err)
}
}
return db
}