optimized cfg
This commit is contained in:
parent
d312604e97
commit
3178a5d5d5
16
.env
16
.env
@ -4,17 +4,13 @@ MONGO_DB_NAME = "admin"
|
||||
|
||||
# Kafka settings
|
||||
KAFKA_BROKERS="localhost:9092"
|
||||
KAFKA_TOPIC_TARIFF="test-topic"
|
||||
KAFKA_TOPIC_MAIL_NOTIFIER="test-topic"
|
||||
|
||||
# SMTP settings
|
||||
SMTP_API_URL="https://api.smtp.bz/v1/smtp/send"
|
||||
SMTP_HOST="connect.mailclient.bz"
|
||||
SMTP_PORT="587"
|
||||
SMTP_UNAME="kotilion.95@gmail.com"
|
||||
SMTP_PASS="vWwbCSg4bf0p"
|
||||
SMTP_API_KEY="P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"
|
||||
SMTP_SENDER="noreply@mailing.pena.digital"
|
||||
API_URL="https://api.smtp.bz/v1/smtp/send"
|
||||
MAIL_API_KEY="P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"
|
||||
MAIL_SENDER="noreply@mailing.pena.digital"
|
||||
|
||||
# URL settings
|
||||
CustomerURL = "http://localhost:8080"
|
||||
QuizRPCURL = "localhost:9000"
|
||||
CUSTOMER_MICROSERVICE_GRPC_URL = "http://localhost:8080"
|
||||
QUIZ_CORE_MICROSERVICE_GRPC_URL = "localhost:9000"
|
20
go.mod
20
go.mod
@ -1,11 +1,12 @@
|
||||
module gitea.pena/PenaSide/notifier
|
||||
|
||||
go 1.22.0
|
||||
go 1.23.2
|
||||
|
||||
toolchain go1.23.2
|
||||
toolchain go1.23.3
|
||||
|
||||
require (
|
||||
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1
|
||||
gitea.pena/PenaSide/common v0.0.0-20241213122118-5fbc737eb63e
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735
|
||||
github.com/caarlos0/env/v8 v8.0.0
|
||||
github.com/gofiber/fiber/v2 v2.51.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
@ -17,11 +18,10 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735 // indirect
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.17.4 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
@ -37,10 +37,10 @@ require (
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
)
|
||||
|
32
go.sum
32
go.sum
@ -1,5 +1,5 @@
|
||||
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1 h1:w1AAxrlZGmxUI9NAa/0TYsc6sqWWF9yAzQaLL/KxwrM=
|
||||
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw=
|
||||
gitea.pena/PenaSide/common v0.0.0-20241213122118-5fbc737eb63e h1:44CqlJOrUaZUsEv7ssFwyDjHn8PxTbTJqhDKlo1kLwE=
|
||||
gitea.pena/PenaSide/common v0.0.0-20241213122118-5fbc737eb63e/go.mod h1:l4frySn2SkcdYonL0qyiv9+byj8+/GMLohSICnVYDTM=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735 h1:jDVeUhGBTXBibmW5dmtJg2m2+z5z2Rf6J4G0LpjVoJ0=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735/go.mod h1:gdd+vOT6up9STkEbxa2qESLIMZFjCmRbkcheFQCVgZU=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
@ -18,8 +18,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
|
||||
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
@ -35,8 +35,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/twmb/franz-go v1.16.1 h1:rpWc7fB9jd7TgmCyfxzenBI+QbgS8ZfJOUQE+tzPtbE=
|
||||
github.com/twmb/franz-go v1.16.1/go.mod h1:/pER254UPPGp/4WfGqRi+SIRGE50RSQzVubQp6+N4FA=
|
||||
github.com/twmb/franz-go/pkg/kmsg v1.7.0 h1:a457IbvezYfA5UkiBvyV3zj0Is3y1i8EJgqjJYoij2E=
|
||||
@ -66,18 +66,18 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@ -85,16 +85,16 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
|
@ -36,21 +36,12 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
|
||||
repo := repository.NewRepository(mdb.Collection("notify"))
|
||||
|
||||
mailClient := clients.NewMailClient(clients.Deps{
|
||||
SmtpHost: config.SmtpHost,
|
||||
SmtpApiUrl: config.SmtpApiUrl,
|
||||
SmtpPort: config.SmtpPort,
|
||||
SmtpSender: config.SmtpSender,
|
||||
Username: config.SmtpUsername,
|
||||
Password: config.SmtpPassword,
|
||||
ApiKey: config.SmtpApiKey,
|
||||
Logger: logger,
|
||||
})
|
||||
mailClient := clients.NewMailClient(config.External.MailClientCfg)
|
||||
|
||||
quizClient := clients.NewQuizClient(config.QuizRPCURL, logger)
|
||||
quizClient := clients.NewQuizClient(config.QuizCoreMicroserviceGRPC, logger)
|
||||
|
||||
customerClient := clients.NewCustomerClient(clients.CustomerDeps{
|
||||
Url: config.CustomerURL,
|
||||
Url: config.CustomerMicroserviceGRPC,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
|
@ -3,34 +3,31 @@ package clients
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"gitea.pena/PenaSide/notifier/internal/initialize"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"html/template"
|
||||
"mime/multipart"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
SmtpApiUrl string
|
||||
SmtpHost string
|
||||
SmtpPort string
|
||||
SmtpSender string
|
||||
Username string
|
||||
Password string
|
||||
ApiKey string
|
||||
FiberClient *fiber.Client
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type MailClient struct {
|
||||
deps Deps
|
||||
smtpApiUrl string
|
||||
smtpSender string
|
||||
apiKey string
|
||||
fiberClient *fiber.Client
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewMailClient(deps Deps) *MailClient {
|
||||
func NewMailClient(deps initialize.MailClientCfg) *MailClient {
|
||||
if deps.FiberClient == nil {
|
||||
deps.FiberClient = fiber.AcquireClient()
|
||||
}
|
||||
return &MailClient{
|
||||
deps: deps,
|
||||
smtpApiUrl: deps.ApiURL,
|
||||
smtpSender: deps.Sender,
|
||||
apiKey: deps.ApiKey,
|
||||
fiberClient: deps.FiberClient,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,13 +40,13 @@ type SenderDeps struct {
|
||||
func (m *MailClient) MailSender(data SenderDeps) error {
|
||||
tmpl, err := template.New("email").Parse(data.Tmpl)
|
||||
if err != nil {
|
||||
m.deps.Logger.Error("Error parsing HTML template:", zap.Error(err))
|
||||
m.logger.Error("Error parsing HTML template:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err = tmpl.Execute(&buf, nil); err != nil {
|
||||
m.deps.Logger.Error("Error executing template:", zap.Error(err))
|
||||
m.logger.Error("Error executing template:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -59,7 +56,7 @@ func (m *MailClient) MailSender(data SenderDeps) error {
|
||||
writer := multipart.NewWriter(form)
|
||||
|
||||
fields := map[string]string{
|
||||
"from": m.deps.SmtpSender,
|
||||
"from": m.smtpSender,
|
||||
"to": data.Email,
|
||||
"subject": data.Subject,
|
||||
"html": htmlBody,
|
||||
@ -75,20 +72,20 @@ func (m *MailClient) MailSender(data SenderDeps) error {
|
||||
return err
|
||||
}
|
||||
|
||||
req := m.deps.FiberClient.Post(m.deps.SmtpApiUrl).Body(form.Bytes()).ContentType(writer.FormDataContentType())
|
||||
if m.deps.ApiKey != "" {
|
||||
req.Set("Authorization", m.deps.ApiKey)
|
||||
req := m.fiberClient.Post(m.smtpApiUrl).Body(form.Bytes()).ContentType(writer.FormDataContentType())
|
||||
if m.apiKey != "" {
|
||||
req.Set("Authorization", m.apiKey)
|
||||
}
|
||||
|
||||
statusCode, body, errs := req.Bytes()
|
||||
if errs != nil {
|
||||
m.deps.Logger.Error("Error sending request:", zap.Error(errs[0]))
|
||||
m.logger.Error("Error sending request:", zap.Error(errs[0]))
|
||||
return errs[0]
|
||||
}
|
||||
|
||||
if statusCode != fiber.StatusOK {
|
||||
err = fmt.Errorf("the SMTP service returned an error: %s Response body: %s", statusCode, body)
|
||||
m.deps.Logger.Error("Error sending email:", zap.Error(err))
|
||||
m.logger.Error("Error sending email:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -3,23 +3,31 @@ package initialize
|
||||
import (
|
||||
"gitea.pena/PenaSide/common/mongo"
|
||||
"github.com/caarlos0/env/v8"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/joho/godotenv"
|
||||
"go.uber.org/zap"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
KafkaBrokers string `env:"KAFKA_BROKERS"`
|
||||
KafkaTopic string `env:"KAFKA_TOPIC_TARIFF"`
|
||||
SmtpApiUrl string `env:"SMTP_API_URL"`
|
||||
SmtpHost string `env:"SMTP_HOST"`
|
||||
SmtpPort string `env:"SMTP_PORT"`
|
||||
SmtpUsername string `env:"SMTP_UNAME"`
|
||||
SmtpPassword string `env:"SMTP_PASS"`
|
||||
SmtpApiKey string `env:"SMTP_API_KEY"`
|
||||
SmtpSender string `env:"SMTP_SENDER"`
|
||||
CustomerURL string `env:"CUSTOMER_URL"`
|
||||
QuizRPCURL string `enc:"QUIZ_RPC_URL"`
|
||||
DataBase mongo.Configuration
|
||||
KafkaBrokers string `env:"KAFKA_BROKERS,required"`
|
||||
KafkaTopicMailNotifier string `env:"KAFKA_TOPIC_MAIL_NOTIFIER,required"`
|
||||
CustomerMicroserviceGRPC string `env:"CUSTOMER_MICROSERVICE_GRPC_URL,required"`
|
||||
QuizCoreMicroserviceGRPC string `env:"QUIZ_CORE_MICROSERVICE_GRPC_URL,required"`
|
||||
External External
|
||||
}
|
||||
|
||||
type External struct {
|
||||
MailClientCfg MailClientCfg
|
||||
Database mongo.Configuration
|
||||
}
|
||||
|
||||
type MailClientCfg struct {
|
||||
ApiURL string `env:"API_URL,required"`
|
||||
ApiKey string `env:"MAIL_API_KEY,required"`
|
||||
Sender string `env:"MAIL_SENDER,required"`
|
||||
FiberClient *fiber.Client
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
func LoadConfig() (*Config, error) {
|
||||
|
@ -10,7 +10,7 @@ func KafkaConsumerInit(ctx context.Context, config Config) (*kgo.Client, error)
|
||||
kafkaClient, err := kgo.NewClient(
|
||||
kgo.SeedBrokers(config.KafkaBrokers),
|
||||
kgo.ConsumerGroup("mailnotifier"),
|
||||
kgo.ConsumeTopics(config.KafkaTopic),
|
||||
kgo.ConsumeTopics(config.KafkaTopicMailNotifier),
|
||||
kgo.ConsumeResetOffset(kgo.NewOffset().AfterMilli(time.Now().UnixMilli())),
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -12,7 +12,7 @@ func MongoInit(ctx context.Context, config Config) (*mongo.Database, error) {
|
||||
defer cancel()
|
||||
|
||||
deps := mg.ConnectDeps{
|
||||
Configuration: &config.DataBase,
|
||||
Configuration: &config.External.Database,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,11 @@ import (
|
||||
func TestInsertAndGetMany(t *testing.T) {
|
||||
crx := context.Background()
|
||||
mdb, err := initialize.MongoInit(crx, initialize.Config{
|
||||
DataBase: mongo.Configuration{
|
||||
URL: "mongodb://test:test@localhost:27020/",
|
||||
DatabaseName: "admin",
|
||||
External: initialize.External{
|
||||
Database: mongo.Configuration{
|
||||
URL: "mongodb://test:test@localhost:27020/",
|
||||
DatabaseName: "admin",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user