Browse Source

拆开配置文件

qdy 2 months ago
parent
commit
2bbea15215

+ 87
- 375
config/config.go View File

@@ -1,428 +1,140 @@
1 1
 package config
2 2
 
3 3
 import (
4
-	"fmt"
5
-	"os"
6
-	"path/filepath"
7 4
 	"sync"
8 5
 
9
-	"gopkg.in/yaml.v2"
6
+	"git.x2erp.com/qdy/go-base/config/subconfigs"
10 7
 )
11 8
 
12
-// ==================== 配置结构体定义 ====================
13
-
14
-// Config 应用配置
15
-type Config struct {
16
-	Database DBConfig       `yaml:"database"`
17
-	Redis    RedisConfig    `yaml:"redis"`
18
-	Doris    DorisConfig    `yaml:"doris"`
19
-	RabbitMQ RabbitMQConfig `yaml:"rabbitmq"`
20
-	Auth     Auth           `yaml:"auth"`
21
-	Service  Service        `yaml:"service"`
22
-	HTTP     HTTPConfig     `yaml:"http"`
23
-	Micro    MicroConfig    `yaml:"micro"` // Go Micro配置
24
-}
25
-
26
-// ==================== 各个组件的配置结构 ====================
27
-
28
-// RabbitMQConfig RabbitMQ配置
29
-type RabbitMQConfig struct {
30
-	Host                 string `yaml:"host"`
31
-	Port                 int    `yaml:"port"`
32
-	Username             string `yaml:"username"`
33
-	Password             string `yaml:"password"`
34
-	Vhost                string `yaml:"vhost"`
35
-	UseTLS               bool   `yaml:"use_tls"`
36
-	CACert               string `yaml:"ca_cert"`
37
-	CertFile             string `yaml:"cert_file"`
38
-	KeyFile              string `yaml:"key_file"`
39
-	MaxOpenChannels      int    `yaml:"max_open_channels"`
40
-	ReconnectDelay       int    `yaml:"reconnect_delay"`
41
-	MaxReconnectAttempts int    `yaml:"max_reconnect_attempts"`
42
-	Heartbeat            int    `yaml:"heartbeat"`
43
-	ChannelSize          int    `yaml:"channel_size"`
44
-	DefaultExchange      string `yaml:"default_exchange"`
45
-	DefaultQueue         string `yaml:"default_queue"`
46
-	AutoAck              bool   `yaml:"auto_ack"`
47
-	Mandatory            bool   `yaml:"mandatory"`
48
-	Immediate            bool   `yaml:"immediate"`
49
-	PrefetchCount        int    `yaml:"prefetch_count"`
50
-	PrefetchSize         int    `yaml:"prefetch_size"`
51
-	Global               bool   `yaml:"global"`
52
-	PublisherConfirms    bool   `yaml:"publisher_confirms"`
53
-	ConfirmTimeout       int    `yaml:"confirm_timeout"`
54
-}
55
-
56
-// HTTPConfig HTTP客户端配置
57
-type HTTPConfig struct {
58
-	Timeout             int  `yaml:"timeout"`
59
-	MaxIdleConns        int  `yaml:"max_idle_conns"`
60
-	MaxIdleConnsPerHost int  `yaml:"max_idle_conns_per_host"`
61
-	IdleConnTimeout     int  `yaml:"idle_conn_timeout"`
62
-	MaxConnsPerHost     int  `yaml:"max_conns_per_host"`
63
-	DisableCompression  bool `yaml:"disable_compression"`
64
-	DisableKeepAlives   bool `yaml:"disable_keep_alives"`
65
-}
66
-
67
-// DBConfig 数据库配置
68
-type DBConfig struct {
69
-	Type            string `yaml:"type"`
70
-	Host            string `yaml:"host"`
71
-	Port            int    `yaml:"port"`
72
-	Username        string `yaml:"username"`
73
-	Password        string `yaml:"password"`
74
-	Database        string `yaml:"database"`
75
-	MaxOpenConns    int    `yaml:"max_open_conns"`
76
-	MaxIdleConns    int    `yaml:"max_idle_conns"`
77
-	ConnMaxLifetime int    `yaml:"conn_max_lifetime"`
78
-}
79
-
80
-// RedisConfig Redis配置
81
-type RedisConfig struct {
82
-	Host         string `yaml:"host"`
83
-	Port         int    `yaml:"port"`
84
-	Password     string `yaml:"password"`
85
-	DB           int    `yaml:"db"`
86
-	PoolSize     int    `yaml:"pool_size"`
87
-	DialTimeout  int    `yaml:"dial_timeout"`
88
-	ReadTimeout  int    `yaml:"read_timeout"`
89
-	WriteTimeout int    `yaml:"write_timeout"`
90
-	IdleTimeout  int    `yaml:"idle_timeout"`
91
-	MaxConnAge   int    `yaml:"max_conn_age"`
92
-}
93
-
94
-// DorisConfig Doris配置
95
-type DorisConfig struct {
96
-	FEHost            string `yaml:"fe_host"`
97
-	FEPort            int    `yaml:"fe_port"`
98
-	FEUsername        string `yaml:"fe_username"`
99
-	FEPassword        string `yaml:"fe_password"`
100
-	MySQLHost         string `yaml:"mysql_host"`
101
-	MySQLPort         int    `yaml:"mysql_port"`
102
-	MaxOpenConns      int    `yaml:"max_open_conns"`
103
-	MaxIdleConns      int    `yaml:"max_idle_conns"`
104
-	ConnMaxLifetime   int    `yaml:"conn_max_lifetime"`
105
-	StreamLoadTimeout int    `yaml:"stream_load_timeout"`
106
-	BatchSize         int    `yaml:"batch_size"`
107
-}
108
-
109
-// Auth 认证配置
110
-type Auth struct {
111
-	Token string `yaml:"token"`
112
-}
113
-
114
-// Service 微服务配置
115
-type Service struct {
116
-	ServiceName    string `yaml:"service_name"`
117
-	ServiceVersion string `yaml:"service_version"`
118
-	ServiceTag     string `yaml:"service_tags"`
119
-	Port           int    `yaml:"port"`
120
-	ReadTimeout    int    `yaml:"read_timeout"`
121
-	WriteTimeout   int    `yaml:"write_timeout"`
122
-	IdleTimeout    int    `yaml:"idle_timeout"`
123
-	TrustedProxies string `yaml:"trusted_proxies"`
124
-}
125
-
126
-// MicroConfig Go Micro微服务配置
127
-type MicroConfig struct {
128
-	RegistryAddress string `yaml:"registry_address"`
129
-	RegistryType    string `yaml:"registry_type"`
130
-	RegistryTimeout int    `yaml:"registry_timeout"`
131
-	LBStrategy      string `yaml:"lb_strategy"`
132
-	LBCacheTTL      int    `yaml:"lb_cache_ttl"`
133
-	LBRetries       int    `yaml:"lb_retries"`
134
-	ClientTimeout   int    `yaml:"client_timeout"`
135
-	ClientPoolSize  int    `yaml:"client_pool_size"`
136
-	MaxRetries      int    `yaml:"max_retries"`
137
-	CircuitEnabled  bool   `yaml:"circuit_enabled"`
138
-	CircuitTimeout  int    `yaml:"circuit_timeout"`
139
-	ErrorThreshold  int    `yaml:"error_threshold"`
140
-	SleepWindow     int    `yaml:"sleep_window"`
141
-	HealthPath      string `yaml:"health_path"`
142
-	HealthInterval  int    `yaml:"health_interval"`
143
-	HealthTimeout   int    `yaml:"health_timeout"`
144
-	LogLevel        string `yaml:"log_level"`
145
-	EnableDebug     bool   `yaml:"enable_debug"`
146
-	MetricsEnabled  bool   `yaml:"metrics_enabled"`
147
-	MetricsAddress  string `yaml:"metrics_address"`
148
-	TracerEnabled   bool   `yaml:"tracer_enabled"`
149
-	TracerAddress   string `yaml:"tracer_address"`
150
-}
151
-
152
-// ==================== 配置接口定义 ====================
153
-
154
-// IConfig 配置接口
9
+// IConfig 主配置接口
155 10
 type IConfig interface {
156
-	GetDatabase() DBConfig
157
-	GetRedis() RedisConfig
158
-	GetDoris() DorisConfig
159
-	GetRabbitMQ() RabbitMQConfig
160
-	GetAuth() Auth
161
-	GetService() Service
162
-	GetHTTP() HTTPConfig
163
-	GetMicro() MicroConfig
164
-
11
+	GetDatabase() *subconfigs.DatabaseConfig
12
+	GetRedis() *subconfigs.RedisConfig
13
+	GetDoris() *subconfigs.DorisConfig
14
+	GetRabbitMQ() *subconfigs.RabbitMQConfig
15
+	GetAuth() *subconfigs.AuthConfig
16
+	GetService() *subconfigs.ServiceConfig
17
+	GetHTTP() *subconfigs.HTTPConfig
18
+	GetMicro() *subconfigs.MicroConfig
19
+	GetLog() *subconfigs.LogConfig
20
+	GetInitError() error
165 21
 	IsDatabaseConfigured() bool
166
-	IsRedisConfigured() bool
167 22
 	IsDorisConfigured() bool
168
-	IsRabbitMQConfigured() bool
169
-	IsHTTPConfigured() bool
170
-	IsAuthConfigured() bool
171
-	IsMicroConfigured() bool
172
-}
173
-
174
-// configWrapper 配置包装器
175
-type configWrapper struct {
176
-	config *Config
177
-}
178
-
179
-// ==================== 接口实现 ====================
180
-
181
-func (cw *configWrapper) GetDatabase() DBConfig {
182
-	return cw.config.Database
183
-}
184
-
185
-func (cw *configWrapper) GetRedis() RedisConfig {
186
-	return cw.config.Redis
187
-}
188
-
189
-func (cw *configWrapper) GetDoris() DorisConfig {
190
-	return cw.config.Doris
191
-}
192
-
193
-func (cw *configWrapper) GetRabbitMQ() RabbitMQConfig {
194
-	return cw.config.RabbitMQ
23
+	IsRedisConfigured() bool
195 24
 }
