|
|
@@ -11,9 +11,11 @@ import (
|
|
11
|
11
|
|
|
12
|
12
|
// Config 应用配置
|
|
13
|
13
|
type Config struct {
|
|
14
|
|
- Database DBConfig `yaml:"database"`
|
|
15
|
|
- Auth Auth `yaml:"auth"`
|
|
16
|
|
- Service Service `yaml:"service"`
|
|
|
14
|
+ Database DBConfig `yaml:"database"`
|
|
|
15
|
+ Redis RedisConfig `yaml:"redis"`
|
|
|
16
|
+ Doris DorisConfig `yaml:"doris"`
|
|
|
17
|
+ Auth Auth `yaml:"auth"`
|
|
|
18
|
+ Service Service `yaml:"service"`
|
|
17
|
19
|
}
|
|
18
|
20
|
|
|
19
|
21
|
// DBConfig 数据库配置
|
|
|
@@ -29,6 +31,44 @@ type DBConfig struct {
|
|
29
|
31
|
ConnMaxLifetime int `yaml:"conn_max_lifetime"` // 单位:秒
|
|
30
|
32
|
}
|
|
31
|
33
|
|
|
|
34
|
+// RedisConfig Redis配置
|
|
|
35
|
+type RedisConfig struct {
|
|
|
36
|
+ Host string `yaml:"host"`
|
|
|
37
|
+ Port int `yaml:"port"`
|
|
|
38
|
+ Password string `yaml:"password"`
|
|
|
39
|
+ DB int `yaml:"db"`
|
|
|
40
|
+ PoolSize int `yaml:"pool_size"`
|
|
|
41
|
+ // 连接超时和读写超时(秒)
|
|
|
42
|
+ DialTimeout int `yaml:"dial_timeout"`
|
|
|
43
|
+ ReadTimeout int `yaml:"read_timeout"`
|
|
|
44
|
+ WriteTimeout int `yaml:"write_timeout"`
|
|
|
45
|
+ // 连接池配置
|
|
|
46
|
+ IdleTimeout int `yaml:"idle_timeout"` // 空闲连接超时(秒)
|
|
|
47
|
+ MaxConnAge int `yaml:"max_conn_age"` // 连接最大存活时间(秒)
|
|
|
48
|
+}
|
|
|
49
|
+
|
|
|
50
|
+// DorisConfig Doris配置
|
|
|
51
|
+type DorisConfig struct {
|
|
|
52
|
+ // FE节点配置
|
|
|
53
|
+ FEHost string `yaml:"fe_host"`
|
|
|
54
|
+ FEPort int `yaml:"fe_port"`
|
|
|
55
|
+ FEUsername string `yaml:"fe_username"`
|
|
|
56
|
+ FEPassword string `yaml:"fe_password"`
|
|
|
57
|
+
|
|
|
58
|
+ // MySQL协议配置
|
|
|
59
|
+ MySQLHost string `yaml:"mysql_host"`
|
|
|
60
|
+ MySQLPort int `yaml:"mysql_port"`
|
|
|
61
|
+
|
|
|
62
|
+ // 连接池配置
|
|
|
63
|
+ MaxOpenConns int `yaml:"max_open_conns"`
|
|
|
64
|
+ MaxIdleConns int `yaml:"max_idle_conns"`
|
|
|
65
|
+ ConnMaxLifetime int `yaml:"conn_max_lifetime"` // 单位:秒
|
|
|
66
|
+
|
|
|
67
|
+ // Stream Load配置
|
|
|
68
|
+ StreamLoadTimeout int `yaml:"stream_load_timeout"` // 秒
|
|
|
69
|
+ BatchSize int `yaml:"batch_size"` // 批量大小
|
|
|
70
|
+}
|
|
|
71
|
+
|
|
32
|
72
|
// Auth 认证配置
|
|
33
|
73
|
type Auth struct {
|
|
34
|
74
|
Token string `yaml:"token"`
|
|
|
@@ -36,6 +76,7 @@ type Auth struct {
|
|
36
|
76
|
|
|
37
|
77
|
// Service 微服务配置
|
|
38
|
78
|
type Service struct {
|
|
|
79
|
+ ServiceName string `yaml:"service_name"`
|
|
39
|
80
|
Port int `yaml:"port"`
|
|
40
|
81
|
ReadTimeout int `yaml:"read_timeout"`
|
|
41
|
82
|
WriteTimeout int `yaml:"write_timeout"`
|
|
|
@@ -46,9 +87,13 @@ type Service struct {
|
|
46
|
87
|
// 导出接口,防止外部修改
|
|
47
|
88
|
type IConfig interface {
|
|
48
|
89
|
GetDatabase() DBConfig
|
|
|
90
|
+ GetRedis() RedisConfig
|
|
|
91
|
+ GetDoris() DorisConfig
|
|
49
|
92
|
GetAuth() Auth
|
|
50
|
93
|
GetService() Service
|
|
51
|
94
|
IsDatabaseConfigured() bool
|
|
|
95
|
+ IsRedisConfigured() bool
|
|
|
96
|
+ IsDorisConfigured() bool
|
|
52
|
97
|
}
|
|
53
|
98
|
|
|
54
|
99
|
// 实现接口的具体类型
|
|
|
@@ -60,6 +105,14 @@ func (cw *configWrapper) GetDatabase() DBConfig {
|
|
60
|
105
|
return cw.config.Database
|
|
61
|
106
|
}
|
|
62
|
107
|
|
|
|
108
|
+func (cw *configWrapper) GetRedis() RedisConfig {
|
|
|
109
|
+ return cw.config.Redis
|
|
|
110
|
+}
|
|
|
111
|
+
|
|
|
112
|
+func (cw *configWrapper) GetDoris() DorisConfig {
|
|
|
113
|
+ return cw.config.Doris
|
|
|
114
|
+}
|
|
|
115
|
+
|
|
63
|
116
|
func (cw *configWrapper) GetAuth() Auth {
|
|
64
|
117
|
return cw.config.Auth
|
|
65
|
118
|
}
|
|
|
@@ -69,11 +122,23 @@ func (cw *configWrapper) GetService() Service {
|
|
69
|
122
|
}
|
|
70
|
123
|
|
|
71
|
124
|
func (cw *configWrapper) IsDatabaseConfigured() bool {
|
|
72
|
|
- return cw.config.Database.Type != "" &&
|
|
73
|
|
- cw.config.Database.Host != "" &&
|
|
74
|
|
- cw.config.Database.Port > 0 &&
|
|
75
|
|
- cw.config.Database.Username != "" &&
|
|
76
|
|
- cw.config.Database.Database != ""
|
|
|
125
|
+ db := cw.config.Database
|
|
|
126
|
+ return db.Type != "" &&
|
|
|
127
|
+ db.Host != "" &&
|
|
|
128
|
+ db.Port > 0 &&
|
|
|
129
|
+ db.Username != "" &&
|
|
|
130
|
+ db.Database != ""
|
|
|
131
|
+}
|
|
|
132
|
+
|
|
|
133
|
+func (cw *configWrapper) IsRedisConfigured() bool {
|
|
|
134
|
+ redis := cw.config.Redis
|
|
|
135
|
+ return redis.Host != "" && redis.Port > 0
|
|
|
136
|
+}
|
|
|
137
|
+
|
|
|
138
|
+func (cw *configWrapper) IsDorisConfigured() bool {
|
|
|
139
|
+ doris := cw.config.Doris
|
|
|
140
|
+ // 检查FE配置(HTTP API方式)
|
|
|
141
|
+ return doris.FEHost != "" && doris.FEPort > 0
|
|
77
|
142
|
}
|
|
78
|
143
|
|
|
79
|
144
|
func (cw *configWrapper) IsAuthConfigured() bool {
|
|
|
@@ -119,12 +184,32 @@ func loadConfig() (*Config, error) {
|
|
119
|
184
|
// 先创建带默认值的配置
|
|
120
|
185
|
config := &Config{
|
|
121
|
186
|
Service: Service{
|
|
|
187
|
+ ServiceName: "myService",
|
|
122
|
188
|
Port: 8080,
|
|
123
|
189
|
ReadTimeout: 30,
|
|
124
|
190
|
WriteTimeout: 30,
|
|
125
|
191
|
IdleTimeout: 60,
|
|
126
|
192
|
TrustedProxies: "",
|
|
127
|
193
|
},
|
|
|
194
|
+ Redis: RedisConfig{
|
|
|
195
|
+ Port: 6379,
|
|
|
196
|
+ DB: 0,
|
|
|
197
|
+ PoolSize: 10,
|
|
|
198
|
+ DialTimeout: 5,
|
|
|
199
|
+ ReadTimeout: 3,
|
|
|
200
|
+ WriteTimeout: 3,
|
|
|
201
|
+ IdleTimeout: 300,
|
|
|
202
|
+ MaxConnAge: 0, // 0表示不限制
|
|
|
203
|
+ },
|
|
|
204
|
+ Doris: DorisConfig{
|
|
|
205
|
+ FEPort: 8030,
|
|
|
206
|
+ MySQLPort: 9030,
|
|
|
207
|
+ MaxOpenConns: 20,
|
|
|
208
|
+ MaxIdleConns: 10,
|
|
|
209
|
+ ConnMaxLifetime: 3600,
|
|
|
210
|
+ StreamLoadTimeout: 30,
|
|
|
211
|
+ BatchSize: 1000,
|
|
|
212
|
+ },
|
|
128
|
213
|
}
|
|
129
|
214
|
// 读取配置文件
|
|
130
|
215
|
data, err := os.ReadFile(configFile)
|