optimize cfg

This commit is contained in:
pasha1coil 2025-02-25 11:14:51 +03:00
parent ed22813e11
commit 8d6a2c34d9
4 changed files with 26 additions and 32 deletions

@ -90,15 +90,15 @@ func New(ctx context.Context, cfg initialize.Config, build Build) error {
mailSender := senders2.NewMailLeadSender(clients.MailClient) mailSender := senders2.NewMailLeadSender(clients.MailClient)
leadSenders := []senders2.LeadSender{mailSender /* , tgSender */} leadSenders := []senders2.LeadSender{mailSender /* , tgSender */}
pgdal, err := dal.New(ctx, cfg.PostgresCredentials, minioClient) pgdal, err := dal.New(ctx, cfg.PostgresURL, minioClient)
if err != nil { if err != nil {
zapLogger.Error("failed init postgres", zap.Error(err)) zapLogger.Error("failed init postgres", zap.Error(err))
return err return err
} }
kafkaWorker, err := privilegewc2.NewKafkaConsumerWorker(privilegewc2.Config{ kafkaWorker, err := privilegewc2.NewKafkaConsumerWorker(privilegewc2.Config{
KafkaBroker: cfg.KafkaBroker, KafkaBroker: cfg.KafkaBrokers,
KafkaTopic: cfg.KafkaTopic, KafkaTopic: cfg.KafkaTopicTariff,
ServiceKey: cfg.ServiceName, ServiceKey: cfg.ServiceName,
TickerInterval: time.Second * 10, TickerInterval: time.Second * 10,
ErrChan: errChan, ErrChan: errChan,

@ -14,15 +14,13 @@ type Clients struct {
func NewClients(cfg Config, logger *zap.Logger) *Clients { func NewClients(cfg Config, logger *zap.Logger) *Clients {
return &Clients{ return &Clients{
MailClient: clients.NewSmtpClient(clients.Deps{ MailClient: clients.NewSmtpClient(clients.Deps{
SmtpHost: cfg.SmtpHost, SmtpSender: cfg.Sender,
SmtpPort: cfg.SmtpPort, ApiKey: cfg.ApiKey,
SmtpSender: cfg.SmtpSender, SmtpApiUrl: cfg.ApiUrl,
ApiKey: cfg.SmtpApiKey,
SmtpApiUrl: cfg.SmtpApiUrl,
}), }),
CustomerClient: customer_clients.NewCustomersClient(customer_clients.CustomersClientDeps{ CustomerClient: customer_clients.NewCustomersClient(customer_clients.CustomersClientDeps{
Logger: logger, Logger: logger,
CustomerServiceHost: cfg.CustomerServiceAddress, CustomerServiceHost: cfg.CustomerMicroserviceRPCURL,
}), }),
} }
} }

@ -7,27 +7,23 @@ import (
) )
type Config struct { type Config struct {
ServiceName string `env:"SERVICE_NAME" envDefault:"squiz"` ServiceName string `env:"SERVICE_NAME" envDefault:"squiz"`
KafkaBroker string `env:"KAFKA_BROKER" envDefault:"localhost:6379"` KafkaBrokers string `env:"KAFKA_BROKERS" envDefault:"localhost:6379"`
KafkaTopic string `env:"KAFKA_TOPIC" envDefault:"test-topic"` KafkaTopicTariff string `env:"KAFKA_TOPIC_TARIFF" envDefault:"test-topic"`
LoggerProdMode bool `env:"IS_PROD_LOG" envDefault:"false"` LoggerProdMode bool `env:"IS_PROD_LOG" envDefault:"false"`
IsProd bool `env:"IS_PROD" envDefault:"false"` IsProd bool `env:"IS_PROD" envDefault:"false"`
MinioEP string `env:"MINIO_EP" envDefault:"localhost:3002"` S3Endpoint string `env:"S3_ENDPOINT" envDefault:"localhost:3002"`
MinioAK string `env:"MINIO_AK" envDefault:"minio"` S3AccessKey string `env:"S3_ACCESS_KEY" envDefault:"minio"`
MinioSK string `env:"MINIO_SK" envDefault:"miniostorage"` S3SecretKey string `env:"S3_SECRET_KEY" envDefault:"miniostorage"`
PostgresCredentials string `env:"PG_CRED" envDefault:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"` PostgresURL string `env:"POSTGRES_URL" envDefault:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
RedisHost string `env:"REDIS_HOST" envDefault:"localhost:6379"` RedisHost string `env:"REDIS_HOST"`
RedisPassword string `env:"REDIS_PASSWORD" envDefault:"admin"` RedisPassword string `env:"REDIS_PASSWORD"`
RedisDB uint64 `env:"REDIS_DB" envDefault:"2"` RedisDB uint64 `env:"REDIS_DB"`
SmtpHost string `env:"SMTP_HOST" envDefault:"connect.mailclient.bz"` Sender string `env:"MAIL_SENDER" envDefault:"noreply@mailing.pena.digital"`
SmtpPort string `env:"SMTP_PORT" envDefault:"587"` ApiKey string `env:"MAIL_API_KEY" envDefault:"P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"`
SmtpSender string `env:"SMTP_SENDER" envDefault:"noreply@mailing.pena.digital"` ApiUrl string `env:"API_URL" envDefault:"https://api.smtp.bz/v1/smtp/send"`
SmtpUsername string `env:"SMTP_USERNAME" envDefault:"kotilion.95@gmail.com"` CustomerMicroserviceRPCURL string `env:"CUSTOMER_MICROSERVICE_RPC_URL" envDefault:"localhost:9001"`
SmtpPassword string `env:"SMTP_PASSWORD" envDefault:"vWwbCSg4bf0p"` TelegramToken string `env:"TELEGRAM_TOKEN"`
SmtpApiKey string `env:"SMTP_API_KEY" envDefault:"P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"`
SmtpApiUrl string `env:"SMTP_API_URL" envDefault:"https://api.smtp.bz/v1/smtp/send"`
CustomerServiceAddress string `env:"CUSTOMER_SERVICE_ADDRESS" envDefault:"localhost:9001"`
TgToken string `env:"TG_TOKEN"`
} }
func LoadConfig() (*Config, error) { func LoadConfig() (*Config, error) {

@ -6,8 +6,8 @@ import (
) )
func NewMinio(cfg Config) (*minio.Client, error) { func NewMinio(cfg Config) (*minio.Client, error) {
minioClient, err := minio.New(cfg.MinioEP, &minio.Options{ minioClient, err := minio.New(cfg.S3Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(cfg.MinioAK, cfg.MinioSK, ""), Creds: credentials.NewStaticV4(cfg.S3AccessKey, cfg.S3SecretKey, ""),
Secure: cfg.IsProd, Secure: cfg.IsProd,
}) })
if err != nil { if err != nil {