2023-06-12 14:19:10 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-09 16:38:56 +00:00
|
|
|
"fmt"
|
2023-06-12 14:19:10 +00:00
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
2023-07-03 11:40:20 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/verification/internal/client"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/verification/internal/config"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/verification/internal/initialize"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/verification/internal/server"
|
2023-06-12 14:19:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Run(cfg *config.Config) {
|
|
|
|
cfgLogger := zap.NewDevelopmentConfig()
|
|
|
|
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
|
|
|
cfgLogger.EncoderConfig.ConsoleSeparator = " "
|
|
|
|
|
|
|
|
logger, err := cfgLogger.Build()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Info("RUN", zap.Any("ENV", cfg))
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2024-02-09 16:38:56 +00:00
|
|
|
fmt.Println(cfg.MongoUri)
|
|
|
|
|
|
|
|
mongoClient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
|
2023-06-12 14:19:10 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("MongoClient", zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
minioClient, err := minio.New(cfg.S3Endpoint, &minio.Options{
|
|
|
|
Creds: credentials.NewStaticV4(cfg.S3AccessKeyID, cfg.S3SecretKey, ""),
|
2023-07-03 16:55:26 +00:00
|
|
|
Secure: true,
|
2023-06-12 14:19:10 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("MinioClient", zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
reps, err := initialize.NewRepositories(ctx, logger, mongoClient, cfg.DatabaseName, minioClient)
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("Repositories", zap.Error(err))
|
|
|
|
}
|
2024-02-09 16:38:56 +00:00
|
|
|
//tgBot, err := tgbotapi.NewBotAPI(cfg.TelegramToken)
|
|
|
|
//if err != nil {
|
|
|
|
// logger.Fatal("TelegramBotApi", zap.Error(err))
|
|
|
|
//}
|
2023-06-12 14:19:10 +00:00
|
|
|
|
2024-02-09 16:38:56 +00:00
|
|
|
telegram := client.NewTelegram(logger, nil, cfg.TelegramChannelID)
|
2023-06-12 14:19:10 +00:00
|
|
|
cons := initialize.NewControllers(reps, telegram, client.NewCustomer(logger, cfg.CustomerSvcAddress))
|
|
|
|
|
|
|
|
httpSrv := server.NewHTTP(cfg, logger).Register(cons.List()...)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := httpSrv.Start()
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("CanNotServe", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
gracefulShutdown(ctx, logger, httpSrv, mongoClient)
|
|
|
|
}
|