chore: add qe and integrations with rabbit mq
This commit is contained in:
+33
-2
@@ -1,12 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/rostpoliplast/backend/docs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/rostpoliplast/backend/internal/handlers"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/rostpoliplast/backend/internal/mq"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/rostpoliplast/backend/internal/storage"
|
||||
)
|
||||
|
||||
// @securityDefinitions.apikey Bearer
|
||||
@@ -15,6 +22,31 @@ import (
|
||||
// @description Type "Bearer" followed by a space and the JWT token.
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
connStr := os.Getenv("DATABASE_URL")
|
||||
if connStr == "" {
|
||||
connStr = "postgres://postgres:postgres@localhost:5432/rostpoliplast?sslmode=disable"
|
||||
}
|
||||
|
||||
pool, err := pgxpool.New(ctx, connStr)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect to database: %v", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
if err := pool.Ping(ctx); err != nil {
|
||||
log.Fatalf("failed to ping database: %v", err)
|
||||
}
|
||||
|
||||
rabbit, err := mq.NewRabbitMQ()
|
||||
if err != nil {
|
||||
log.Printf("warning: failed to connect to rabbitmq: %v", err)
|
||||
}
|
||||
defer rabbit.Close()
|
||||
|
||||
repo := storage.NewRepository(pool)
|
||||
h := &handlers.Handlers{Repo: repo, MQ: rabbit}
|
||||
|
||||
router := gin.Default()
|
||||
v1 := router.Group("/api/v1")
|
||||
@@ -24,8 +56,7 @@ func main() {
|
||||
docs.SwaggerInfo.Version = "1.0"
|
||||
docs.SwaggerInfo.Schemes = []string{"http", "https"}
|
||||
|
||||
baleHandlers := &handlers.Handlers{}
|
||||
baleHandlers.RegisterRoutes(v1)
|
||||
h.RegisterRoutes(v1)
|
||||
|
||||
{
|
||||
v1.GET("/health", func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user