initial commit. Go test app

This commit is contained in:
2026-05-04 16:38:32 +02:00
parent e50565bf85
commit e1a58e92a8
7 changed files with 329 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package main
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Task struct {
gorm.Model
Title string `json:"title"`
}
func InitDB() *gorm.DB {
dsn := "host=localhost user=postgres password=postgres dbname=go_postgres port=5432 sslmode=disable"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic("Failed to connect to database")
}
// This automatically creates the 'tasks' table in Postgres
db.AutoMigrate(&Task{})
return db
}