fix: environment variable loading with godotenv (v0.0.3)
- Add godotenv dependency for .env file loading - Update main.go to load environment variables - Update memory.md with troubleshooting notes - Test basic CLI functionality Version: 0.0.3
This commit is contained in:
25
memory.md
25
memory.md
@@ -92,6 +92,31 @@
|
||||
|
||||
---
|
||||
|
||||
### 环境变量加载问题
|
||||
**问题**: 配置文件中的环境变量没有正确加载
|
||||
**原因**: Go程序不会自动加载.env文件,需要使用第三方库
|
||||
**解决方案**:
|
||||
1. 使用`github.com/joho/godotenv`包
|
||||
2. 在程序启动时调用`godotenv.Load()`
|
||||
3. 将.env文件添加到.gitignore
|
||||
|
||||
**代码示例**:
|
||||
```go
|
||||
import "github.com/joho/godotenv"
|
||||
|
||||
func main() {
|
||||
_ = godotenv.Load() // 加载.env文件
|
||||
// 然后加载配置文件
|
||||
}
|
||||
```
|
||||
|
||||
**注意事项**:
|
||||
- 不要提交真实的.env文件到版本控制
|
||||
- 提供.env.example模板
|
||||
- 在文档中说明环境变量配置方法
|
||||
|
||||
---
|
||||
|
||||
## 配置最佳实践
|
||||
|
||||
### 安全配置
|
||||
|
||||
Reference in New Issue
Block a user