jokes-bapak2/api/main.go

59 lines
1.2 KiB
Go
Raw Normal View History

2021-05-02 07:49:13 +00:00
package main
import (
2021-05-02 07:58:37 +00:00
"log"
2021-07-09 06:11:11 +00:00
"os"
"time"
2021-05-02 07:49:13 +00:00
2021-07-09 06:11:11 +00:00
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/routes"
"github.com/getsentry/sentry-go"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/limiter"
2021-05-02 07:49:13 +00:00
)
func main() {
2021-07-09 06:11:11 +00:00
timeoutDefault, _ := time.ParseDuration("1m")
err := sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
// Enable printing of SDK debug messages.
// Useful when getting started or trying to figure something out.
Debug: true,
})
if err != nil {
log.Fatal(err)
}
defer sentry.Flush(2 * time.Second)
err = database.Setup()
if err != nil {
sentry.CaptureException(err)
log.Fatal(err)
2021-05-02 07:49:13 +00:00
}
2021-07-09 06:11:11 +00:00
app := fiber.New(fiber.Config{
ReadTimeout: timeoutDefault,
WriteTimeout: timeoutDefault,
ErrorHandler: errorHandler,
})
app.Use(cors.New())
app.Use(limiter.New())
app.Use(etag.New())
app.Mount("/", routes.New())
log.Fatal(app.Listen(":" + os.Getenv("PORT")))
}
func errorHandler(c *fiber.Ctx, err error) error {
sentry.CaptureException(err)
return c.Status(500).JSON(fiber.Map{
"error": "Something went wrong on our end",
})
2021-05-02 07:49:13 +00:00
}