-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
57 lines (45 loc) · 892 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
49
50
51
52
53
54
55
56
57
package main
import (
"os"
"github.com/bmdavis419/fiber-mongo-example/common"
"github.com/bmdavis419/fiber-mongo-example/router"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
)
func main() {
err := run()
if err != nil {
panic(err)
}
}
func run() error {
// init env
err := common.LoadEnv()
if err != nil {
return err
}
// init db
err = common.InitDB()
if err != nil {
return err
}
// defer closing db
defer common.CloseDB()
// create app
app := fiber.New()
// add basic middleware
app.Use(logger.New())
app.Use(recover.New())
app.Use(cors.New())
// add routes
router.AddBookGroup(app)
// start server
var port string
if port = os.Getenv("PORT"); port == "" {
port = "8080"
}
app.Listen(":" + port)
return nil
}