From 448244cef862b24c38cd18a9dfd8a8d9dbb9168a Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 25 Nov 2024 11:14:01 +0300 Subject: [PATCH 1/9] aplied renamer --- cmd/main.go | 4 ++-- go.mod | 2 +- internal/app/app.go | 8 ++++---- internal/clients/customer.go | 2 +- internal/clients/quiz_rpc.go | 2 +- internal/repository/repository.go | 2 +- internal/workers/consumer.go | 6 +++--- internal/workers/notifyer.go | 6 +++--- internal/workers/welcomer.go | 6 +++--- test/core_test.go | 4 ++-- test/kafka_test.go | 2 +- test/repo_test.go | 6 +++--- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 342a455..3ac0897 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,8 +4,8 @@ import ( "context" "fmt" "go.uber.org/zap" - "mailnotifier/internal/app" - "mailnotifier/internal/initialize" + "gitea.pena/PenaSide/notifier/internal/app" + "gitea.pena/PenaSide/notifier/internal/initialize" "os" "os/signal" "syscall" diff --git a/go.mod b/go.mod index 54946f2..4ddf118 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module mailnotifier +module gitea.pena/PenaSide/notifier go 1.21.6 diff --git a/internal/app/app.go b/internal/app/app.go index 063900f..6764e8f 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -3,10 +3,10 @@ package app import ( "context" "go.uber.org/zap" - "mailnotifier/internal/clients" - "mailnotifier/internal/initialize" - "mailnotifier/internal/repository" - "mailnotifier/internal/workers" + "gitea.pena/PenaSide/notifier/internal/clients" + "gitea.pena/PenaSide/notifier/internal/initialize" + "gitea.pena/PenaSide/notifier/internal/repository" + "gitea.pena/PenaSide/notifier/internal/workers" ) func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error { diff --git a/internal/clients/customer.go b/internal/clients/customer.go index bcc6b09..d4fd35a 100644 --- a/internal/clients/customer.go +++ b/internal/clients/customer.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/gofiber/fiber/v2" "go.uber.org/zap" - "mailnotifier/internal/models" + "gitea.pena/PenaSide/notifier/internal/models" ) type Customer struct { diff --git a/internal/clients/quiz_rpc.go b/internal/clients/quiz_rpc.go index 10ea998..aacbb8d 100644 --- a/internal/clients/quiz_rpc.go +++ b/internal/clients/quiz_rpc.go @@ -5,7 +5,7 @@ import ( "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "mailnotifier/internal/proto/notifyer" + "gitea.pena/PenaSide/notifier/internal/proto/notifyer" ) type QuizClient struct { diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 90161ed..6c45da1 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -5,7 +5,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" - "mailnotifier/internal/models" + "gitea.pena/PenaSide/notifier/internal/models" "time" ) diff --git a/internal/workers/consumer.go b/internal/workers/consumer.go index 419ba07..dfdd2d8 100644 --- a/internal/workers/consumer.go +++ b/internal/workers/consumer.go @@ -7,9 +7,9 @@ import ( "fmt" "github.com/twmb/franz-go/pkg/kgo" "go.uber.org/zap" - "mailnotifier/internal/clients" - "mailnotifier/internal/models" - "mailnotifier/internal/repository" + "gitea.pena/PenaSide/notifier/internal/clients" + "gitea.pena/PenaSide/notifier/internal/models" + "gitea.pena/PenaSide/notifier/internal/repository" "time" ) diff --git a/internal/workers/notifyer.go b/internal/workers/notifyer.go index 8a83f0e..c6f5b05 100644 --- a/internal/workers/notifyer.go +++ b/internal/workers/notifyer.go @@ -4,9 +4,9 @@ import ( "context" _ "embed" "go.uber.org/zap" - "mailnotifier/internal/clients" - "mailnotifier/internal/proto/notifyer" - "mailnotifier/internal/repository" + "gitea.pena/PenaSide/notifier/internal/clients" + "gitea.pena/PenaSide/notifier/internal/proto/notifyer" + "gitea.pena/PenaSide/notifier/internal/repository" "time" ) diff --git a/internal/workers/welcomer.go b/internal/workers/welcomer.go index 7d5337f..451c518 100644 --- a/internal/workers/welcomer.go +++ b/internal/workers/welcomer.go @@ -5,9 +5,9 @@ package workers // "context" // _ "embed" // "go.uber.org/zap" -// "mailnotifier/internal/clients" -// "mailnotifier/internal/models" -// "mailnotifier/internal/repository" +// "gitea.pena/PenaSide/notifier/internal/clients" +// "gitea.pena/PenaSide/notifier/internal/models" +// "gitea.pena/PenaSide/notifier/internal/repository" //) // ////go:embed mail/register.tmpl diff --git a/test/core_test.go b/test/core_test.go index a15c14b..57e4b9e 100644 --- a/test/core_test.go +++ b/test/core_test.go @@ -4,8 +4,8 @@ import ( "context" "fmt" "go.uber.org/zap" - "mailnotifier/internal/clients" - "mailnotifier/internal/proto/notifyer" + "gitea.pena/PenaSide/notifier/internal/clients" + "gitea.pena/PenaSide/notifier/internal/proto/notifyer" "testing" ) diff --git a/test/kafka_test.go b/test/kafka_test.go index 0794d17..9658efb 100644 --- a/test/kafka_test.go +++ b/test/kafka_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "github.com/twmb/franz-go/pkg/kgo" - "mailnotifier/internal/models" + "gitea.pena/PenaSide/notifier/internal/models" "testing" "time" ) diff --git a/test/repo_test.go b/test/repo_test.go index 33712c6..c82f584 100644 --- a/test/repo_test.go +++ b/test/repo_test.go @@ -3,9 +3,9 @@ package test import ( "context" "fmt" - "mailnotifier/internal/initialize" - "mailnotifier/internal/models" - "mailnotifier/internal/repository" + "gitea.pena/PenaSide/notifier/internal/initialize" + "gitea.pena/PenaSide/notifier/internal/models" + "gitea.pena/PenaSide/notifier/internal/repository" "testing" "time" ) -- 2.45.2 From b7fe31199c112348987b6f560d65a0111ca9a992 Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 25 Nov 2024 11:33:23 +0300 Subject: [PATCH 2/9] update package common --- go.mod | 2 +- go.sum | 4 ++-- internal/initialize/mongo.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 4ddf118..4a6f48f 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module gitea.pena/PenaSide/notifier go 1.21.6 require ( + gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562 github.com/caarlos0/env/v8 v8.0.0 github.com/gofiber/fiber/v2 v2.51.0 github.com/joho/godotenv v1.5.1 @@ -11,7 +12,6 @@ require ( go.uber.org/zap v1.27.0 google.golang.org/grpc v1.63.0 google.golang.org/protobuf v1.33.0 - penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 ) require ( diff --git a/go.sum b/go.sum index 7a9b6fb..d1a4b29 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562 h1:LobhWlICMcbCCI+SouOzeRk2K5MsXSVHtv3QOcHRZnY= +gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= @@ -103,5 +105,3 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA= -penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= diff --git a/internal/initialize/mongo.go b/internal/initialize/mongo.go index 3039823..ec0456c 100644 --- a/internal/initialize/mongo.go +++ b/internal/initialize/mongo.go @@ -2,8 +2,8 @@ package initialize import ( "context" + mg "gitea.pena/PenaSide/common/mongo" "go.mongodb.org/mongo-driver/mongo" - mg "penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo" "time" ) -- 2.45.2 From 93ef98fe248404e4a53f6b2c7cc915496a23feed Mon Sep 17 00:00:00 2001 From: Pasha Date: Fri, 29 Nov 2024 10:38:24 +0300 Subject: [PATCH 3/9] update mongo init --- .env | 8 ++------ go.mod | 2 +- go.sum | 4 ++-- internal/app/app.go | 2 +- internal/initialize/config.go | 30 +++++++++++++----------------- internal/initialize/mongo.go | 11 +---------- test/repo_test.go | 11 +++++------ 7 files changed, 25 insertions(+), 43 deletions(-) diff --git a/.env b/.env index 3ce0765..79df6ad 100644 --- a/.env +++ b/.env @@ -1,10 +1,6 @@ # MongoDB settings -MONGO_HOST="127.0.0.1" -MONGO_PORT="27020" -MONGO_USER="test" -MONGO_PASSWORD="test" -MONGO_DB="admin" -MONGO_AUTH="admin" +MONGO_URL = "mongodb://test:test@localhost:27020/" +MONGO_DB_NAME = "admin" # Kafka settings KAFKA_BROKERS="localhost:9092" diff --git a/go.mod b/go.mod index 4a6f48f..5410710 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitea.pena/PenaSide/notifier go 1.21.6 require ( - gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562 + gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1 github.com/caarlos0/env/v8 v8.0.0 github.com/gofiber/fiber/v2 v2.51.0 github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum index d1a4b29..f98032b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562 h1:LobhWlICMcbCCI+SouOzeRk2K5MsXSVHtv3QOcHRZnY= -gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw= +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= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= diff --git a/internal/app/app.go b/internal/app/app.go index 6764e8f..b5e50d1 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -2,11 +2,11 @@ package app import ( "context" - "go.uber.org/zap" "gitea.pena/PenaSide/notifier/internal/clients" "gitea.pena/PenaSide/notifier/internal/initialize" "gitea.pena/PenaSide/notifier/internal/repository" "gitea.pena/PenaSide/notifier/internal/workers" + "go.uber.org/zap" ) func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error { diff --git a/internal/initialize/config.go b/internal/initialize/config.go index 6295e64..be1d0b3 100644 --- a/internal/initialize/config.go +++ b/internal/initialize/config.go @@ -1,29 +1,25 @@ package initialize import ( + "gitea.pena/PenaSide/common/mongo" "github.com/caarlos0/env/v8" "github.com/joho/godotenv" "log" ) type Config struct { - MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"` - MongoPort string `env:"MONGO_PORT" envDefault:"27020"` - MongoUser string `env:"MONGO_USER" envDefault:"test"` - MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"` - MongoDatabase string `env:"MONGO_DB" envDefault:"admin"` - MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"` - 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"` + 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 } func LoadConfig() (*Config, error) { diff --git a/internal/initialize/mongo.go b/internal/initialize/mongo.go index ec0456c..920c575 100644 --- a/internal/initialize/mongo.go +++ b/internal/initialize/mongo.go @@ -11,17 +11,8 @@ func MongoInit(ctx context.Context, config Config) (*mongo.Database, error) { newCtx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() - cfg := mg.Configuration{ - Host: config.MongoHost, - Port: config.MongoPort, - User: config.MongoUser, - Password: config.MongoPassword, - Auth: config.MongoAuth, - DatabaseName: config.MongoDatabase, - } - deps := mg.ConnectDeps{ - Configuration: &cfg, + Configuration: &config.DataBase, Timeout: 10 * time.Second, } diff --git a/test/repo_test.go b/test/repo_test.go index c82f584..21d6b39 100644 --- a/test/repo_test.go +++ b/test/repo_test.go @@ -3,6 +3,7 @@ package test import ( "context" "fmt" + "gitea.pena/PenaSide/common/mongo" "gitea.pena/PenaSide/notifier/internal/initialize" "gitea.pena/PenaSide/notifier/internal/models" "gitea.pena/PenaSide/notifier/internal/repository" @@ -13,12 +14,10 @@ import ( func TestInsertAndGetMany(t *testing.T) { crx := context.Background() mdb, err := initialize.MongoInit(crx, initialize.Config{ - MongoHost: "127.0.0.1", - MongoPort: "27020", - MongoUser: "test", - MongoPassword: "test", - MongoDatabase: "admin", - MongoAuth: "admin", + DataBase: mongo.Configuration{ + URL: "mongodb://test:test@localhost:27020/", + DatabaseName: "admin", + }, }) if err != nil { panic(err) -- 2.45.2 From d312604e9703c2682ee419efced43eb35403ddbe Mon Sep 17 00:00:00 2001 From: skeris Date: Sat, 14 Dec 2024 15:53:42 +0300 Subject: [PATCH 4/9] add ci --- .gitea/workflows/deploy.yml | 24 ++++++++++++++++++++++++ .gitea/workflows/lint.yml | 14 ++++++++++++++ .gitlab-ci.yml | 13 ------------- Taskfile.dist.yml | 10 ++++++++++ cmd/main.go | 1 + go.mod | 5 ++++- go.sum | 2 ++ 7 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 .gitea/workflows/deploy.yml create mode 100644 .gitea/workflows/lint.yml delete mode 100644 .gitlab-ci.yml create mode 100644 Taskfile.dist.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..2c2d232 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,24 @@ +name: Deploy +run-name: ${{ gitea.actor }} build image and push to container registry + +on: + push: + branches: + - 'main' + - 'staging' + +jobs: + CreateImage: + runs-on: [hubstaging] + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.5 + with: + runner: hubstaging + secrets: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + DeployService: + runs-on: [hubstaging] + needs: CreateImage + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.4-p7 + with: + runner: hubstaging diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..0bd7867 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,14 @@ +name: Lint +run-name: ${{ gitea.actor }} produce linting + +on: + push: + branches: + - 'dev' + +jobs: + Lint: + runs-on: [hubstaging] + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/lint.yml@v1.1.2 + with: + runner: hubstaging diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index fef13ef..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,13 +0,0 @@ -# You can override the included template(s) by including variable overrides -# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings -# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings -# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings -# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings -# Note that environment variables can be set in several places -# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence -stages: -- test -sast: - stage: test -include: -- template: Security/SAST.gitlab-ci.yml diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml new file mode 100644 index 0000000..bac807b --- /dev/null +++ b/Taskfile.dist.yml @@ -0,0 +1,10 @@ +version: "3" + +tasks: + update-linter: + cmds: + - go get -u gitea.pena/PenaSide/linters-golang + lint: + cmds: + - task: update-linter + - cmd: golangci-lint run -v -c $(go list -f '{{"{{"}}.Dir{{"}}"}}' -m gitea.pena/PenaSide/linters-golang)/.golangci.yml diff --git a/cmd/main.go b/cmd/main.go index 3ac0897..3413587 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" "syscall" + _ "gitea.pena/PenaSide/linters-golang/pkg/dummy" ) func main() { diff --git a/go.mod b/go.mod index 5410710..14d1c87 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module gitea.pena/PenaSide/notifier -go 1.21.6 +go 1.22.0 + +toolchain go1.23.2 require ( gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1 @@ -15,6 +17,7 @@ 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 diff --git a/go.sum b/go.sum index f98032b..7a3a940 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ 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/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= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= -- 2.45.2 From 3178a5d5d5ba8054c0601e7e3f779cb6527ae54b Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 16 Dec 2024 14:17:25 +0300 Subject: [PATCH 5/9] optimized cfg --- .env | 16 +++++-------- go.mod | 20 ++++++++-------- go.sum | 32 +++++++++++++------------- internal/app/app.go | 15 +++--------- internal/clients/mail.go | 43 ++++++++++++++++------------------- internal/initialize/config.go | 32 ++++++++++++++++---------- internal/initialize/kafka.go | 2 +- internal/initialize/mongo.go | 2 +- test/repo_test.go | 8 ++++--- 9 files changed, 82 insertions(+), 88 deletions(-) diff --git a/.env b/.env index 79df6ad..569b59a 100644 --- a/.env +++ b/.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" \ No newline at end of file +CUSTOMER_MICROSERVICE_GRPC_URL = "http://localhost:8080" +QUIZ_CORE_MICROSERVICE_GRPC_URL = "localhost:9000" \ No newline at end of file diff --git a/go.mod b/go.mod index 14d1c87..7111098 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index 7a3a940..d201ece 100644 --- a/go.sum +++ b/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= diff --git a/internal/app/app.go b/internal/app/app.go index b5e50d1..54bbe74 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -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, }) diff --git a/internal/clients/mail.go b/internal/clients/mail.go index eea63d1..ca0499f 100644 --- a/internal/clients/mail.go +++ b/internal/clients/mail.go @@ -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 } diff --git a/internal/initialize/config.go b/internal/initialize/config.go index be1d0b3..56aa923 100644 --- a/internal/initialize/config.go +++ b/internal/initialize/config.go @@ -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) { diff --git a/internal/initialize/kafka.go b/internal/initialize/kafka.go index cdb3d17..cc42676 100644 --- a/internal/initialize/kafka.go +++ b/internal/initialize/kafka.go @@ -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 { diff --git a/internal/initialize/mongo.go b/internal/initialize/mongo.go index 920c575..6df27cc 100644 --- a/internal/initialize/mongo.go +++ b/internal/initialize/mongo.go @@ -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, } diff --git a/test/repo_test.go b/test/repo_test.go index 21d6b39..c930b7d 100644 --- a/test/repo_test.go +++ b/test/repo_test.go @@ -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 { -- 2.45.2 From daa0b892434bed88c1e532a4043abe891e0ea537 Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 16 Dec 2024 14:54:41 +0300 Subject: [PATCH 6/9] added ful logic for validate cfg --- cmd/validator/main.go | 73 +++++++++++++++++++++++++++++++++++++++++++ go.mod | 16 +++++++--- go.sum | 39 ++++++++++++++++++----- 3 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 cmd/validator/main.go diff --git a/cmd/validator/main.go b/cmd/validator/main.go new file mode 100644 index 0000000..b4f9218 --- /dev/null +++ b/cmd/validator/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "errors" + "gitea.pena/PenaSide/common/validate" + "gitea.pena/PenaSide/notifier/internal/initialize" + "github.com/caarlos0/env/v8" + "log" +) + +func main() { + cfg, err := loadConfig() + if err != nil { + log.Fatalf("Error loading config: %v", err) + } + + if err = validateNotEmpty([]string{ + cfg.CustomerMicroserviceGRPC, + cfg.QuizCoreMicroserviceGRPC, + }); err != nil { + log.Fatalf("Error validating not empty values: %v", err) + } + + if err = validateSMTP(cfg.External.MailClientCfg); err != nil { + log.Fatalf("Error validating SMTP: %v", err) + } + + if err = validate.ValidateMongo(cfg.External.Database); err != nil { + log.Fatalf("Error validating Mongo: %v", err) + } + + if err = validate.ValidateKafka([]string{cfg.KafkaBrokers}, cfg.KafkaTopicMailNotifier); err != nil { + log.Fatalf("Error validating Kafka: %v", err) + } + +} + +func loadConfig() (*initialize.Config, error) { + var cfg initialize.Config + if err := env.Parse(&cfg); err != nil { + return nil, err + } + return &cfg, nil +} + +func validateNotEmpty(values []string) error { + for _, value := range values { + if value == "" { + return errors.New("important cfg value is empty") + } + } + return nil +} + +func validateSMTP(cfg initialize.MailClientCfg) error { + if cfg.Sender == "" { + return errors.New("smtp sender is empty") + } + + if cfg.ApiURL == "" { + return errors.New("smtp api url is empty") + } + + if cfg.ApiKey == "" { + return errors.New("smtp api key is empty") + } + + err := validate.ValidateSmtp(cfg.ApiKey) + if err != nil { + return err + } + return nil +} diff --git a/go.mod b/go.mod index 7111098..e9567bd 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,12 @@ go 1.23.2 toolchain go1.23.3 require ( - gitea.pena/PenaSide/common v0.0.0-20241213122118-5fbc737eb63e + gitea.pena/PenaSide/common v0.0.0-20241216115106-ecdff721f8a3 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 - github.com/twmb/franz-go v1.16.1 + github.com/twmb/franz-go v1.18.0 go.mongodb.org/mongo-driver v1.14.0 go.uber.org/zap v1.27.0 google.golang.org/grpc v1.63.0 @@ -19,16 +19,24 @@ require ( require ( github.com/andybalholm/brotli v1.0.5 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/go-ini/ini v1.67.0 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/golang/snappy v0.0.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.17.11 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // 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 + github.com/minio/md5-simd v1.1.2 // indirect + github.com/minio/minio-go/v7 v7.0.81 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect - github.com/pierrec/lz4/v4 v4.1.19 // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect + github.com/pioz/faker v1.7.3 // indirect github.com/rivo/uniseg v0.2.0 // indirect - github.com/twmb/franz-go/pkg/kmsg v1.7.0 // indirect + github.com/rs/xid v1.6.0 // indirect + github.com/twmb/franz-go/pkg/kmsg v1.9.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.50.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect diff --git a/go.sum b/go.sum index d201ece..58bc858 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,20 @@ -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/common v0.0.0-20241216115106-ecdff721f8a3 h1:oZenr/Am7+/8ZPLhpW13cJQ0c+usnqKZiWw8cXE6E1Q= +gitea.pena/PenaSide/common v0.0.0-20241216115106-ecdff721f8a3/go.mod h1:U7QFuvkrIWyb/m/SOyrsroS7DJntjcr9k7kNy3vtPdU= 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= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ= github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= @@ -20,6 +27,9 @@ 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.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= +github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 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= @@ -27,20 +37,30 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= +github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= +github.com/minio/minio-go/v7 v7.0.81 h1:SzhMN0TQ6T/xSBu6Nvw3M5M8voM+Ht8RH3hE8S7zxaA= +github.com/minio/minio-go/v7 v7.0.81/go.mod h1:84gmIilaX4zcvAWWzJ5Z1WI5axN+hAbM5w25xf8xvC0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/pierrec/lz4/v4 v4.1.19 h1:tYLzDnjDXh9qIxSTKHwXwOYmm9d887Y7Y1ZkyXYHAN4= -github.com/pierrec/lz4/v4 v4.1.19/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pioz/faker v1.7.3 h1:Tez8Emuq0UN+/d6mo3a9m/9ZZ/zdfJk0c5RtRatrceM= +github.com/pioz/faker v1.7.3/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= -github.com/twmb/franz-go/pkg/kmsg v1.7.0/go.mod h1:se9Mjdt0Nwzc9lnjJ0HyDtLyBnaBDAd7pCje47OhSyw= +github.com/twmb/franz-go v1.18.0 h1:25FjMZfdozBywVX+5xrWC2W+W76i0xykKjTdEeD2ejw= +github.com/twmb/franz-go v1.18.0/go.mod h1:zXCGy74M0p5FbXsLeASdyvfLFsBvTubVqctIaa5wQ+I= +github.com/twmb/franz-go/pkg/kmsg v1.9.0 h1:JojYUph2TKAau6SBtErXpXGC7E3gg4vGZMv9xFU/B6M= +github.com/twmb/franz-go/pkg/kmsg v1.9.0/go.mod h1:CMbfazviCyY6HM0SXuG5t9vOwYDHRCSrJJyBAe5paqg= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= @@ -84,6 +104,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -105,5 +126,7 @@ google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8= google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -- 2.45.2 From 20dcb01f550634b888ecca4be1d75b149a231482 Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 16 Dec 2024 15:07:19 +0300 Subject: [PATCH 7/9] fix lint --- internal/clients/customer.go | 4 ++-- internal/clients/errors.go | 7 +++++++ internal/clients/mail.go | 4 ++-- internal/clients/quiz_rpc.go | 13 ++++++++----- internal/repository/repository.go | 21 +++++++++++---------- 5 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 internal/clients/errors.go diff --git a/internal/clients/customer.go b/internal/clients/customer.go index d4fd35a..6c19c47 100644 --- a/internal/clients/customer.go +++ b/internal/clients/customer.go @@ -3,9 +3,9 @@ package clients import ( "encoding/json" "fmt" + "gitea.pena/PenaSide/notifier/internal/models" "github.com/gofiber/fiber/v2" "go.uber.org/zap" - "gitea.pena/PenaSide/notifier/internal/models" ) type Customer struct { @@ -41,7 +41,7 @@ func (c *Customer) GetAccount(userID string) (models.Account, error) { statusCode, body, errs := resp.Bytes() if errs != nil { - c.logger.Error("Error sending request:", zap.Error(errs[0])) + c.logger.Error(errSendingRequest.Error(), zap.Error(errs[0])) return account, errs[0] } diff --git a/internal/clients/errors.go b/internal/clients/errors.go new file mode 100644 index 0000000..2e98cf7 --- /dev/null +++ b/internal/clients/errors.go @@ -0,0 +1,7 @@ +package clients + +import "errors" + +var ( + errSendingRequest = errors.New("error sending request") +) diff --git a/internal/clients/mail.go b/internal/clients/mail.go index eea63d1..824f884 100644 --- a/internal/clients/mail.go +++ b/internal/clients/mail.go @@ -82,12 +82,12 @@ func (m *MailClient) MailSender(data SenderDeps) error { statusCode, body, errs := req.Bytes() if errs != nil { - m.deps.Logger.Error("Error sending request:", zap.Error(errs[0])) + m.deps.Logger.Error(errSendingRequest.Error(), 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) + err = fmt.Errorf("the SMTP service returned an error: %d Response body: %s", statusCode, body) m.deps.Logger.Error("Error sending email:", zap.Error(err)) return err } diff --git a/internal/clients/quiz_rpc.go b/internal/clients/quiz_rpc.go index aacbb8d..5d6ef46 100644 --- a/internal/clients/quiz_rpc.go +++ b/internal/clients/quiz_rpc.go @@ -2,10 +2,10 @@ package clients import ( "context" + "gitea.pena/PenaSide/notifier/internal/proto/notifyer" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "gitea.pena/PenaSide/notifier/internal/proto/notifyer" ) type QuizClient struct { @@ -20,10 +20,13 @@ func NewQuizClient(address string, logger *zap.Logger) *QuizClient { } } +var coreRpcHost = "core rpc host" +var request = "request" + func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesRequest) (*notifyer.GetQuizzesResponse, error) { connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - q.logger.Error("failed to connect on GetQuizzes of core rpc", zap.Error(err), zap.String("core rpc host", q.address)) + q.logger.Error("failed to connect on GetQuizzes of core rpc", zap.Error(err), zap.String(coreRpcHost, q.address)) return nil, err } defer func() { @@ -36,7 +39,7 @@ func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesReq response, err := client.GetQuizzes(ctx, req) if err != nil { - q.logger.Error("failed to GetQuizzes core rpc", zap.Error(err), zap.Any("request", req)) + q.logger.Error("failed to GetQuizzes core rpc", zap.Error(err), zap.Any(request, req)) return nil, err } @@ -46,7 +49,7 @@ func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesReq func (q *QuizClient) GetStartedQuizzes(ctx context.Context, req *notifyer.GetStartedQuizzesRequest) (*notifyer.GetStartedQuizzesResponse, error) { connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - q.logger.Error("failed to connect on GetStartedQuizzes of core rpc", zap.Error(err), zap.String("core rpc host", q.address)) + q.logger.Error("failed to connect on GetStartedQuizzes of core rpc", zap.Error(err), zap.String(coreRpcHost, q.address)) return nil, err } defer func() { @@ -59,7 +62,7 @@ func (q *QuizClient) GetStartedQuizzes(ctx context.Context, req *notifyer.GetSta response, err := client.GetStartedQuizzes(ctx, req) if err != nil { - q.logger.Error("failed to GetStartedQuizzes core rpc", zap.Error(err), zap.Any("request", req)) + q.logger.Error("failed to GetStartedQuizzes core rpc", zap.Error(err), zap.Any(request, req)) return nil, err } diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 6c45da1..0bd4aed 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -2,10 +2,11 @@ package repository import ( "context" + "errors" + "gitea.pena/PenaSide/notifier/internal/models" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" - "gitea.pena/PenaSide/notifier/internal/models" "time" ) @@ -39,18 +40,18 @@ func (r *Repository) GetMany(ctx context.Context) ([]models.Message, error) { from := time.Now().AddDate(0, 0, -7) filter := bson.D{ - {"$and", bson.A{ + {Key: "$and", Value: bson.A{ bson.D{ - {"$or", bson.A{ - bson.D{{"sendRegistration", false}}, - bson.D{{"sendNoneCreated", false}}, - bson.D{{"sendUnpublished", false}}, + {Key: "$or", Value: bson.A{ + bson.D{{Key: "sendRegistration", Value: false}}, + bson.D{{Key: "sendNoneCreated", Value: false}}, + bson.D{{Key: "sendUnpublished", Value: false}}, }}, }, bson.D{ - {"sendAt", bson.D{ - {"$gte", to}, - {"$lte", from}, + {Key: "sendAt", Value: bson.D{ + {Key: "$gte", Value: to}, + {Key: "$lte", Value: from}, }}, }, }}, @@ -58,7 +59,7 @@ func (r *Repository) GetMany(ctx context.Context) ([]models.Message, error) { cursor, err := r.mdb.Find(ctx, filter) if err != nil { - if err == mongo.ErrNoDocuments { + if errors.Is(err, mongo.ErrNoDocuments) { return []models.Message{}, nil } return nil, err -- 2.45.2 From b63de617246e57d95fe6551ec85ee0431a8a76a5 Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 16 Dec 2024 15:07:58 +0300 Subject: [PATCH 8/9] - --- .gitea/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 0bd7867..6a22dd0 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -4,7 +4,7 @@ run-name: ${{ gitea.actor }} produce linting on: push: branches: - - 'dev' + - 'fixlint' jobs: Lint: -- 2.45.2 From e2015da262f59b18d1814a2dbab30ed39944a957 Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 16 Dec 2024 16:22:00 +0300 Subject: [PATCH 9/9] - --- .gitea/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 6a22dd0..0bd7867 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -4,7 +4,7 @@ run-name: ${{ gitea.actor }} produce linting on: push: branches: - - 'fixlint' + - 'dev' jobs: Lint: -- 2.45.2