-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (39 loc) · 1.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"TODOproject/config"
"TODOproject/todo"
"TODOproject/user"
)
func main() {
cfg := config.NewConfig()
// MongoDB bağlantı ayarları
clientOptions := options.Client().ApplyURI(cfg.MongoDB.ConnectionURL)
client, err := mongo.Connect(context.Background(), clientOptions)
if err != nil {
log.Fatalf("MongoDB bağlantı hatası: %v", err)
}
defer client.Disconnect(context.Background())
// Todo Repository, Service ve Handler'larını oluştur
todoRepo := todo.NewTodoRepository(client, cfg.MongoDB.DatabaseName)
todoService := todo.NewTodoService(todoRepo)
todoHandler := todo.NewTodoHandler(todoService)
// User Repository, Service ve Handler'larını oluştur
userRepo := user.NewUserRepository(client, cfg.MongoDB.DatabaseName)
userService := user.NewUserService(userRepo)
userHandler := user.NewUserHandler(userService)
// Fiber uygulaması
app := fiber.New()
// Middleware'ler
app.Use(logger.New())
// Routerlar
todoHandler.RegisterRoutes(app)
userHandler.RegisterRoutes(app)
// Uygulamayı belirtilen port üzerinden dinle
log.Fatal(app.Listen(":" + cfg.Server.Port))
}