Преглед на файлове

添加redis,doris配置

qdy преди 3 месеца
родител
ревизия
f8ead302b2
променени са 1 файла, в които са добавени 93 реда и са изтрити 8 реда
  1. 93
    8
      config/config.go

+ 93
- 8
config/config.go Целия файл

11
 
11
 
12
 // Config 应用配置
12
 // Config 应用配置
13
 type Config struct {
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
 // DBConfig 数据库配置
21
 // DBConfig 数据库配置
29
 	ConnMaxLifetime int    `yaml:"conn_max_lifetime"` // 单位:秒
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
 // Auth 认证配置
72
 // Auth 认证配置
33
 type Auth struct {
73
 type Auth struct {
34
 	Token string `yaml:"token"`
74
 	Token string `yaml:"token"`
36
 
76
 
37
 // Service 微服务配置
77
 // Service 微服务配置
38
 type Service struct {
78
 type Service struct {
79
+	ServiceName    string `yaml:"service_name"`
39
 	Port           int    `yaml:"port"`
80
 	Port           int    `yaml:"port"`
40
 	ReadTimeout    int    `yaml:"read_timeout"`
81
 	ReadTimeout    int    `yaml:"read_timeout"`
41
 	WriteTimeout   int    `yaml:"write_timeout"`
82
 	WriteTimeout   int    `yaml:"write_timeout"`
46
 // 导出接口,防止外部修改
87
 // 导出接口,防止外部修改
47
 type IConfig interface {
88
 type IConfig interface {
48
 	GetDatabase() DBConfig
89
 	GetDatabase() DBConfig
90
+	GetRedis() RedisConfig
91
+	GetDoris() DorisConfig
49
 	GetAuth() Auth
92
 	GetAuth() Auth
50
 	GetService() Service
93
 	GetService() Service
51
 	IsDatabaseConfigured() bool
94
 	IsDatabaseConfigured() bool
95
+	IsRedisConfigured() bool
96
+	IsDorisConfigured() bool
52
 }
97
 }
53
 
98
 
54
 // 实现接口的具体类型
99
 // 实现接口的具体类型
60
 	return cw.config.Database
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
 func (cw *configWrapper) GetAuth() Auth {
116
 func (cw *configWrapper) GetAuth() Auth {
64
 	return cw.config.Auth
117
 	return cw.config.Auth
65
 }
118
 }
69
 }
122
 }
70
 
123
 
71
 func (cw *configWrapper) IsDatabaseConfigured() bool {
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
 func (cw *configWrapper) IsAuthConfigured() bool {
144
 func (cw *configWrapper) IsAuthConfigured() bool {
119
 	// 先创建带默认值的配置
184
 	// 先创建带默认值的配置
120
 	config := &Config{
185
 	config := &Config{
121
 		Service: Service{
186
 		Service: Service{
187
+			ServiceName:    "myService",
122
 			Port:           8080,
188
 			Port:           8080,
123
 			ReadTimeout:    30,
189
 			ReadTimeout:    30,
124
 			WriteTimeout:   30,
190
 			WriteTimeout:   30,
125
 			IdleTimeout:    60,
191
 			IdleTimeout:    60,
126
 			TrustedProxies: "",
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
 	data, err := os.ReadFile(configFile)
215
 	data, err := os.ReadFile(configFile)

Loading…
Отказ
Запис