# smart-infra **Repository Path**: hubert_rust/smart-infra ## Basic Information - **Project Name**: smart-infra - **Description**: No description available - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-06 - **Last Updated**: 2026-03-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # smart-infra 数字化基础设施平台,基于 Go 1.26 + Gin + PostgreSQL。**架构对齐 smart-platform**:console、auth、apps 作为**插件**注册,同一二进制可同时启动三个端口(5366 / 5368 / 5369),各用独立配置文件。 ## 技术栈 - Go 1.26 - Gin - PostgreSQL(pgx/v5) - 配置:YAML,**每应用独立**:config_console.yaml、config_auth.yaml、config_apps.yaml ## 架构:插件式多 App | 应用 | 配置文件 | 端口 | |--------|------------------------|-------| | console | configs/config_console.yaml | **5366** | | auth | configs/config_auth.yaml | **5368** | | apps | configs/config_apps.yaml | **5369** | - **编译**:通过 Build Tags 将需要运行的 App 编进二进制。三端同时运行请使用: ```bash go build -tags "include_console,include_auth,include_apps" -o smart-infra ./cmd/smart-infra ``` - **运行**:`./smart-infra` 会启动所有已编译进的 App(每个 App 在 Initialize 时加载自己的 config_xxx.yaml,在各自端口启动)。 - 可选通过 `-ldflags "-X main.IncludedApps=console,auth,apps"` 指定要启动的 App 列表。 ## 目录结构 ``` smart-infra/ ├── cmd/smart-infra/ # main + service_console/auth/apps(build tag 注册) ├── internal/ │ ├── shared/app/ # App 接口与注册表 │ ├── shared/config、database、utils │ ├── api/router # Register(r) / RegisterApp(r, app),未匹配请求由 webui/dist 提供 SPA │ ├── console/、auth/、apps/ # 各含 app.go、router/ │ └── webui/dist # 统一前端构建产出(仅此一处,如 src/del 构建到此) ├── configs/ │ ├── config_console.yaml │ ├── config_auth.yaml │ └── config_apps.yaml └── go.mod ``` ## 运行 ```bash cd smart-infra # 编译(三端) go build -tags "include_console,include_auth,include_apps" -o smart-infra ./cmd/smart-infra # 运行(同时起 5366、5368、5369) ./smart-infra ``` 未构建前端时,各端口根路径会显示占位页。 ## 前端与打包进二进制 - **前端统一打包**到 **internal/webui/dist**(仅此一处)。控制台前端在 **src/del**,构建产出到该目录。 - **App 接口**仅包含 `RegisterRoutes(r, prefix)`,路由由各应用实现;未匹配请求由 router 统一用 webui/dist 提供 SPA。 - 各 App 在 Start() 时调用 `router.RegisterApp(r, a)`,挂载自己的 API;同一份前端在 5366/5368/5369 任一端口未匹配时均回退到该 SPA。 **完整构建(三前端 + 三端二进制):** ```bash # 控制台前端(在 src/del) cd del && npm install && npm run build && cd ../smart-infra # auth、apps 前端(仍在 smart-infra 内) cd smart-infra cd web/auth && npm install && npm run build && cd ../.. cd web/apps && npm install && npm run build && cd ../.. go build -tags "include_console,include_auth,include_apps" -o smart-infra ./cmd/smart-infra ``` ## 健康检查 - **5366**:`GET http://localhost:5366/health`、`/ping` - **5368**:`GET http://localhost:5368/health`、`/ping` - **5369**:`GET http://localhost:5369/health`、`/ping` ### IAM / auth API 返回 HTTP 404(例如 `PUT /auth/users/:id`) - **现象**:浏览器里 `GET /auth/users/:id` 正常(或返回 200 + JSON 业务码),但 **`PUT` 同一路径为 HTTP 404**。 - **原因**:当前运行的 **auth 进程不是最新编译产物**(路由里尚未包含 `PUT`),或 5368 上跑的是旧二进制。 - **处理**:在仓库根目录重新编译并重启 auth(或含 auth 的 `smart-infra` 一体化进程),例如: ```bash go build -tags "include_console,include_auth,include_apps" -o smart-infra ./cmd/smart-infra ``` 停止旧进程后运行新的 `./smart-infra`(Windows 下为 `smart-infra.exe`)。 ## 数据库 - **库名**:smart_infra(console、apps 使用;auth 可不配)。 - **Schema**:platform、iam、mail、sms、resource。 - 在 **config_console.yaml**、**config_apps.yaml** 中配置 database;**config_auth.yaml** 可不配 database。 **初始化步骤:** 1. 创建库:`CREATE DATABASE smart_infra;` 2. 执行迁移:`psql -d smart_infra -f migrations/001_schemas.sql` 3. 按需修改 config_console.yaml、config_apps.yaml 中的 database 连接信息。