diff --git a/config/config.go b/config/config.go index de4ac21..a8f4854 100644 --- a/config/config.go +++ b/config/config.go @@ -87,12 +87,13 @@ func defaultConfig() *Config { // configPath 返回当前平台的配置文件路径 func configPath() string { if runtime.GOOS == "windows" { - // Windows: 相对于可执行文件的 conf/config.toml - exePath, err := os.Executable() + // Windows: 相对于工作目录的 conf/config.toml + // 注意: 使用工作目录而非 os.Executable(),因为 go run 时 exe 在临时目录 + wd, err := os.Getwd() if err != nil { return "conf/config.toml" } - return filepath.Join(filepath.Dir(exePath), "conf", "config.toml") + return filepath.Join(wd, "conf", "config.toml") } // Linux: FHS 标准 /etc/portal_page/config.toml return "/etc/portal_page/config.toml"