✨Feat: 从.env文件中加载变量

This commit is contained in:
2026-03-22 20:54:09 +08:00
parent 295938c916
commit 81b8933c83
3 changed files with 30 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
func init() {
err := godotenv.Load()
if err != nil {
fmt.Println(".env 文件加载失败")
}
apiKey := os.Getenv("API_KEY")
baseUrl := os.Getenv("BASE_URL")
fmt.Printf("API Key: %s\n", apiKey)
fmt.Printf("Base URL: %s\n", baseUrl)
}
func main() {
}