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:
parent
49e7099bf2
commit
35c6577ac8
|
|
@ -34,8 +34,13 @@ docs/openapi/*.json
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
# 本機開發設定(含 Port、DB、provider 帳密等,勿提交)
|
||||||
|
etc/gateway.dev.yaml
|
||||||
|
etc/gateway.private.yaml
|
||||||
etc/*-local.yaml
|
etc/*-local.yaml
|
||||||
etc/*.local.yaml
|
etc/*.local.yaml
|
||||||
|
# 可提交的範例檔
|
||||||
|
!etc/gateway.dev.example.yaml
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# IDE / 編輯器
|
# IDE / 編輯器
|
||||||
|
|
|
||||||
8
Makefile
8
Makefile
|
|
@ -16,7 +16,7 @@ GOLANGCI_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
|
||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
|
|
||||||
.PHONY: help tools gen-api gen-mock build-go-doc gen-doc test fmt lint lint-fix fix check run \
|
.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: ## 顯示可用指令
|
help: ## 顯示可用指令
|
||||||
@echo "Gateway Makefile"
|
@echo "Gateway Makefile"
|
||||||
|
|
@ -75,7 +75,11 @@ check: fix test ## 提交 / PR 前完整檢查(fmt、lint、test)
|
||||||
run: ## 啟動 Gateway(etc/gateway.yaml,無需 Docker)
|
run: ## 啟動 Gateway(etc/gateway.yaml,無需 Docker)
|
||||||
$(GO) run gateway.go -f etc/gateway.yaml
|
$(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
|
$(GO) run gateway.go -f etc/gateway.dev.yaml
|
||||||
|
|
||||||
run-local: run-dev ## 別名:同 run-dev
|
run-local: run-dev ## 別名:同 run-dev
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
"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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
|
||||||
|
|
@ -53,4 +53,5 @@ make mongo-index # 手動建立/補齊索引
|
||||||
| 檔案 | 用途 |
|
| 檔案 | 用途 |
|
||||||
|------|------|
|
|------|------|
|
||||||
| [`etc/gateway.yaml`](../etc/gateway.yaml) | 預設,無需 Docker |
|
| [`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`) |
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,23 @@ Gateway 使用 [go-zero `conf`](https://go-zero.dev/docs/tutorials/go-zero/confi
|
||||||
|
|
||||||
## 用哪個檔案?
|
## 用哪個檔案?
|
||||||
|
|
||||||
| 檔案 | 用途 | 啟動方式 |
|
| 檔案 | 是否提交 git | 用途 |
|
||||||
|------|------|----------|
|
|------|:------------:|------|
|
||||||
| **`gateway.yaml`** | 預設:不需 Docker,僅 HTTP / health | `make run` |
|
| **`gateway.yaml`** | ✅ | 預設:不需 Docker,僅 health |
|
||||||
| **`gateway.dev.yaml`** | 本機完整功能(Mongo + Redis + Notification) | `make deps-up` 後 `make run-dev` |
|
| **`gateway.dev.example.yaml`** | ✅ | 本機完整功能範例(無真實帳密) |
|
||||||
|
| **`gateway.dev.yaml`** | ❌ **勿提交** | 你的本機設定(Port、DB、SMTP/SES/三竹帳密) |
|
||||||
|
|
||||||
```bash
|
```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 deps-up
|
||||||
make mongo-index # 首次建議執行
|
make mongo-index
|
||||||
make run-dev
|
make run-dev # 會自動 setup-dev(缺檔時從 example 複製)
|
||||||
|
|
||||||
|
# 僅 API(不需 gateway.dev.yaml)
|
||||||
|
make run
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -31,14 +31,14 @@ func TestLoadGatewayYAML_default(t *testing.T) {
|
||||||
func TestLoadGatewayYAML_dev(t *testing.T) {
|
func TestLoadGatewayYAML_dev(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
var c config.Config
|
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 {
|
if err := conf.Load(path, &c); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if c.Mongo.Host == "" {
|
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 == "" {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
// Config is member module settings (embedded in gateway root config).
|
// Config is member module settings (embedded in gateway root config).
|
||||||
type 幫Config struct {
|
type Config struct {
|
||||||
OTP OTPConfig `json:",optional"`
|
OTP OTPConfig `json:",optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue