coo7 commited on
Commit
87f7b55
·
verified ·
1 Parent(s): 1fd6586

Create config/config.go

Browse files
Files changed (1) hide show
  1. internal/config/config.go +27 -0
internal/config/config.go ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+
6
+ "github.com/joho/godotenv"
7
+ )
8
+
9
+ var MonicaConfig *Config
10
+
11
+ // Config 存储应用配置
12
+ type Config struct {
13
+ MonicaCookie string
14
+ BearerToken string
15
+ }
16
+
17
+ // LoadConfig 从环境变量加载配置
18
+ func LoadConfig() *Config {
19
+ // 尝试加载 .env 文件,但不强制要求文件存在
20
+ _ = godotenv.Load()
21
+
22
+ MonicaConfig = &Config{
23
+ MonicaCookie: os.Getenv("MONICA_COOKIE"),
24
+ BearerToken: os.Getenv("BEARER_TOKEN"),
25
+ }
26
+ return MonicaConfig
27
+ }