feat(backend,docker,docs): implement Go/Gin/SQLite REST API server, Docker containerization, and architecture specifications
- Implement standalone Go backend API server using Gin and pure-Go SQLite (modernc.org/sqlite) - Add 11-table schema DDL migrations (000001_init.up.sql) based on DATA_TABLE.md - Add seed data ingestion tool (cmd/seed) and static TypeScript content exporter (cmd/export-content) - Add configuration loader (internal/config) supporting environment variables and .env files (HOST, PORT, DB_PATH, GIN_MODE, CORS_ALLOW_ORIGINS, AUTO_MIGRATE) - Add lightweight multi-stage Dockerfile and docker-compose.yml with persistent SQLite volume - Add comprehensive architecture specification (ARCHITECTURE.md) and REST API interface specification (API_INTERFACE.md) - Harmonize frontend publications page to consume isHighlight flag from database-synced content
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/config"
|
||||
"git.godopu.com/lab/landing_page/backend/internal/db"
|
||||
"git.godopu.com/lab/landing_page/backend/internal/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables & .env
|
||||
cfg := config.Load()
|
||||
|
||||
// Optional CLI flags override environment defaults
|
||||
portFlag := flag.Int("port", 0, "Port for the Gin server to listen on (overrides PORT)")
|
||||
hostFlag := flag.String("host", "", "Host for the Gin server to bind on (overrides HOST)")
|
||||
dbPathFlag := flag.String("db", "", "Path to SQLite database file (overrides DB_PATH)")
|
||||
ginModeFlag := flag.String("mode", "", "Gin mode: release, debug, test (overrides GIN_MODE)")
|
||||
flag.Parse()
|
||||
|
||||
if *portFlag > 0 {
|
||||
cfg.Port = *portFlag
|
||||
}
|
||||
if *hostFlag != "" {
|
||||
cfg.Host = *hostFlag
|
||||
}
|
||||
if *dbPathFlag != "" {
|
||||
cfg.DBPath = *dbPathFlag
|
||||
}
|
||||
if *ginModeFlag != "" {
|
||||
cfg.GinMode = *ginModeFlag
|
||||
}
|
||||
|
||||
gin.SetMode(cfg.GinMode)
|
||||
|
||||
log.Printf("Connecting to SQLite database at %s...", cfg.DBPath)
|
||||
database, err := db.Connect(cfg.DBPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to connect to database: %v", err)
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
if cfg.AutoMigrate {
|
||||
log.Println("Ensuring database schema migrations are applied...")
|
||||
if err := db.RunMigrations(database); err != nil {
|
||||
log.Fatalf("Migration failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
r := router.SetupRouter(database, cfg.CORSAllowOrigins)
|
||||
|
||||
addr := cfg.Address()
|
||||
log.Printf("Starting ANL Backend API server on http://%s/api/v1 (mode: %s)...", addr, cfg.GinMode)
|
||||
if err := r.Run(addr); err != nil {
|
||||
log.Fatalf("Server failed to run: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user