added gigachatproducer

This commit is contained in:
pasha1coil 2025-05-15 11:58:21 +03:00
parent f121cc527d
commit ba668b3539
4 changed files with 44 additions and 19 deletions

@ -97,11 +97,26 @@ func Run(ctx context.Context, cfg initialize.Config, build Build) error {
return err
}
gigaChatKafka, err := initialize.KafkaInit(ctx, initialize.KafkaDeps{
KafkaGroup: cfg.KafkaGroupGigaChat,
KafkaBrokers: cfg.KafkaBrokers,
KafkaTopic: cfg.KafkaTopicGigaChat,
})
if err != nil {
zapLogger.Error("Error initializing kafka", zap.Error(err))
return err
}
producer := brokers.NewProducer(brokers.ProducerDeps{
KafkaClient: kafkaClient,
Logger: zapLogger,
})
producerGigaChat := brokers.NewProducer(brokers.ProducerDeps{
KafkaClient: gigaChatKafka,
Logger: zapLogger,
})
redisClient, err := initialize.Redis(ctx, cfg)
if err != nil {
zapLogger.Error("Error initializing redis", zap.Error(err))
@ -135,6 +150,7 @@ func Run(ctx context.Context, cfg initialize.Config, build Build) error {
Config: cfg,
Producer: producer,
RedisClient: redisClient,
ProducerGigaChat: producerGigaChat,
})
grpc, err := server.NewGRPC(zapLogger)

@ -10,21 +10,26 @@ import (
"gitea.pena/SQuiz/core/internal/brokers"
"gitea.pena/SQuiz/core/internal/models"
"github.com/gofiber/fiber/v2"
"time"
"strconv"
"time"
"unicode/utf8"
)
type Deps struct {
DAL *dal.DAL
ProducerGigaChat *brokers.Producer
}
type Quiz struct {
dal *dal.DAL
producerGigaChat *brokers.Producer
}
func NewQuizController(deps Deps) *Quiz {
return &Quiz{dal: deps.DAL}
return &Quiz{
dal: deps.DAL,
producerGigaChat: deps.ProducerGigaChat,
}
}
type CreateQuizReq struct {

@ -27,6 +27,8 @@ type Config struct {
CrtFile string `env:"CRT" envDefault:"server.crt"`
KeyFile string `env:"KEY" envDefault:"server.key"`
ServiceName string `env:"SERVICE_NAME" envDefault:"squiz"`
KafkaGroupGigaChat string `env:"KAFKA_GROUP_GIGA_CHAT" default:"gigachat"`
KafkaTopicGigaChat string `env:"KAFKA_TOPIC_GIGA_CHAT"`
}
func LoadConfig() (*Config, error) {

@ -1,7 +1,6 @@
package initialize
import (
"github.com/go-redis/redis/v8"
"gitea.pena/SQuiz/core/internal/brokers"
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/account"
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/question"
@ -10,6 +9,7 @@ import (
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/statistic"
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/telegram"
"gitea.pena/SQuiz/core/internal/controllers/rpc_controllers"
"github.com/go-redis/redis/v8"
)
type ControllerDeps struct {
@ -18,6 +18,7 @@ type ControllerDeps struct {
Config Config
Producer *brokers.Producer
RedisClient *redis.Client
ProducerGigaChat *brokers.Producer
}
type Controller struct {
@ -55,6 +56,7 @@ func NewControllers(deps ControllerDeps) *Controller {
}),
Quiz: quiz.NewQuizController(quiz.Deps{
DAL: deps.DALs.PgDAL,
ProducerGigaChat: deps.ProducerGigaChat,
}),
Result: result.NewResultController(result.Deps{
DAL: deps.DALs.PgDAL,