forked from Taker-Academy/KeDuBak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 887 Bytes
/
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
package main
import (
"context"
"fmt"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
"KeDuBak/database"
"KeDuBak/routes"
)
func error_hanling(MongoURL *string) int {
err := godotenv.Load(".env")
if err != nil {
fmt.Print("Error : file .env not found\n")
return -1
}
*MongoURL = os.Getenv("MONGO_URL")
if *MongoURL == "" {
fmt.Print("Error : missing environment variables\n")
return -1
}
return 0
}
func main() {
var MongoURL string
if error_hanling(&MongoURL) == -1 {
os.Exit(1)
}
app := fiber.New()
client_mongo := database.ConnectDB(MongoURL)
defer func() {
if err := client_mongo.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()
app.Use(cors.New())
routes.Auth(app, client_mongo)
routes.User(app, client_mongo)
routes.Post(app, client_mongo)
app.Listen(":8080")
}