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 <cursoragent@cursor.com>
This commit is contained in:
王性驊 2026-05-20 15:14:44 +08:00
parent 49e7099bf2
commit 35c6577ac8
8 changed files with 98 additions and 17 deletions

5
.gitignore vendored
View File

@ -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 / 編輯器

View File

@ -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: ## 啟動 Gatewayetc/gateway.yaml無需 Docker
$(GO) run gateway.go -f etc/gateway.yaml
run-dev: ## 啟動 Gatewayetc/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 ## 啟動 Gatewayetc/gateway.dev.yaml需 make deps-up
$(GO) run gateway.go -f etc/gateway.dev.yaml
run-local: run-dev ## 別名:同 run-dev

View File

@ -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()

View File

@ -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` |

View File

@ -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
```
---

View File

@ -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

View File

@ -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")
}
}

View File

@ -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"`
}