-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (54 loc) · 1.46 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"os"
"context"
"teslaUsers/src/configs"
"teslaUsers/src/controllers"
"teslaUsers/src/controllers/repointerfaces"
"teslaUsers/src/datasources"
"teslaUsers/src/middlewares"
"teslaUsers/src/models"
"teslaUsers/src/repositories"
"teslaUsers/src/routes"
"github.com/joho/godotenv"
"github.com/gofiber/fiber/v2"
)
func main() {
// Define Fiber config.
config := configs.FiberConfig()
// Define a new Fiber app with config.
app := fiber.New(config)
// Middlewares.
middlewares.FiberMiddleware(app) // Register Fiber's middleware for app.
err := godotenv.Load()
if err != nil {
panic(err)
}
mongoURI := os.Getenv("MONGO_URI")
mongoClient, err := datasources.NewMongoDataSource(mongoURI)
if err != nil {
panic(err)
}
defer mongoClient.Disconnect(context.TODO())
repo := repositories.NewUserMongoRepo(mongoClient, "TeslaDB")
// Esto es para cargar la db con algunos datos.
// loadUsers(repo)
// Creo una instancia de mis controladores con mi instancia de repo
controller := controllers.NewUserController(repo)
// Routes.
routes.PublicRoutes(app, controller)
// Aqui inicializamos el servidor en el puerto 8080
app.Listen(":8080")
}
func loadUsers(repo repointerfaces.UserRepo) {
repo.AddUser(models.User{
EMail : "juan@gmail.com",
UserName : "BigJuan",
Name : "Juan",
LastName : "Casanova",
BirthDay : "26-01-1999",
Country : "Uruguay",
Language : "es",
PaymentMethods : []string{"visa", "mastercard"},
})
}