dataRT/config/rabbit.go

84 lines
1.5 KiB
Go
Raw Normal View History

2025-09-05 18:35:46 +08:00
package config
type rabbitConfig struct {
2025-11-20 20:58:51 +08:00
Broker string `json:"broker" yaml:"broker"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
2025-09-05 18:35:46 +08:00
}
func NewRabbitConfig() *rabbitConfig {
return new(rabbitConfig)
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) GenAddress(tls bool) string {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("rabbit config is nil")
}
2025-09-19 16:17:46 +08:00
address := "amqp://"
if tls {
address = "amqps://"
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
if conf.GetUsername() != "" && conf.GetPassword() != "" {
address += conf.GetUsername() + ":" + conf.GetPassword() + "@"
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
address += conf.GetBroker() + "/"
2025-09-05 18:35:46 +08:00
2025-09-19 16:17:46 +08:00
return address
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) GetBroker() string {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("rabbit config is nil")
}
2025-09-19 16:17:46 +08:00
return conf.Broker
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) SetBroker(broker string) *rabbitConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("rabbit config is nil")
}
2025-09-19 16:17:46 +08:00
conf.Broker = broker
2025-09-05 18:35:46 +08:00
2025-09-19 16:17:46 +08:00
return conf
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) GetUsername() string {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("rabbit config is nil")
}
2025-09-19 16:17:46 +08:00
return conf.Username
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) SetUsername(username string) *rabbitConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
2025-09-19 16:17:46 +08:00
panic("rabbit config is nil")
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
conf.Username = username
2025-09-05 18:35:46 +08:00
2025-09-19 16:17:46 +08:00
return conf
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) GetPassword() string {
2025-09-05 18:35:46 +08:00
if conf == nil {
2025-09-19 16:17:46 +08:00
panic("rabbit config is nil")
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
return conf.Password
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *rabbitConfig) SetPassword(password string) *rabbitConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
2025-09-19 16:17:46 +08:00
panic("rabbit config is nil")
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
conf.Password = password
2025-09-05 18:35:46 +08:00
2025-09-19 16:17:46 +08:00
return conf
2025-09-05 18:35:46 +08:00
}
func rabbitConfigName() string {
return "rabbit.json"
}