-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
48 lines (38 loc) · 1.09 KB
/
server.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 (
"fmt"
"os"
"github.com/Ericarthurc/GoFiber-Rest-API-Mongo_Template/database"
"github.com/Ericarthurc/GoFiber-Rest-API-Mongo_Template/models"
"github.com/Ericarthurc/GoFiber-Rest-API-Mongo_Template/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/joho/godotenv"
)
func main() {
// Load enviromental variables from config
godotenv.Load("./config/config.env")
// Create new fiber instance
app := fiber.New(fiber.Config{
// Prefork: true,
CaseSensitive: true,
StrictRouting: true,
ServerHeader: "Fiber",
})
// Connect to database
database.Connect()
defer database.Cancel()
defer database.Client.Disconnect(database.Ctx)
// Create model schemas
models.CreateUserSchema()
// Middleware
app.Use(logger.New())
app.Use(cors.New())
// Routes
routes.UserRoutes(app)
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
app.Listen(fmt.Sprintf(":%s", os.Getenv("PORT")))
}