Skip to content

Commit

Permalink
✨ feat: added kafka clusters conf #50 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Dec 2, 2023
1 parent dc609a2 commit 70c45db
Show file tree
Hide file tree
Showing 7 changed files with 988 additions and 56 deletions.
33 changes: 33 additions & 0 deletions configx/configx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/sivaosorg/govm/mongodb"
"github.com/sivaosorg/govm/mysql"
"github.com/sivaosorg/govm/postgres"
"github.com/sivaosorg/govm/queues"
"github.com/sivaosorg/govm/rabbitmqx"
"github.com/sivaosorg/govm/redisx"
"github.com/sivaosorg/govm/server"
Expand Down Expand Up @@ -180,6 +181,7 @@ func GetKeysDefaultConfig() *KeysConfig {
k.SetCors(*corsx.GetCorsConfigSample().SetEnabled(false))
k.SetCookie(*cookies.GetCookieConfigSample().SetEnabled(false))
k.SetLogger(*logger.GetLoggerSample().SetEnabled(false))
k.SetKafka(*queues.GetKafkaSample().SetEnabled(false))
k.AppendTelegramSeekers(*telegram.GetMultiTenantTelegramConfigSample())
k.AppendSlackSeekers(*slack.GetMultiTenantSlackConfigSample())
k.AppendAsteriskSeekers(*asterisk.GetMultiTenantAsteriskConfigSample())
Expand All @@ -190,6 +192,7 @@ func GetKeysDefaultConfig() *KeysConfig {
k.AppendRedisSeekers(*redisx.GetMultiTenantRedisConfigSample())
k.AppendCookieSeekers(*cookies.GetMultiTenantCookieConfigSample())
k.AppendLoggerSeekers(*logger.GetMultiTenantLoggerConfigSample())
k.AppendKafkaSeekers(*queues.GetMultiTenantKafkaConfigSample())
return k
}

Expand All @@ -205,6 +208,7 @@ func (KeysConfig) WriteDefaultConfig() {
"server": fmt.Sprintf("################################\n%s\n%s\n################################", "Server Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"cookie": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"logger": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"kafka": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"asterisk": fmt.Sprintf("################################\n%s\n%s\n################################", "Asterisk Server Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mongodb": fmt.Sprintf("################################\n%s\n%s\n################################", "Mongodb Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mysql": fmt.Sprintf("################################\n%s\n%s\n################################", "MySQL Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
Expand All @@ -224,6 +228,7 @@ func (KeysConfig) WriteDefaultConfig() {
"redis-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Redis Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"cookie-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"logger-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"kafka-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
})
err = CreateConfigWithComments[KeysConfig](filepath.Join(".", FilenameDefaultConf), *m)
if err != nil {
Expand Down Expand Up @@ -449,6 +454,16 @@ func (k *KeysConfig) SetLoggerCursor(value *logger.Logger) *KeysConfig {
return k
}

func (k *KeysConfig) SetKafka(value queues.KafkaConfig) *KeysConfig {
k.Kafka = value
return k
}

func (k *KeysConfig) SetKafkaCursor(value *queues.KafkaConfig) *KeysConfig {
k.Kafka = *value
return k
}

func (k *KeysConfig) SetTelegramSeekers(values []telegram.MultiTenantTelegramConfig) *KeysConfig {
k.TelegramSeekers = values
return k
Expand Down Expand Up @@ -549,6 +564,16 @@ func (k *KeysConfig) AppendLoggerSeekers(values ...logger.MultiTenantLoggerConfi
return k
}

func (k *KeysConfig) SetKafkaSeekers(values []queues.MultiTenantKafkaConfig) *KeysConfig {
k.KafkaSeekers = values
return k
}

func (k *KeysConfig) AppendKafkaSeekers(values ...queues.MultiTenantKafkaConfig) *KeysConfig {
k.KafkaSeekers = append(k.KafkaSeekers, values...)
return k
}

func (k *KeysConfig) AvailableTelegramSeekers() bool {
return len(k.TelegramSeekers) > 0
}
Expand Down Expand Up @@ -589,6 +614,10 @@ func (k *KeysConfig) AvailableLoggerSeekers() bool {
return len(k.LoggerSeekers) > 0
}

func (k *KeysConfig) AvailableKafkaSeekers() bool {
return len(k.KafkaSeekers) > 0
}

func (k *KeysConfig) FindTelegramSeeker(key string) (telegram.MultiTenantTelegramConfig, error) {
return telegram.NewClusterMultiTenantTelegramConfig().SetClusters(k.TelegramSeekers).FindClusterBy(key)
}
Expand Down Expand Up @@ -629,6 +658,10 @@ func (k *KeysConfig) FindLoggerSeeker(key string) (logger.MultiTenantLoggerConfi
return logger.NewClusterMultiTenantLoggerConfig().SetClusters(k.LoggerSeekers).FindClusterBy(key)
}

func (k *KeysConfig) FindKafkaSeeker(key string) (queues.MultiTenantKafkaConfig, error) {
return queues.NewClusterMultiTenantKafkaConfig().SetClusters(k.KafkaSeekers).FindClusterBy(key)
}

func _marshal(data interface{}, comments FieldCommentConfig) ([]byte, error) {
bytes, err := yaml.Marshal(data)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions configx/configx_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/sivaosorg/govm/mongodb"
"github.com/sivaosorg/govm/mysql"
"github.com/sivaosorg/govm/postgres"
"github.com/sivaosorg/govm/queues"
"github.com/sivaosorg/govm/rabbitmqx"
"github.com/sivaosorg/govm/redisx"
"github.com/sivaosorg/govm/server"
Expand Down Expand Up @@ -38,6 +39,7 @@ type KeysConfig struct {
Server server.Server `json:"server,omitempty" yaml:"server"`
Cookie cookies.CookieConfig `json:"cookie,omitempty" yaml:"cookie"`
Logger logger.Logger `json:"logger,omitempty" yaml:"logger"`
Kafka queues.KafkaConfig `json:"kafka,omitempty" yaml:"kafka"`

// Seekers
TelegramSeekers []telegram.MultiTenantTelegramConfig `json:"telegram_seekers,omitempty" yaml:"telegram-seekers"`
Expand All @@ -50,6 +52,7 @@ type KeysConfig struct {
RedisSeekers []redisx.MultiTenantRedisConfig `json:"redis_seekers,omitempty" yaml:"redis-seekers"`
CookieSeekers []cookies.MultiTenantCookieConfig `json:"cookie_seekers,omitempty" yaml:"cookie-seekers"`
LoggerSeekers []logger.MultiTenantLoggerConfig `json:"logger_seekers,omitempty" yaml:"logger-seekers"`
KafkaSeekers []queues.MultiTenantKafkaConfig `json:"kafka_seekers,omitempty" yaml:"kafka-seekers"`

// Params unknown
Param1 map[string]interface{} `json:"param1,omitempty" yaml:"param1"`
Expand Down
Loading

0 comments on commit 70c45db

Please sign in to comment.