-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (56 loc) · 1.4 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
70
71
72
73
package main
import (
"log"
"os"
"github.com/alekangelov/testament/database"
_ "github.com/alekangelov/testament/docs"
"github.com/alekangelov/testament/models"
"github.com/alekangelov/testament/router"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
"github.com/joho/godotenv"
)
// @title Testament API
// @version 1.0
// @description This is the API for Testament
// @license.name MIT
// @license.url /license.md
// @host localhost:8080
// @BasePath /
func main() {
err := godotenv.Load()
database.Connect()
database.Migrate()
address := os.Getenv("ADDRESS")
if address == "" {
address = ":8080"
}
app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
return c.Status(code).JSON(models.GlobalErrorHandlerResp{
Success: false,
Message: err.Error(),
})
},
})
app.Use(cors.New(
cors.Config{
AllowOrigins: "*",
AllowHeaders: "*",
AllowMethods: "*",
AllowCredentials: true,
},
))
app.Get("/swagger/*", swagger.HandlerDefault)
app.Get("/license", func(c *fiber.Ctx) error {
return c.SendFile("./license.md")
})
router.SetupRoutes(app)
err = app.Listen(address)
log.Fatal(err)
}