-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (50 loc) · 1.54 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
package main
import (
"gofiber-gorm/src/pkg/config"
"gofiber-gorm/src/routes"
"log"
"strconv"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/gofiber/helmet/v2"
_ "gofiber-gorm/docs"
)
// @title API Documentation
// @version 1.0
// @description This is an auto-generated API Docs.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @BasePath /
func main() {
app := fiber.New()
port := config.Env("APP_PORT", "8000")
envRateLimit := config.Env("RATE_LIMIT", "10")
rateLimit, _ := strconv.Atoi(envRateLimit)
// default middleware
app.Use(cors.New(config.Cors()))
app.Use(compress.New())
app.Use(helmet.New())
app.Use(logger.New())
app.Use(limiter.New(limiter.Config{Max: rateLimit}))
app.Use(requestid.New())
app.Use(recover.New())
// static file
app.Static("/", "./public")
// Connect to the Database
config.ConnectDB()
// initial app route
routes.Initialize(app)
// listening app
log.Fatal(app.Listen(":" + port))
}