diff --git a/README.md b/README.md index cc9adea..d4005c3 100644 --- a/README.md +++ b/README.md @@ -29,19 +29,21 @@ docker compose up -d --build docker compose up -d mysql redis rabbitmq ``` -2) 启动后端 API: +2) 用 compose 启 MySQL 时,宿主机端口是 `3307`。本地 Go 进程请使用面向 compose 依赖的配置文件 `backend/configs/config.compose-local.yaml`。 + +3) 启动后端 API: ```bash cd backend -go run ./cmd +CONFIG_PATH=configs/config.compose-local.yaml go run ./cmd ``` -3) 启动 Worker(消费 MQ、异步落库/更新 Redis 热榜): +4) 启动 Worker(消费 MQ、异步落库/更新 Redis 热榜): ```bash cd backend -go run ./cmd/worker +CONFIG_PATH=configs/config.compose-local.yaml go run ./cmd/worker ``` -4) 启动前端(开发模式): +5) 启动前端(开发模式): ```bash cd frontend npm install @@ -50,6 +52,8 @@ npm run dev 前端默认使用 Vite 代理 `/api` 到 `http://127.0.0.1:8080`(见 `frontend/vite.config.ts`)。 +`backend/configs/config.yaml` 继续适用于本机原生 MySQL `3306` 的场景。 + ## Star History -[![Star History Chart](https://api.star-history.com/svg?repos=LeoninCS/feedsystem_video_go&type=Date)](https://www.star-history.com/#LeoninCS/feedsystem_video_go&Date) \ No newline at end of file +[![Star History Chart](https://api.star-history.com/svg?repos=LeoninCS/feedsystem_video_go&type=Date)](https://www.star-history.com/#LeoninCS/feedsystem_video_go&Date) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index e302e66..3861fd6 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -9,14 +9,18 @@ import ( rediscache "feedsystem_video_go/internal/middleware/redis" "feedsystem_video_go/internal/observability" "log" + "os" "strconv" "time" ) func main() { // 加载配置 - log.Printf("Loading config from configs/config.yaml") - const configPath = "configs/config.yaml" + configPath := os.Getenv("CONFIG_PATH") + if configPath == "" { + configPath = "configs/config.yaml" + } + log.Printf("Loading config from %s", configPath) cfg, usedDefault, err := config.LoadLocalDev(configPath) if err != nil { log.Fatalf("Failed to load config: %v", err) diff --git a/backend/cmd/worker/main.go b/backend/cmd/worker/main.go index 5c74bb1..10923fc 100644 --- a/backend/cmd/worker/main.go +++ b/backend/cmd/worker/main.go @@ -10,7 +10,6 @@ import ( "feedsystem_video_go/internal/video" "feedsystem_video_go/internal/worker" "log" - "os" "os/signal" "strconv" @@ -40,7 +39,10 @@ const ( func main() { // 加载配置 - const configPath = "configs/config.yaml" + configPath := os.Getenv("CONFIG_PATH") + if configPath == "" { + configPath = "configs/config.yaml" + } log.Printf("Loading config from %s", configPath) cfg, usedDefault, err := config.LoadLocalDev(configPath) if err != nil { diff --git a/backend/configs/config.compose-local.yaml b/backend/configs/config.compose-local.yaml new file mode 100644 index 0000000..577168b --- /dev/null +++ b/backend/configs/config.compose-local.yaml @@ -0,0 +1,27 @@ +server: + port: 8080 + +database: + host: localhost + port: 3307 + user: root + password: 123456 + dbname: feedsystem + +redis: + host: localhost + port: 6379 + password: 123456 + db: 0 + +rabbitmq: + host: localhost + port: 5672 + username: admin + password: password123 + +observability: + pprof: + enabled: true + api_addr: localhost:6060 + worker_addr: localhost:6061