feat: rabbitMQ is now calling from seatchtitles

This commit is contained in:
Iron_Felix 2025-11-30 02:57:11 +03:00
parent c6cebb0ed2
commit 77a63a1c74
7 changed files with 237 additions and 124 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"net/http"
sqlc "nyanimedb/sql"
"os"
"reflect"
@ -10,11 +11,14 @@ import (
oapi "nyanimedb/api"
handlers "nyanimedb/modules/backend/handlers"
"nyanimedb/modules/backend/rmq"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pelletier/go-toml/v2"
"github.com/rabbitmq/amqp091-go"
log "github.com/sirupsen/logrus"
)
var AppConfig Config
@ -43,7 +47,21 @@ func main() {
queries := sqlc.New(pool)
server := handlers.NewServer(queries)
// === RabbitMQ setup ===
rmqURL := os.Getenv("RABBITMQ_URL")
if rmqURL == "" {
rmqURL = "amqp://guest:guest@10.1.0.65:5672/"
}
rmqConn, err := amqp091.Dial(rmqURL)
if err != nil {
log.Fatalf("Failed to connect to RabbitMQ: %v", err)
}
defer rmqConn.Close()
publisher := rmq.NewPublisher(rmqConn)
server := handlers.NewServer(queries, publisher)
// r.LoadHTMLGlob("templates/*")
r.Use(cors.New(cors.Config{
@ -60,24 +78,15 @@ func main() {
// сюда можно добавить middlewares, если нужно
[]oapi.StrictMiddlewareFunc{},
))
// r.GET("/", func(c *gin.Context) {
// c.HTML(http.StatusOK, "index.html", gin.H{
// "title": "Welcome Page",
// "message": "Hello, Gin with HTML templates!",
// })
// })
// r.GET("/api", func(c *gin.Context) {
// items := []Item{
// {ID: 1, Title: "First Item", Description: "This is the description of the first item."},
// {ID: 2, Title: "Second Item", Description: "This is the description of the second item."},
// {ID: 3, Title: "Third Item", Description: "This is the description of the third item."},
// }
// Внедряем publisher в сервер
server = handlers.NewServer(queries, publisher)
// c.JSON(http.StatusOK, items)
// })
r.Run(":8080")
// Запуск
log.Infof("Server starting on :8080")
if err := r.Run(":8080"); err != nil && err != http.ErrServerClosed {
log.Fatalf("server failed: %v", err)
}
}
func InitConfig() error {