-
Notifications
You must be signed in to change notification settings - Fork 73
/
app.go
51 lines (38 loc) · 973 Bytes
/
app.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
package main
import (
"boilerplate/database"
"boilerplate/handlers"
"flag"
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
)
var (
port = flag.String("port", ":3000", "Port to listen on")
prod = flag.Bool("prod", false, "Enable prefork in Production")
)
func main() {
// Parse command-line flags
flag.Parse()
// Connected with database
database.Connect()
// Create fiber app
app := fiber.New(fiber.Config{
Prefork: *prod, // go run app.go -prod
})
// Middleware
app.Use(recover.New())
app.Use(logger.New())
// Create a /api/v1 endpoint
v1 := app.Group("/api/v1")
// Bind handlers
v1.Get("/users", handlers.UserList)
v1.Post("/users", handlers.UserCreate)
// Setup static files
app.Static("/", "./static/public")
// Handle not founds
app.Use(handlers.NotFound)
// Listen on port 3000
log.Fatal(app.Listen(*port)) // go run app.go -port=:3000
}