-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (52 loc) · 1.41 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
61
62
63
64
65
66
67
68
69
package main
import (
"log"
"os"
"os/signal"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.yanuarizal.net/go-restful-product/cmd"
"github.yanuarizal.net/go-restful-product/config"
"github.yanuarizal.net/go-restful-product/database"
"github.yanuarizal.net/go-restful-product/router"
_ "github.com/joho/godotenv/autoload"
_ "github.yanuarizal.net/go-restful-product/docs"
)
// @title Go Restful Test
// @version 1.0
// @description This is a sample restful api with fiber, gorm & testing.
// @contact.name Yanuarizal K
// @contact.url https://www.yanuarizal.net
// @contact.email [email protected]
// @host localhost:3000
// @BasePath /
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
err := database.Connect(config.Database)
if err != nil {
panic(err)
}
cmd.Execute()
app := fiber.New(config.Fiber)
app.Use(logger.New(), recover.New())
router.RegisterRoutes(app)
start(app)
}
func start(app *fiber.App) {
conn := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
<-sigint
if err := app.Shutdown(); err != nil {
log.Println(err)
}
close(conn)
}()
if err := app.Listen(config.App.ListenAddr); err != nil {
log.Println(err)
}
<-conn
}