46 lines
896 B
Go
46 lines
896 B
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/aykhans/oh-my-chat/internal/core/utils"
|
|
)
|
|
|
|
type BootstrapServers []string
|
|
|
|
func (b *BootstrapServers) String() string {
|
|
return strings.Join(*b, ",")
|
|
}
|
|
|
|
type KafkaConfig struct {
|
|
*KafkaProducerConfig
|
|
*KafkaConsumerConfig
|
|
}
|
|
|
|
type KafkaProducerConfig struct {
|
|
BootstrapServers BootstrapServers
|
|
}
|
|
|
|
type KafkaConsumerConfig struct {
|
|
BootstrapServers BootstrapServers
|
|
}
|
|
|
|
func NewKafkaConfig() *KafkaConfig {
|
|
return &KafkaConfig{
|
|
NewKafkaProducerConfig(),
|
|
NewKafkaConsumerConfig(),
|
|
}
|
|
}
|
|
|
|
func NewKafkaProducerConfig() *KafkaProducerConfig {
|
|
return &KafkaProducerConfig{
|
|
BootstrapServers: utils.Str2StrSlice(GetEnvOrDie("KAFKA_PRODUCER_BOOTSTRAP_SERVERS")),
|
|
}
|
|
}
|
|
|
|
func NewKafkaConsumerConfig() *KafkaConsumerConfig {
|
|
return &KafkaConsumerConfig{
|
|
BootstrapServers: utils.Str2StrSlice(GetEnvOrDie("KAFKA_CONSUMER_BOOTSTRAP_SERVERS")),
|
|
}
|
|
}
|