-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (28 loc) · 770 Bytes
/
main.go
File metadata and controls
36 lines (28 loc) · 770 Bytes
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
package main
import (
"context"
"os"
"github.com/Danztee/url-shortener/config"
"github.com/Danztee/url-shortener/routes"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
)
func main() {
err := godotenv.Load()
if err != nil {
logrus.WithField("error", err.Error()).Fatal("Error loading .env file")
}
client := config.ConnectDB()
defer func() {
if err := client.Disconnect(context.TODO()); err != nil {
logrus.WithField("error", err.Error()).Error("Error disconnecting from database")
}
}()
server := gin.Default()
routes.RegisterRoutes(server, client)
port := os.Getenv("PORT")
if err := server.Run(":" + port); err != nil {
logrus.WithField("error", err.Error()).Fatal("Failed to start server")
}
}