Files
likegears 85ba15c564 Initial commit: Material Texture API service
- Go + Gin + GORM + PostgreSQL backend
- RESTful API for material management
- Docker deployment support
- Database partitioning for billion-scale data
- API documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 15:29:49 +08:00

38 lines
894 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"log"
"material_texture/internal/config"
"material_texture/internal/models"
"material_texture/internal/router"
)
func main() {
// 加载配置
cfg := config.Load()
// 连接数据库
db := config.NewDatabase(cfg)
// 自动迁移表结构
if err := db.AutoMigrate(&models.Material{}, &models.MaterialBinding{}); err != nil {
log.Fatalf("Failed to migrate database: %v", err)
}
// 添加唯一约束GORM的uniqueIndex在某些情况下可能不生效
db.Exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_material_group
ON material_bindings(material_id, group_id)`)
log.Println("Database migrated successfully")
// 设置路由
r := router.Setup(db, cfg)
// 启动服务器
log.Printf("Server starting on port %s", cfg.ServerPort)
if err := r.Run(":" + cfg.ServerPort); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}