more boilerplate and dev environment

This commit is contained in:
2026-07-16 16:04:48 -07:00
parent ea34be4e1b
commit a06f21a5c2
27 changed files with 670 additions and 27 deletions
+8 -2
View File
@@ -20,8 +20,14 @@ func InitDB() (*sql.DB, error) {
password = "secret"
}
// Build the DSN. The host "db" matches the service name in docker-compose.yml.
dsn := fmt.Sprintf("oworganizer:%s@tcp(db:3306)/?parseTime=true", password)
host := os.Getenv("DB_HOST")
if host == "" {
// Default to the Docker Compose service name.
host = "db"
}
// Build the DSN. The default host "db" matches the service name in docker-compose.yml.
dsn := fmt.Sprintf("oworganizer:%s@tcp(%s:3306)/?parseTime=true", password, host)
db, err := sql.Open("mysql", dsn)
if err != nil {
+1
View File
@@ -14,6 +14,7 @@ require (
github.com/bytedance/sonic/loader v0.5.1 // indirect
github.com/cloudwego/base64x v0.1.7 // indirect
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
github.com/gin-contrib/cors v1.7.7 // indirect
github.com/gin-contrib/sse v1.1.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
+2
View File
@@ -13,6 +13,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/gin-contrib/cors v1.7.7 h1:Oh9joP463x7Mw72vhvJ61YQm8ODh9b04YR7vsOErD0Q=
github.com/gin-contrib/cors v1.7.7/go.mod h1:K5tW0RkzJtWSiOdikXloy8VEZlgdVNpHNw8FpjUPNrE=
github.com/gin-contrib/sse v1.1.1 h1:uGYpNwTacv5R68bSGMapo62iLTRa9l5zxGCps4hK6ko=
github.com/gin-contrib/sse v1.1.1/go.mod h1:QXzuVkA0YO7o/gun03UI1Q+FTI8ZV/n5t03kIQAI89s=
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
+17
View File
@@ -3,7 +3,10 @@ package main
import (
"log"
"net/http"
"os"
"strings"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
@@ -16,6 +19,20 @@ func main() {
router := gin.Default()
// Configure CORS. In production, set CORS_ALLOWED_ORIGINS to your public domain.
allowedOrigins := []string{"http://localhost:5173"}
if envOrigins := os.Getenv("CORS_ALLOWED_ORIGINS"); envOrigins != "" {
allowedOrigins = strings.Split(envOrigins, ",")
}
router.Use(cors.New(cors.Config{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * 60 * 60,
}))
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",