diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 56531c5..e3b89ef 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "os" @@ -36,10 +37,19 @@ import ( // @description Bearer token for authentication func main() { + // 定义命令行参数 + var customPath string + flag.StringVar(&customPath, "config", "", "path to configuration file") + flag.StringVar(&customPath, "c", "", "path to configuration file (shorthand)") + flag.Parse() + // 加载配置 - configPath := "config.yaml" // Docker 环境默认路径 - if _, err := os.Stat(configPath); os.IsNotExist(err) { - configPath = "../configs/config.yaml" // 本地开发环境 + configPath := customPath + if configPath == "" { + configPath = "config.yaml" // Docker 环境默认路径 + if _, err := os.Stat(configPath); os.IsNotExist(err) { + configPath = "../configs/config.yaml" // 本地开发环境 + } } if err := config.Load(configPath); err != nil { diff --git a/backend/docs/install/dev_install.md b/backend/docs/install/dev_install.md new file mode 100644 index 0000000..e653c88 --- /dev/null +++ b/backend/docs/install/dev_install.md @@ -0,0 +1,9 @@ +## 本地开发环境 + +```bash +# 使用默认配置 +go run cmd/main.go + +# 指定配置文件 +go run . -config configs/config.dev.yaml +``` \ No newline at end of file