update mongo init
This commit is contained in:
parent
b7fe31199c
commit
93ef98fe24
8
.env
8
.env
@ -1,10 +1,6 @@
|
|||||||
# MongoDB settings
|
# MongoDB settings
|
||||||
MONGO_HOST="127.0.0.1"
|
MONGO_URL = "mongodb://test:test@localhost:27020/"
|
||||||
MONGO_PORT="27020"
|
MONGO_DB_NAME = "admin"
|
||||||
MONGO_USER="test"
|
|
||||||
MONGO_PASSWORD="test"
|
|
||||||
MONGO_DB="admin"
|
|
||||||
MONGO_AUTH="admin"
|
|
||||||
|
|
||||||
# Kafka settings
|
# Kafka settings
|
||||||
KAFKA_BROKERS="localhost:9092"
|
KAFKA_BROKERS="localhost:9092"
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module gitea.pena/PenaSide/notifier
|
|||||||
go 1.21.6
|
go 1.21.6
|
||||||
|
|
||||||
require (
|
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/caarlos0/env/v8 v8.0.0
|
||||||
github.com/gofiber/fiber/v2 v2.51.0
|
github.com/gofiber/fiber/v2 v2.51.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
4
go.sum
4
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-20241128160655-fe730a08b5f1 h1:w1AAxrlZGmxUI9NAa/0TYsc6sqWWF9yAzQaLL/KxwrM=
|
||||||
gitea.pena/PenaSide/common v0.0.0-20241120141501-1695a0981562/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw=
|
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 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
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 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
|
||||||
|
@ -2,11 +2,11 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"go.uber.org/zap"
|
|
||||||
"gitea.pena/PenaSide/notifier/internal/clients"
|
"gitea.pena/PenaSide/notifier/internal/clients"
|
||||||
"gitea.pena/PenaSide/notifier/internal/initialize"
|
"gitea.pena/PenaSide/notifier/internal/initialize"
|
||||||
"gitea.pena/PenaSide/notifier/internal/repository"
|
"gitea.pena/PenaSide/notifier/internal/repository"
|
||||||
"gitea.pena/PenaSide/notifier/internal/workers"
|
"gitea.pena/PenaSide/notifier/internal/workers"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error {
|
func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error {
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
package initialize
|
package initialize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.pena/PenaSide/common/mongo"
|
||||||
"github.com/caarlos0/env/v8"
|
"github.com/caarlos0/env/v8"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"`
|
KafkaBrokers string `env:"KAFKA_BROKERS"`
|
||||||
MongoPort string `env:"MONGO_PORT" envDefault:"27020"`
|
KafkaTopic string `env:"KAFKA_TOPIC_TARIFF"`
|
||||||
MongoUser string `env:"MONGO_USER" envDefault:"test"`
|
SmtpApiUrl string `env:"SMTP_API_URL"`
|
||||||
MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"`
|
SmtpHost string `env:"SMTP_HOST"`
|
||||||
MongoDatabase string `env:"MONGO_DB" envDefault:"admin"`
|
SmtpPort string `env:"SMTP_PORT"`
|
||||||
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
|
SmtpUsername string `env:"SMTP_UNAME"`
|
||||||
KafkaBrokers string `env:"KAFKA_BROKERS"`
|
SmtpPassword string `env:"SMTP_PASS"`
|
||||||
KafkaTopic string `env:"KAFKA_TOPIC_TARIFF"`
|
SmtpApiKey string `env:"SMTP_API_KEY"`
|
||||||
SmtpApiUrl string `env:"SMTP_API_URL"`
|
SmtpSender string `env:"SMTP_SENDER"`
|
||||||
SmtpHost string `env:"SMTP_HOST"`
|
CustomerURL string `env:"CUSTOMER_URL"`
|
||||||
SmtpPort string `env:"SMTP_PORT"`
|
QuizRPCURL string `enc:"QUIZ_RPC_URL"`
|
||||||
SmtpUsername string `env:"SMTP_UNAME"`
|
DataBase mongo.Configuration
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
|
@ -11,17 +11,8 @@ func MongoInit(ctx context.Context, config Config) (*mongo.Database, error) {
|
|||||||
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||||
defer cancel()
|
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{
|
deps := mg.ConnectDeps{
|
||||||
Configuration: &cfg,
|
Configuration: &config.DataBase,
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitea.pena/PenaSide/common/mongo"
|
||||||
"gitea.pena/PenaSide/notifier/internal/initialize"
|
"gitea.pena/PenaSide/notifier/internal/initialize"
|
||||||
"gitea.pena/PenaSide/notifier/internal/models"
|
"gitea.pena/PenaSide/notifier/internal/models"
|
||||||
"gitea.pena/PenaSide/notifier/internal/repository"
|
"gitea.pena/PenaSide/notifier/internal/repository"
|
||||||
@ -13,12 +14,10 @@ import (
|
|||||||
func TestInsertAndGetMany(t *testing.T) {
|
func TestInsertAndGetMany(t *testing.T) {
|
||||||
crx := context.Background()
|
crx := context.Background()
|
||||||
mdb, err := initialize.MongoInit(crx, initialize.Config{
|
mdb, err := initialize.MongoInit(crx, initialize.Config{
|
||||||
MongoHost: "127.0.0.1",
|
DataBase: mongo.Configuration{
|
||||||
MongoPort: "27020",
|
URL: "mongodb://test:test@localhost:27020/",
|
||||||
MongoUser: "test",
|
DatabaseName: "admin",
|
||||||
MongoPassword: "test",
|
},
|
||||||
MongoDatabase: "admin",
|
|
||||||
MongoAuth: "admin",
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user