196 25
 
197
-func (cw *configWrapper) GetAuth() Auth {
198
-	return cw.config.Auth
26
+// Config 主配置结构体 - 访问门面
27
+type Config struct {
28
+	initError error // 初始化错误
199 29
 }
200 30
 
201
-func (cw *configWrapper) GetService() Service {
202
-	return cw.config.Service
31
+// 实现IConfig接口 - 从注册表获取配置
32
+func (c *Config) GetDatabase() *subconfigs.DatabaseConfig {
33
+	if config := subconfigs.GetRegisteredConfig("database"); config != nil {
34
+		return config.(*subconfigs.DatabaseConfig)
35
+	}
36
+	return nil
203 37
 }
204 38
 
205
-func (cw *configWrapper) GetHTTP() HTTPConfig {
206
-	return cw.config.HTTP
39
+func (c *Config) GetRedis() *subconfigs.RedisConfig {
40
+	if config := subconfigs.GetRegisteredConfig("redis"); config != nil {
41
+		return config.(*subconfigs.RedisConfig)
42
+	}
43
+	return nil
207 44
 }
208 45
 
209
-func (cw *configWrapper) GetMicro() MicroConfig {
210
-	return cw.config.Micro
46
+func (c *Config) GetDoris() *subconfigs.DorisConfig {
47
+	if config := subconfigs.GetRegisteredConfig("doris"); config != nil {
48
+		return config.(*subconfigs.DorisConfig)
49
+	}
50
+	return nil
211 51
 }
212 52
 
213
-func (cw *configWrapper) IsDatabaseConfigured() bool {
214
-	db := cw.config.Database
215
-	return db.Type != "" &&
216
-		db.Host != "" &&
217
-		db.Port > 0 &&
218
-		db.Username != "" &&
219
-		db.Database != ""
53
+func (c *Config) GetRabbitMQ() *subconfigs.RabbitMQConfig {
54
+	if config := subconfigs.GetRegisteredConfig("rabbitmq"); config != nil {
55
+		return config.(*subconfigs.RabbitMQConfig)
56
+	}
57
+	return nil
220 58
 }
221 59
 
222
-func (cw *configWrapper) IsRedisConfigured() bool {
223
-	redis := cw.config.Redis
224
-	return redis.Host != "" && redis.Port > 0
60
+func (c *Config) GetAuth() *subconfigs.AuthConfig {
61
+	if config := subconfigs.GetRegisteredConfig("auth"); config != nil {
62
+		return config.(*subconfigs.AuthConfig)
63
+	}
64
+	return nil
225 65
 }
226 66
 
227
-func (cw *configWrapper) IsDorisConfigured() bool {
228
-	doris := cw.config.Doris
229
-	return doris.FEHost != "" && doris.FEPort > 0
67
+func (c *Config) GetService() *subconfigs.ServiceConfig {
68
+	if config := subconfigs.GetRegisteredConfig("service"); config != nil {
69
+		return config.(*subconfigs.ServiceConfig)
70
+	}
71
+	return nil
230 72
 }
231 73
 
232
-func (cw *configWrapper) IsRabbitMQConfigured() bool {
233
-	rabbit := cw.config.RabbitMQ
234
-	return rabbit.Host != "" && rabbit.Port > 0
74
+func (c *Config) GetHTTP() *subconfigs.HTTPConfig {
75
+	if config := subconfigs.GetRegisteredConfig("http"); config != nil {
76
+		return config.(*subconfigs.HTTPConfig)
77
+	}
78
+	return nil
235 79
 }
236 80
 
237
-func (cw *configWrapper) IsHTTPConfigured() bool {
238
-	httpCfg := cw.config.HTTP
239
-	return httpCfg.Timeout > 0
81
+func (c *Config) GetMicro() *subconfigs.MicroConfig {
82
+	if config := subconfigs.GetRegisteredConfig("micro"); config != nil {
83
+		return config.(*subconfigs.MicroConfig)
84
+	}
85
+	return nil
240 86
 }
241 87
 
242
-func (cw *configWrapper) IsAuthConfigured() bool {
243
-	return cw.config.Auth.Token != ""
88
+func (c *Config) GetLog() *subconfigs.LogConfig {
89
+	if config := subconfigs.GetRegisteredConfig("log"); config != nil {
90
+		return config.(*subconfigs.LogConfig)
91
+	}
92
+	return nil
244 93
 }
245 94
 
246
-func (cw *configWrapper) IsMicroConfigured() bool {
247
-	micro := cw.config.Micro
248
-	return micro.RegistryAddress != ""
95
+func (c *Config) GetInitError() error {
96
+	return c.initError
249 97
 }
250 98
 
251
-// ==================== 单例和全局变量 ====================
252
-
253 99
 var (
254
-	instance IConfig
255
-	once     sync.Once
256
-	initErr  error
100
+	cfgInstance *Config
101
+	once        sync.Once
257 102
 )
258 103
 
259
-// GetConfig 获取配置单例实例
104
+// GetConfig 获取主配置(单例模式)
260 105
 func GetConfig() IConfig {
261 106
 	once.Do(func() {
262
-		config, err := loadConfig()
263
-		if err != nil {
264
-			initErr = err
265
-			instance = &configWrapper{config: &Config{}}
266
-			return
267
-		}
268
-		instance = &configWrapper{config: config}
107
+		cfgInstance = &Config{}
108
+		cfgInstance.initError = LoadConfig() // 加载配置到注册表
269 109
 	})
270
-	return instance
110
+	return cfgInstance
271 111
 }
272 112
 
273
-// GetInitError 获取初始化错误(如果有)
113
+// GetInitError 包级函数 - 兼容现有代码调用
274 114
 func GetInitError() error {
275
-	return initErr
115
+	return cfgInstance.GetInitError()
276 116
 }
277 117
 
278
-// ==================== 配置文件加载 ====================
279
-
280
-// loadConfig 加载配置文件(整合所有默认值)
281
-func loadConfig() (*Config, error) {
282
-	configFile, err := findConfigFile()
283
-	if err != nil {
284
-		return nil, err
285
-	}
286
-
287
-	fmt.Printf("✅ Using config file: %s\n", configFile)
288
-
289
-	// 创建带默认值的配置
290
-	config := &Config{
291
-		Service: Service{
292
-			ServiceName:    "myService",
293
-			Port:           8080,
294
-			ReadTimeout:    30,
295
-			WriteTimeout:   30,
296
-			IdleTimeout:    60,
297
-			TrustedProxies: "",
298
-		},
299
-		Redis: RedisConfig{
300
-			Port:         6379,
301
-			DB:           0,
302
-			PoolSize:     10,
303
-			DialTimeout:  5,
304
-			ReadTimeout:  3,
305
-			WriteTimeout: 3,
306
-			IdleTimeout:  300,
307
-			MaxConnAge:   0,
308
-		},
309
-		Doris: DorisConfig{
310
-			FEPort:            8030,
311
-			MySQLPort:         9030,
312
-			MaxOpenConns:      20,
313
-			MaxIdleConns:      10,
314
-			ConnMaxLifetime:   3600,
315
-			StreamLoadTimeout: 30,
316
-			BatchSize:         1000,
317
-		},
318
-		HTTP: HTTPConfig{
319
-			Timeout:             30,
320
-			MaxIdleConns:        100,
321
-			MaxIdleConnsPerHost: 10,
322
-			IdleConnTimeout:     90,
323
-			MaxConnsPerHost:     0,
324
-			DisableCompression:  false,
325
-			DisableKeepAlives:   false,
326
-		},
327
-		RabbitMQ: RabbitMQConfig{
328
-			Port:                 5672,
329
-			Username:             "guest",
330
-			Password:             "guest",
331
-			Vhost:                "/",
332
-			UseTLS:               false,
333
-			MaxOpenChannels:      10,
334
-			ReconnectDelay:       5000,
335
-			MaxReconnectAttempts: 10,
336
-			Heartbeat:            30,
337
-			ChannelSize:          100,
338
-			DefaultExchange:      "amq.direct",
339
-			DefaultQueue:         "",
340
-			AutoAck:              false,
341
-			Mandatory:            false,
342
-			Immediate:            false,
343
-			PrefetchCount:        1,
344
-			PrefetchSize:         0,
345
-			Global:               false,
346
-			PublisherConfirms:    false,
347
-			ConfirmTimeout:       30,
348
-		},
349
-		Micro: MicroConfig{
350
-			RegistryAddress: "localhost:8500",
351
-			RegistryType:    "consul",
352
-			RegistryTimeout: 10,
353
-			LBStrategy:      "roundrobin",
354
-			LBCacheTTL:      30,
355
-			LBRetries:       3,
356
-			ClientTimeout:   30,
357
-			ClientPoolSize:  100,
358
-			MaxRetries:      3,
359
-			CircuitEnabled:  true,
360
-			CircuitTimeout:  60,
361
-			ErrorThreshold:  5,
362
-			SleepWindow:     5000,
363
-			HealthPath:      "/health",
364
-			HealthInterval:  10,
365
-			HealthTimeout:   5,
366
-			LogLevel:        "info",
367
-			EnableDebug:     false,
368
-			MetricsEnabled:  true,
369
-			MetricsAddress:  ":9090",
370
-			TracerEnabled:   false,
371
-			TracerAddress:   "localhost:6831",
372
-		},
373
-	}
374
-
375
-	// 读取并解析配置文件
376
-	data, err := os.ReadFile(configFile)
377
-	if err != nil {
378
-		return nil, fmt.Errorf("failed to read config file %s: %v", configFile, err)
379
-	}
380
-
381
-	err = yaml.Unmarshal(data, &config)
382
-	if err != nil {
383
-		return nil, fmt.Errorf("failed to parse config file: %v", err)
384
-	}
385
-
386
-	return config, nil
118
+// GetConfigWithError 新方法 - 同时获取配置和错误
119
+func GetConfigWithError() (IConfig, error) {
120
+	cfg := GetConfig()
121
+	return cfg, cfg.GetInitError()
387 122
 }
388 123
 
389
-// findConfigFile 查找配置文件路径
390
-func findConfigFile() (string, error) {
391
-	// 1. 可执行文件同目录
392
-	exePath, err := os.Executable()
393
-	if err == nil {
394
-		exeDir := filepath.Dir(exePath)
395
-		configFile := filepath.Join(exeDir, "db.yaml")
396
-		if _, err := os.Stat(configFile); err == nil {
397
-			return configFile, nil
398
-		}
399
-	}
400
-
401
-	// 2. 环境变量指定路径
402
-	envConfigPath := os.Getenv("DB_CONFIG_PATH")
403
-	if envConfigPath != "" {
404
-		if _, err := os.Stat(envConfigPath); err == nil {
405
-			return envConfigPath, nil
406
-		}
407
-		return "", fmt.Errorf("DB_CONFIG_PATH file not found: %s", envConfigPath)
408
-	}
124
+// 实现 IConfig 接口的 IsDatabaseConfigured 方法
125
+func (c *Config) IsDatabaseConfigured() bool {
409 126
 
410
-	// 3. 未找到配置文件
411
-	exeDir := "unknown"
412
-	if exePath, err := os.Executable(); err == nil {
413
-		exeDir = filepath.Dir(exePath)
414
-	}
127
+	return c.GetDatabase().IsConfigured()
128
+}
415 129
 
416
-	return "", fmt.Errorf(`no configuration file found!
130
+// 实现 IConfig 接口的 IsDorisConfigured 方法
131
+func (c *Config) IsDorisConfigured() bool {
417 132
 
418
-Tried locations:
419
-1. Executable directory: %s/db.yaml
420
-2. Environment variable: DB_CONFIG_PATH
133
+	return c.GetDoris().IsConfigured()
134
+}
421 135
 
422
-Solutions:
423
-- Place db.yaml in the same directory as the executable  
424
-- Or set DB_CONFIG_PATH environment variable to config file path
136
+// 实现 IConfig 接口的 IsDorisConfigured 方法
137
+func (c *Config) IsRedisConfigured() bool {
425 138
 
426
-Example:
427
-  export DB_CONFIG_PATH=/path/to/your/db.yaml`, exeDir)
139
+	return c.GetRedis().IsConfigured()
428 140
 }

+ 94
- 0
config/loader.go View File

@@ -0,0 +1,94 @@
1
+package config
2
+
3
+import (
4
+	"fmt"
5
+	"os"
6
+	"path/filepath"
7
+
8
+	"git.x2erp.com/qdy/go-base/config/subconfigs"
9
+	"gopkg.in/yaml.v2"
10
+)
11
+
12
+// LoadConfig 加载配置到注册表
13
+func LoadConfig() error {
14
+	// 1. 设置所有注册配置的默认值
15
+	for _, config := range subconfigs.GetAllConfigs() {
16
+		config.SetDefaults()
17
+	}
18
+
19
+	// 2. 查找配置文件
20
+	configFile, err := findConfigFile()
21
+	if err != nil {
22
+		return err
23
+	}
24
+
25
+	// 3. 读取文件
26
+	data, err := os.ReadFile(configFile)
27
+	if err != nil {
28
+		return fmt.Errorf("read config file error: %v", err)
29
+	}
30
+
31
+	// 4. 解析为map
32
+	var rawConfig map[string]interface{}
33
+	err = yaml.Unmarshal(data, &rawConfig)
34
+	if err != nil {
35
+		return fmt.Errorf("parse yaml error: %v", err)
36
+	}
37
+
38
+	// 5. 循环注册表,为每个配置加载数据
39
+	for name, config := range subconfigs.GetAllConfigs() {
40
+		if configData, ok := rawConfig[name].(map[interface{}]interface{}); ok {
41
+			// 转换为 map[string]interface{}
42
+			strMap := convertMap(configData)
43
+			if err := config.Load(strMap); err != nil {
44
+				return fmt.Errorf("load config %s error: %v", name, err)
45
+			}
46
+		}
47
+	}
48
+
49
+	// // 6. 验证所有配置
50
+	// for name, config := range subconfigs.GetAllConfigs() {
51
+	// 	if err := config.Validate(); err != nil {
52
+	// 		return fmt.Errorf("validate config %s error: %v", name, err)
53
+	// 	}
54
+	// }
55
+
56
+	return nil
57
+}
58
+
59
+// convertMap 转换map类型
60
+func convertMap(input map[interface{}]interface{}) map[string]interface{} {
61
+	output := make(map[string]interface{})
62
+	for k, v := range input {
63
+		if strKey, ok := k.(string); ok {
64
+			output[strKey] = v
65
+		}
66
+	}
67
+	return output
68
+}
69
+
70
+// findConfigFile 查找配置文件
71
+func findConfigFile() (string, error) {
72
+	exePath, _ := os.Executable()
73
+	exeDir := filepath.Dir(exePath)
74
+
75
+	possiblePaths := []string{
76
+		filepath.Join(exeDir, "db.yaml"),
77
+		filepath.Join(exeDir, "config", "db.yaml"),
78
+		"db.yaml",
79
+		"config/db.yaml",
80
+		os.Getenv("DB_CONFIG_PATH"),
81
+	}
82
+
83
+	for _, path := range possiblePaths {
84
+		if path == "" {
85
+			continue
86
+		}
87
+		if _, err := os.Stat(path); err == nil {
88
+			fmt.Printf("✅ Using config file: %s\n", path)
89
+			return path, nil
90
+		}
91
+	}
92
+
93
+	return "", fmt.Errorf("no configuration file found")
94
+}

+ 28
- 0
config/subconfigs/auth_config.go View File

@@ -0,0 +1,28 @@
1
+package subconfigs
2
+
3
+// AuthConfig 认证配置
4
+type AuthConfig struct {
5
+	BaseConfig
6
+	Token string `yaml:"token"`
7
+}
8
+
9
+func NewAuthConfig() *AuthConfig {
10
+	return &AuthConfig{}
11
+}
12
+
13
+func (c *AuthConfig) SetDefaults() {
14
+	// 默认不设置token
15
+}
16
+
17
+func (c *AuthConfig) Load(data map[string]interface{}) error {
18
+	return c.LoadFromYAML(data, c)
19
+}
20
+
21
+func (c *AuthConfig) Validate() error {
22
+	// token 可以为空,有些环境不需要认证
23
+	return nil
24
+}
25
+
26
+func (c *AuthConfig) IsConfigured() bool {
27
+	return c.Token != ""
28
+}

+ 30
- 0
config/subconfigs/base.go View File

@@ -0,0 +1,30 @@
1
+package subconfigs
2
+
3
+import (
4
+	"gopkg.in/yaml.v2"
5
+)
6
+
7
+// BaseConfig 基础配置(所有子配置继承)
8
+type BaseConfig struct{}
9
+
10
+// LoadFromYAML 从YAML数据加载
11
+func (b *BaseConfig) LoadFromYAML(data map[string]interface{}, target interface{}) error {
12
+	// 转换为yaml字节
13
+	yamlBytes, err := yaml.Marshal(data)
14
+	if err != nil {
15
+		return err
16
+	}
17
+
18
+	// 解析到目标结构体
19
+	return yaml.Unmarshal(yamlBytes, target)
20
+}
21
+
22
+// GetRegisteredConfig 获取注册的配置实例(避免名称冲突)
23
+func GetRegisteredConfig(name string) ConfigLoader {
24
+	return registry[name]
25
+}
26
+
27
+// GetAllRegisteredConfigs 获取所有注册的配置
28
+func GetAllRegisteredConfigs() map[string]ConfigLoader {
29
+	return registry
30
+}

+ 54
- 0
config/subconfigs/database_config.go View File

@@ -0,0 +1,54 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// DatabaseConfig 数据库配置
6
+type DatabaseConfig struct {
7
+	BaseConfig
8
+	Type            string `yaml:"type"`
9
+	Host            string `yaml:"host"`
10
+	Port            int    `yaml:"port"`
11
+	Username        string `yaml:"username"`
12
+	Password        string `yaml:"password"`
13
+	Database        string `yaml:"database"`
14
+	MaxOpenConns    int    `yaml:"max_open_conns"`
15
+	MaxIdleConns    int    `yaml:"max_idle_conns"`
16
+	ConnMaxLifetime int    `yaml:"conn_max_lifetime"`
17
+}
18
+
19
+// NewDatabaseConfig 创建数据库配置实例
20
+func NewDatabaseConfig() *DatabaseConfig {
21
+	return &DatabaseConfig{}
22
+}
23
+
24
+// SetDefaults 设置默认值
25
+func (c *DatabaseConfig) SetDefaults() {
26
+	c.Type = "mysql"
27
+	c.Port = 3306
28
+	c.MaxOpenConns = 100
29
+	c.MaxIdleConns = 20
30
+	c.ConnMaxLifetime = 3600
31
+}
32
+
33
+// Load 从yaml数据加载
34
+func (c *DatabaseConfig) Load(data map[string]interface{}) error {
35
+	return c.LoadFromYAML(data, c)
36
+}
37
+
38
+// Validate 验证配置
39
+func (c *DatabaseConfig) Validate() error {
40
+	if c.Type == "" {
41
+		return fmt.Errorf("database type is required")
42
+	}
43
+	return nil
44
+}
45
+
46
+// IsConfigured 判断是否已配置
47
+func (c *DatabaseConfig) IsConfigured() bool {
48
+	return c.Host != "" && c.Port > 0 && c.Username != "" && c.Database != ""
49
+}
50
+
51
+// 自动注册
52
+func init() {
53
+	Register("database", &DatabaseConfig{})
54
+}

+ 53
- 0
config/subconfigs/doris_config.go View File

@@ -0,0 +1,53 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// DorisConfig Doris配置
6
+type DorisConfig struct {
7
+	BaseConfig
8
+	FEHost            string `yaml:"fe_host"`
9
+	FEPort            int    `yaml:"fe_port"`
10
+	FEUsername        string `yaml:"fe_username"`
11
+	FEPassword        string `yaml:"fe_password"`
12
+	MySQLHost         string `yaml:"mysql_host"`
13
+	MySQLPort         int    `yaml:"mysql_port"`
14
+	MaxOpenConns      int    `yaml:"max_open_conns"`
15
+	MaxIdleConns      int    `yaml:"max_idle_conns"`
16
+	ConnMaxLifetime   int    `yaml:"conn_max_lifetime"`
17
+	StreamLoadTimeout int    `yaml:"stream_load_timeout"`
18
+	BatchSize         int    `yaml:"batch_size"`
19
+}
20
+
21
+func NewDorisConfig() *DorisConfig {
22
+	return &DorisConfig{}
23
+}
24
+
25
+func (c *DorisConfig) SetDefaults() {
26
+	c.FEPort = 8030
27
+	c.MySQLPort = 9030
28
+	c.MaxOpenConns = 20
29
+	c.MaxIdleConns = 10
30
+	c.ConnMaxLifetime = 3600
31
+	c.StreamLoadTimeout = 30
32
+	c.BatchSize = 1000
33
+}
34
+
35
+func (c *DorisConfig) Load(data map[string]interface{}) error {
36
+	return c.LoadFromYAML(data, c)
37
+}
38
+
39
+func (c *DorisConfig) Validate() error {
40
+	if c.FEHost == "" && c.MySQLHost == "" {
41
+		return fmt.Errorf("at least one of fe_host or mysql_host must be configured")
42
+	}
43
+	return nil
44
+}
45
+
46
+func (c *DorisConfig) IsConfigured() bool {
47
+	return c.FEHost != "" || c.MySQLHost != ""
48
+}
49
+
50
+// 自动注册
51
+func init() {
52
+	Register("doris", &DorisConfig{})
53
+}

+ 46
- 0
config/subconfigs/http_config.go View File

@@ -0,0 +1,46 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// HTTPConfig HTTP客户端配置
6
+type HTTPConfig struct {
7
+	BaseConfig
8
+	Timeout             int  `yaml:"timeout"`
9
+	MaxIdleConns        int  `yaml:"max_idle_conns"`
10
+	MaxIdleConnsPerHost int  `yaml:"max_idle_conns_per_host"`
11
+	IdleConnTimeout     int  `yaml:"idle_conn_timeout"`
12
+	MaxConnsPerHost     int  `yaml:"max_conns_per_host"`
13
+	DisableCompression  bool `yaml:"disable_compression"`
14
+	DisableKeepAlives   bool `yaml:"disable_keep_alives"`
15
+}
16
+
17
+func NewHTTPConfig() *HTTPConfig {
18
+	return &HTTPConfig{}
19
+}
20
+
21
+func (c *HTTPConfig) SetDefaults() {
22
+	c.Timeout = 30
23
+	c.MaxIdleConns = 100
24
+	c.MaxIdleConnsPerHost = 10
25
+	c.IdleConnTimeout = 90
26
+}
27
+
28
+func (c *HTTPConfig) Load(data map[string]interface{}) error {
29
+	return c.LoadFromYAML(data, c)
30
+}
31
+
32
+func (c *HTTPConfig) Validate() error {
33
+	if c.Timeout <= 0 {
34
+		return fmt.Errorf("http timeout must be positive")
35
+	}
36
+	return nil
37
+}
38
+
39
+func (c *HTTPConfig) IsConfigured() bool {
40
+	return c.Timeout > 0
41
+}
42
+
43
+// 自动注册
44
+func init() {
45
+	Register("http", &HTTPConfig{})
46
+}

+ 71
- 0
config/subconfigs/log_config.go View File

@@ -0,0 +1,71 @@
1
+package subconfigs
2
+
3
+import (
4
+	"fmt"
5
+	"strings"
6
+)
7
+
8
+// LogConfig 日志配置
9
+type LogConfig struct {
10
+	BaseConfig
11
+	Level      string `yaml:"level"`
12
+	Output     string `yaml:"output"`
13
+	FilePath   string `yaml:"file_path"`
14
+	MaxSize    int    `yaml:"max_size"`
15
+	MaxBackups int    `yaml:"max_backups"`
16
+	MaxAge     int    `yaml:"max_age"`
17
+	Compress   bool   `yaml:"compress"`
18
+	ESEnabled  bool   `yaml:"es_enabled"`
19
+	ESPath     string `yaml:"es_path"`
20
+	JSONFormat bool   `yaml:"json_format"`
21
+}
22
+
23
+// NewLogConfig 创建日志配置实例
24
+func NewLogConfig() *LogConfig {
25
+	return &LogConfig{}
26
+}
27
+
28
+// SetDefaults 设置默认值
29
+func (c *LogConfig) SetDefaults() {
30
+	c.Level = "info"
31
+	c.Output = "both"
32
+	c.FilePath = "logs/service.log"
33
+	c.MaxSize = 100
34
+	c.MaxBackups = 3
35
+	c.MaxAge = 30
36
+	c.Compress = true
37
+	c.ESEnabled = true
38
+	c.ESPath = "logs/es-service.log"
39
+	c.JSONFormat = true
40
+}
41
+
42
+// Load 从yaml数据加载
43
+func (c *LogConfig) Load(data map[string]interface{}) error {
44
+	return c.LoadFromYAML(data, c)
45
+}
46
+
47
+// Validate 验证配置
48
+func (c *LogConfig) Validate() error {
49
+	// 验证日志级别
50
+	validLevels := map[string]bool{
51
+		"debug": true, "info": true, "warn": true, "error": true,
52
+	}
53
+	if !validLevels[strings.ToLower(c.Level)] {
54
+		return fmt.Errorf("invalid log level: %s", c.Level)
55
+	}
56
+
57
+	// 验证输出类型
58
+	validOutputs := map[string]bool{
59
+		"console": true, "file": true, "both": true,
60
+	}
61
+	if !validOutputs[c.Output] {
62
+		return fmt.Errorf("invalid log output: %s", c.Output)
63
+	}
64
+
65
+	return nil
66
+}
67
+
68
+// 自动注册
69
+func init() {
70
+	Register("log", &LogConfig{})
71
+}

+ 77
- 0
config/subconfigs/micro_config.go View File

@@ -0,0 +1,77 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// MicroConfig Go Micro微服务配置
6
+type MicroConfig struct {
7
+	BaseConfig
8
+	RegistryAddress string `yaml:"registry_address"`
9
+	RegistryType    string `yaml:"registry_type"`
10
+	RegistryTimeout int    `yaml:"registry_timeout"`
11
+	LBStrategy      string `yaml:"lb_strategy"`
12
+	LBCacheTTL      int    `yaml:"lb_cache_ttl"`
13
+	LBRetries       int    `yaml:"lb_retries"`
14
+	ClientTimeout   int    `yaml:"client_timeout"`
15
+	ClientPoolSize  int    `yaml:"client_pool_size"`
16
+	MaxRetries      int    `yaml:"max_retries"`
17
+	CircuitEnabled  bool   `yaml:"circuit_enabled"`
18
+	CircuitTimeout  int    `yaml:"circuit_timeout"`
19
+	ErrorThreshold  int    `yaml:"error_threshold"`
20
+	SleepWindow     int    `yaml:"sleep_window"`
21
+	HealthPath      string `yaml:"health_path"`
22
+	HealthInterval  int    `yaml:"health_interval"`
23
+	HealthTimeout   int    `yaml:"health_timeout"`
24
+	LogLevel        string `yaml:"log_level"`
25
+	EnableDebug     bool   `yaml:"enable_debug"`
26
+	MetricsEnabled  bool   `yaml:"metrics_enabled"`
27
+	MetricsAddress  string `yaml:"metrics_address"`
28
+	TracerEnabled   bool   `yaml:"tracer_enabled"`
29
+	TracerAddress   string `yaml:"tracer_address"`
30
+}
31
+
32
+func NewMicroConfig() *MicroConfig {
33
+	return &MicroConfig{}
34
+}
35
+
36
+func (c *MicroConfig) SetDefaults() {
37
+	c.RegistryAddress = "localhost:8500"
38
+	c.RegistryType = "consul"
39
+	c.RegistryTimeout = 10
40
+	c.LBStrategy = "roundrobin"
41
+	c.LBCacheTTL = 30
42
+	c.LBRetries = 3
43
+	c.ClientTimeout = 30
44
+	c.ClientPoolSize = 100
45
+	c.MaxRetries = 3
46
+	c.CircuitEnabled = true
47
+	c.CircuitTimeout = 60
48
+	c.ErrorThreshold = 5
49
+	c.SleepWindow = 5000
50
+	c.HealthPath = "/health"
51
+	c.HealthInterval = 10
52
+	c.HealthTimeout = 5
53
+	c.LogLevel = "info"
54
+	c.EnableDebug = false
55
+	c.MetricsEnabled = true
56
+	c.MetricsAddress = ":9090"
57
+}
58
+
59
+func (c *MicroConfig) Load(data map[string]interface{}) error {
60
+	return c.LoadFromYAML(data, c)
61
+}
62
+
63
+func (c *MicroConfig) Validate() error {
64
+	if c.RegistryAddress == "" {
65
+		return fmt.Errorf("registry address is required")
66
+	}
67
+	return nil
68
+}
69
+
70
+func (c *MicroConfig) IsConfigured() bool {
71
+	return c.RegistryAddress != ""
72
+}
73
+
74
+// 自动注册
75
+func init() {
76
+	Register("micro", &MicroConfig{})
77
+}

+ 74
- 0
config/subconfigs/rabbitmq_config.go View File

@@ -0,0 +1,74 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// RabbitMQConfig RabbitMQ配置
6
+type RabbitMQConfig struct {
7
+	BaseConfig
8
+	Host                 string `yaml:"host"`
9
+	Port                 int    `yaml:"port"`
10
+	Username             string `yaml:"username"`
11
+	Password             string `yaml:"password"`
12
+	Vhost                string `yaml:"vhost"`
13
+	UseTLS               bool   `yaml:"use_tls"`
14
+	CACert               string `yaml:"ca_cert"`
15
+	CertFile             string `yaml:"cert_file"`
16
+	KeyFile              string `yaml:"key_file"`
17
+	MaxOpenChannels      int    `yaml:"max_open_channels"`
18
+	ReconnectDelay       int    `yaml:"reconnect_delay"`
19
+	MaxReconnectAttempts int    `yaml:"max_reconnect_attempts"`
20
+	Heartbeat            int    `yaml:"heartbeat"`
21
+	ChannelSize          int    `yaml:"channel_size"`
22
+	DefaultExchange      string `yaml:"default_exchange"`
23
+	DefaultQueue         string `yaml:"default_queue"`
24
+	AutoAck              bool   `yaml:"auto_ack"`
25
+	Mandatory            bool   `yaml:"mandatory"`
26
+	Immediate            bool   `yaml:"immediate"`
27
+	PrefetchCount        int    `yaml:"prefetch_count"`
28
+	PrefetchSize         int    `yaml:"prefetch_size"`
29
+	Global               bool   `yaml:"global"`
30
+	PublisherConfirms    bool   `yaml:"publisher_confirms"`
31
+	ConfirmTimeout       int    `yaml:"confirm_timeout"`
32
+}
33
+
34
+func NewRabbitMQConfig() *RabbitMQConfig {
35
+	return &RabbitMQConfig{}
36
+}
37
+
38
+func (c *RabbitMQConfig) SetDefaults() {
39
+	c.Port = 5672
40
+	c.Username = "guest"
41
+	c.Password = "guest"
42
+	c.Vhost = "/"
43
+	c.MaxOpenChannels = 10
44
+	c.ReconnectDelay = 5000
45
+	c.MaxReconnectAttempts = 10
46
+	c.Heartbeat = 30
47
+	c.ChannelSize = 100
48
+	c.DefaultExchange = "amq.direct"
49
+	c.PrefetchCount = 1
50
+	c.ConfirmTimeout = 30
51
+}
52
+
53
+func (c *RabbitMQConfig) Load(data map[string]interface{}) error {
54
+	return c.LoadFromYAML(data, c)
55
+}
56
+
57
+func (c *RabbitMQConfig) Validate() error {
58
+	if c.Host == "" {
59
+		return fmt.Errorf("rabbitmq host is required")
60
+	}
61
+	if c.Port <= 0 {
62
+		return fmt.Errorf("invalid rabbitmq port: %d", c.Port)
63
+	}
64
+	return nil
65
+}
66
+
67
+func (c *RabbitMQConfig) IsConfigured() bool {
68
+	return c.Host != ""
69
+}
70
+
71
+// 自动注册
72
+func init() {
73
+	Register("rabbitmq", &RabbitMQConfig{})
74
+}

+ 52
- 0
config/subconfigs/redis_config.go View File

@@ -0,0 +1,52 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// RedisConfig Redis配置
6
+type RedisConfig struct {
7
+	BaseConfig
8
+	Host         string `yaml:"host"`
9
+	Port         int    `yaml:"port"`
10
+	Password     string `yaml:"password"`
11
+	DB           int    `yaml:"db"`
12
+	PoolSize     int    `yaml:"pool_size"`
13
+	DialTimeout  int    `yaml:"dial_timeout"`
14
+	ReadTimeout  int    `yaml:"read_timeout"`
15
+	WriteTimeout int    `yaml:"write_timeout"`
16
+	IdleTimeout  int    `yaml:"idle_timeout"`
17
+	MaxConnAge   int    `yaml:"max_conn_age"`
18
+}
19
+
20
+func NewRedisConfig() *RedisConfig {
21
+	return &RedisConfig{}
22
+}
23
+
24
+func (c *RedisConfig) SetDefaults() {
25
+	c.Port = 6379
26
+	c.DB = 0
27
+	c.PoolSize = 10
28
+	c.DialTimeout = 5
29
+	c.ReadTimeout = 3
30
+	c.WriteTimeout = 3
31
+	c.IdleTimeout = 300
32
+}
33
+
34
+func (c *RedisConfig) Load(data map[string]interface{}) error {
35
+	return c.LoadFromYAML(data, c)
36
+}
37
+
38
+func (c *RedisConfig) Validate() error {
39
+	if c.Host == "" {
40
+		return fmt.Errorf("redis host is required")
41
+	}
42
+	return nil
43
+}
44
+
45
+func (c *RedisConfig) IsConfigured() bool {
46
+	return c.Host != ""
47
+}
48
+
49
+// 自动注册
50
+func init() {
51
+	Register("redis", &RedisConfig{})
52
+}

+ 26
- 0
config/subconfigs/register.go View File

@@ -0,0 +1,26 @@
1
+package subconfigs
2
+
3
+// ConfigLoader 配置加载接口
4
+type ConfigLoader interface {
5
+	SetDefaults()
6
+	Load(data map[string]interface{}) error
7
+	//Validate() error
8
+}
9
+
10
+// 全局注册表 - 存储配置实例(单例)
11
+var registry = make(map[string]ConfigLoader)
12
+
13
+// Register 注册配置实例
14
+func Register(name string, config ConfigLoader) {
15
+	registry[name] = config
16
+}
17
+
18
+// GetConfig 获取配置实例
19
+func GetConfig(name string) ConfigLoader {
20
+	return registry[name]
21
+}
22
+
23
+// GetAllConfigs 获取所有配置
24
+func GetAllConfigs() map[string]ConfigLoader {
25
+	return registry
26
+}

+ 48
- 0
config/subconfigs/service_config.go View File

@@ -0,0 +1,48 @@
1
+package subconfigs
2
+
3
+import "fmt"
4
+
5
+// ServiceConfig 微服务配置
6
+type ServiceConfig struct {
7
+	BaseConfig
8
+	ServiceName    string `yaml:"service_name"`
9
+	ServiceVersion string `yaml:"service_version"`
10
+	ServiceTag     string `yaml:"service_tags"`
11
+	Port           int    `yaml:"port"`
12
+	ReadTimeout    int    `yaml:"read_timeout"`
13
+	WriteTimeout   int    `yaml:"write_timeout"`
14
+	IdleTimeout    int    `yaml:"idle_timeout"`
15
+	TrustedProxies string `yaml:"trusted_proxies"`
16
+	InstanceName   string `yaml:"instance-name"`
17
+}
18
+
19
+func NewServiceConfig() *ServiceConfig {
20
+	return &ServiceConfig{}
21
+}
22
+
23
+func (c *ServiceConfig) SetDefaults() {
24
+	c.ServiceName = "myService"
25
+	c.Port = 8080
26
+	c.ReadTimeout = 30
27
+	c.WriteTimeout = 30
28
+	c.IdleTimeout = 60
29
+}
30
+
31
+func (c *ServiceConfig) Load(data map[string]interface{}) error {
32
+	return c.LoadFromYAML(data, c)
33
+}
34
+
35
+func (c *ServiceConfig) Validate() error {
36
+	if c.ServiceName == "" {
37
+		return fmt.Errorf("service name is required")
38
+	}
39
+	if c.Port <= 0 || c.Port > 65535 {
40
+		return fmt.Errorf("invalid port: %d", c.Port)
41
+	}
42
+	return nil
43
+}
44
+
45
+// 自动注册
46
+func init() {
47
+	Register("service", &ServiceConfig{})
48
+}

+ 12
- 80
gct.sh View File

@@ -1,82 +1,14 @@
1 1
 #!/bin/bash
2 2
 
3
-# 脚本用法:./git-commit-and-tag.sh "你的提交描述" "版本号"
4
-
5
-# 检查参数数量
6
-if [ $# -ne 2 ]; then
7
-    echo "错误: 脚本需要2个参数。"
8
-    echo "用法: $0 \"提交描述\" \"版本号\""
9
-    echo "示例: $0 \"修复了登录问题\" \"v1.2.3\""
10
-    exit 1
11
-fi
12
-
13
-# 分配参数
14
-COMMIT_MESSAGE="$1"
15
-VERSION_TAG="$2"
16
-
17
-# 检查当前目录是否为Git仓库
18
-if ! git rev-parse --git-dir > /dev/null 2>&1; then
19
-    echo "错误: 当前目录不是一个Git仓库。"
20
-    exit 1
21
-fi
22
-
23
-echo "开始处理提交和版本标签..."
24
-echo "提交描述: $COMMIT_MESSAGE"
25
-echo "版本标签: $VERSION_TAG"
26
-
27
-# 检查是否有未提交的更改
28
-if [ -n "$(git status --porcelain)" ]; then
29
-    echo "检测到未提交的更改,正在提交..."
30
-    
31
-    # 添加所有更改到暂存区
32
-    git add .
33
-    
34
-    # 进行提交
35
-    git commit -m "$COMMIT_MESSAGE"
36
-    if [ $? -ne 0 ]; then
37
-        echo "错误: 提交失败。"
38
-        exit 1
39
-    fi
40
-    echo "✅ 更改已提交"
41
-else
42
-    echo "提示: 没有未提交的更改,跳过提交步骤"
43
-    
44
-    # 检查是否有未提交的commit但未推送
45
-    LOCAL_COMMITS=$(git log @{u}..HEAD --oneline 2>/dev/null | wc -l)
46
-    if [ $LOCAL_COMMITS -eq 0 ]; then
47
-        echo "错误: 没有需要推送的提交。"
48
-        exit 1
49
-    else
50
-        echo "检测到 $LOCAL_COMMITS 个本地提交等待推送"
51
-    fi
52
-fi
53
-
54
-# 检查标签是否已存在
55
-#if git rev-parse "$VERSION_TAG" >/dev/null 2>&1; then
56
- #   echo "错误: 标签 '$VERSION_TAG' 已经存在。"
57
-  #  exit 1
58
-#fi
59
-
60
-# 创建标签
61
-#git tag "$VERSION_TAG"
62
-#if [ $? -ne 0 ]; then
63
-#    echo "错误: 创建标签失败。"
64
-#    exit 1
65
-#fi
66
-#echo "✅ 标签 '$VERSION_TAG' 已创建"
67
-
68
-# 推送到远程仓库并推送标签
69
-echo "正在推送到远程仓库..."
70
-git push
71
-if [ $? -ne 0 ]; then
72
-    echo "错误: 推送提交失败。"
73
-    exit 1
74
-fi
75
-
76
-#git push origin "$VERSION_TAG"
77
-#if [ $? -ne 0 ]; then
78
-#    echo "错误: 推送标签失败。"
79
-#    exit 1
80
-#fi
81
-
82
-#echo "✅ 完成!提交已推送,版本标签 $VERSION_TAG 已创建并推送。"
3
+# 使用命令行参数,如果没有提供则使用默认值
4
+COMMIT_MSG="${1:-初始提交}"
5
+TAG_VERSION="${2:-v0.1.0}"
6
+
7
+echo "提交信息: $COMMIT_MSG"
8
+echo "标签版本: $TAG_VERSION"
9
+
10
+git add .
11
+git commit -m "$COMMIT_MSG"
12
+git push -u origin master
13
+git tag -s "$TAG_VERSION"
14
+git push origin "$TAG_VERSION"

+ 3
- 0
go.mod View File

@@ -33,6 +33,7 @@ require (
33 33
 	github.com/pjbgf/sha1cd v0.5.0 // indirect
34 34
 	github.com/skeema/knownhosts v1.3.2 // indirect
35 35
 	github.com/stretchr/objx v0.5.2 // indirect
36
+	go.uber.org/multierr v1.10.0 // indirect
36 37
 )
37 38
 
38 39
 require (
@@ -61,6 +62,7 @@ require (
61 62
 	github.com/urfave/cli/v2 v2.27.7 // indirect
62 63
 	github.com/xanzy/ssh-agent v0.3.3 // indirect
63 64
 	github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
65
+	go.uber.org/zap v1.27.1
64 66
 	golang.org/x/crypto v0.45.0 // indirect
65 67
 	golang.org/x/mod v0.30.0 // indirect
66 68
 	golang.org/x/net v0.47.0 // indirect
@@ -69,6 +71,7 @@ require (
69 71
 	golang.org/x/text v0.31.0 // indirect
70 72
 	golang.org/x/tools v0.39.0 // indirect
71 73
 	google.golang.org/protobuf v1.36.10 // indirect
74
+	gopkg.in/natefinch/lumberjack.v2 v2.2.1
72 75
 	gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
73 76
 	gopkg.in/warnings.v0 v0.1.2 // indirect
74 77
 )

+ 6
- 0
go.sum View File

@@ -186,6 +186,10 @@ github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAz
186 186
 github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
187 187
 go-micro.dev/v4 v4.11.0 h1:DZ2xcr0pnZJDlp6MJiCLhw4tXRxLw9xrJlPT91kubr0=
188 188
 go-micro.dev/v4 v4.11.0/go.mod h1:eE/tD53n3KbVrzrWxKLxdkGw45Fg1qaNLWjpJMvIUF4=
189
+go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
190
+go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
191
+go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
192
+go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
189 193
 golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
190 194
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
191 195
 golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
@@ -246,6 +250,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
246 250
 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
247 251
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
248 252
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
253
+gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
254
+gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
249 255
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
250 256
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
251 257
 gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

+ 13
- 8
types/types.go View File

@@ -18,17 +18,22 @@ type ExchangeRequest struct {
18 18
 
19 19
 // QueueRequest 创建队列的请求
20 20
 type QueueRequest struct {
21
-	ChannelName string            `json:"channel_name"`
22
-	QueueName   string            `json:"queue_name"`
23
-	Durable     bool              `json:"durable"`
24
-	Exclusive   bool              `json:"exclusive"`
25
-	AutoDelete  bool              `json:"auto_delete"`
26
-	NoWait      bool              `json:"no_wait"`
27
-	Arguments   map[string]string `json:"arguments"`
21
+	ChannelName  string `json:"channel_name"`
22
+	QueueName    string `json:"queue_name"`
23
+	Durable      bool   `json:"durable"`
24
+	Exclusive    bool   `json:"exclusive"`
25
+	AutoDelete   bool   `json:"auto_delete"`
26
+	NoWait       bool   `json:"no_wait"`
27
+	Url          string `json:"url"`
28
+	Concurrency  int    `json:"Concurrency"`
29
+	ExchangeName string `json:"exchange_name"`
30
+	RoutingKey   string `json:"routing_key"`
31
+
32
+	Arguments map[string]string `json:"arguments"`
28 33
 }
29 34
 
30 35
 // BindRequest 绑定队列的请求
31
-type BindRequest struct {
36
+type QueueBindRequest struct {
32 37
 	ChannelName  string            `json:"channel_name"`
33 38
 	QueueName    string            `json:"queue_name"`
34 39
 	ExchangeName string            `json:"exchange_name"`

Loading…
Cancel
Save