From 35c6577ac8ec87f341204cc9f6c047cc40c13a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 20 May 2026 15:14:44 +0800 Subject: [PATCH] chore: gitignore local gateway.dev.yaml and add example template Stop tracking personal dev config (ports, credentials). Developers copy etc/gateway.dev.example.yaml to etc/gateway.dev.yaml locally. Co-authored-by: Cursor --- .gitignore | 5 ++ Makefile | 8 ++- cmd/mongo-index/main.go | 2 +- deploy/README.md | 3 +- etc/README.md | 22 +++++---- etc/gateway.dev.example.yaml | 67 ++++++++++++++++++++++++++ internal/config/config_test.go | 6 +-- internal/model/member/config/config.go | 2 +- 8 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 etc/gateway.dev.example.yaml diff --git a/.gitignore b/.gitignore index 9476944..4f51d21 100644 --- a/.gitignore +++ b/.gitignore @@ -34,8 +34,13 @@ docs/openapi/*.json .env .env.* !.env.example +# 本機開發設定(含 Port、DB、provider 帳密等,勿提交) +etc/gateway.dev.yaml +etc/gateway.private.yaml etc/*-local.yaml etc/*.local.yaml +# 可提交的範例檔 +!etc/gateway.dev.example.yaml # ========================= # IDE / 編輯器 diff --git a/Makefile b/Makefile index 40026a2..a317159 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ GOLANGCI_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 .DEFAULT_GOAL := help .PHONY: help tools gen-api gen-mock build-go-doc gen-doc test fmt lint lint-fix fix check run \ - deps-up deps-up-smtp deps-down deps-down-v deps-logs deps-ps mongo-index run-local + deps-up deps-up-smtp deps-down deps-down-v deps-logs deps-ps mongo-index setup-dev run-local help: ## 顯示可用指令 @echo "Gateway Makefile" @@ -75,7 +75,11 @@ check: fix test ## 提交 / PR 前完整檢查(fmt、lint、test) run: ## 啟動 Gateway(etc/gateway.yaml,無需 Docker) $(GO) run gateway.go -f etc/gateway.yaml -run-dev: ## 啟動 Gateway(etc/gateway.dev.yaml,需 make deps-up) +setup-dev: ## 建立本機 gateway.dev.yaml(自 example,不會被 git 追蹤) + @test -f etc/gateway.dev.yaml || cp etc/gateway.dev.example.yaml etc/gateway.dev.yaml + @echo ">> etc/gateway.dev.yaml ready (edit locally; not committed)" + +run-dev: setup-dev ## 啟動 Gateway(etc/gateway.dev.yaml,需 make deps-up) $(GO) run gateway.go -f etc/gateway.dev.yaml run-local: run-dev ## 別名:同 run-dev diff --git a/cmd/mongo-index/main.go b/cmd/mongo-index/main.go index 3e8d83a..c19f5df 100644 --- a/cmd/mongo-index/main.go +++ b/cmd/mongo-index/main.go @@ -15,7 +15,7 @@ import ( "github.com/zeromicro/go-zero/core/conf" ) -var configFile = flag.String("f", "etc/gateway.dev.yaml", "config file") +var configFile = flag.String("f", "etc/gateway.dev.yaml", "config file (local; copy from etc/gateway.dev.example.yaml)") func main() { flag.Parse() diff --git a/deploy/README.md b/deploy/README.md index acccd16..6427c1c 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -53,4 +53,5 @@ make mongo-index # 手動建立/補齊索引 | 檔案 | 用途 | |------|------| | [`etc/gateway.yaml`](../etc/gateway.yaml) | 預設,無需 Docker | -| [`etc/gateway.dev.yaml`](../etc/gateway.dev.yaml) | 本機完整功能(`make run-dev`) | +| [`etc/gateway.dev.example.yaml`](../etc/gateway.dev.example.yaml) | 範例(可提交) | +| `etc/gateway.dev.yaml` | 本機專用(**勿提交**,見 `.gitignore`) | diff --git a/etc/README.md b/etc/README.md index ee59b1b..cbf1d65 100644 --- a/etc/README.md +++ b/etc/README.md @@ -4,19 +4,23 @@ Gateway 使用 [go-zero `conf`](https://go-zero.dev/docs/tutorials/go-zero/confi ## 用哪個檔案? -| 檔案 | 用途 | 啟動方式 | -|------|------|----------| -| **`gateway.yaml`** | 預設:不需 Docker,僅 HTTP / health | `make run` | -| **`gateway.dev.yaml`** | 本機完整功能(Mongo + Redis + Notification) | `make deps-up` 後 `make run-dev` | +| 檔案 | 是否提交 git | 用途 | +|------|:------------:|------| +| **`gateway.yaml`** | ✅ | 預設:不需 Docker,僅 health | +| **`gateway.dev.example.yaml`** | ✅ | 本機完整功能範例(無真實帳密) | +| **`gateway.dev.yaml`** | ❌ **勿提交** | 你的本機設定(Port、DB、SMTP/SES/三竹帳密) | ```bash -# 僅 API(最快) -make run +# 第一次本機開發 +cp etc/gateway.dev.example.yaml etc/gateway.dev.yaml +# 編輯 etc/gateway.dev.yaml(例如 Port、Mitake 帳密)— 此檔已在 .gitignore -# Notification / Member OTP(需 Docker) make deps-up -make mongo-index # 首次建議執行 -make run-dev +make mongo-index +make run-dev # 會自動 setup-dev(缺檔時從 example 複製) + +# 僅 API(不需 gateway.dev.yaml) +make run ``` --- diff --git a/etc/gateway.dev.example.yaml b/etc/gateway.dev.example.yaml new file mode 100644 index 0000000..7d1e064 --- /dev/null +++ b/etc/gateway.dev.example.yaml @@ -0,0 +1,67 @@ +# 本機開發設定範例(可安全提交) +# 複製為本機專用檔(勿提交): +# cp etc/gateway.dev.example.yaml etc/gateway.dev.yaml +# 再依本機環境修改 Port、Mongo、Redis、SMTP/SES/Mitake 帳密等 + +Name: gateway +Host: 0.0.0.0 +Port: 8888 + +Mongo: + Schema: mongodb + Host: 127.0.0.1 + Port: 27017 + Database: gateway + AuthSource: "" + ReplicaName: "" + TLS: false + MaxPoolSize: 30 + MinPoolSize: 10 + MaxConnIdleTime: 30m + +Redis: + Host: localhost:6379 + Type: node + +Notification: + DefaultLocale: zh-tw + Email: + Provider: mock + From: noreply@example.com + SMTP: + Enable: false + Sort: 1 + Host: localhost + Port: 1025 + Username: "" + Password: "" + SES: + Enable: false + Sort: 2 + Region: ap-northeast-1 + AccessKey: "" + SecretKey: "" + SessionToken: "" + SMS: + Provider: mock + Mitake: + Enable: false + Sort: 1 + User: "" + Password: "" + Async: + QueueRedisKey: notification:queue + Worker: 2 + MaxRetry: 5 + BackoffSeconds: [1, 5, 30, 300, 1800] + RatePerTenant: + Email: 100 + SMS: 50 + +Member: + OTP: + Length: 6 + TTLSeconds: 300 + MaxAttempts: 5 + ResendCooldownSeconds: 60 + DailyVerifyLimit: 10 diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 58aec89..2963966 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -31,14 +31,14 @@ func TestLoadGatewayYAML_default(t *testing.T) { func TestLoadGatewayYAML_dev(t *testing.T) { t.Parallel() var c config.Config - path := filepath.Join(repoRoot(t), "etc", "gateway.dev.yaml") + path := filepath.Join(repoRoot(t), "etc", "gateway.dev.example.yaml") if err := conf.Load(path, &c); err != nil { t.Fatal(err) } if c.Mongo.Host == "" { - t.Fatal("Mongo.Host should be set in gateway.dev.yaml") + t.Fatal("Mongo.Host should be set in gateway.dev.example.yaml") } if c.Redis.Host == "" { - t.Fatal("Redis.Host should be set in gateway.dev.yaml") + t.Fatal("Redis.Host should be set in gateway.dev.example.yaml") } } diff --git a/internal/model/member/config/config.go b/internal/model/member/config/config.go index 031c2c1..c86b78a 100644 --- a/internal/model/member/config/config.go +++ b/internal/model/member/config/config.go @@ -1,7 +1,7 @@ package config // Config is member module settings (embedded in gateway root config). -type 幫Config struct { +type Config struct { OTP OTPConfig `json:",optional"` }