-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 1.2 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
package main
import (
"os"
"github.com/gofiber/fiber/v2"
_ "github.com/joho/godotenv/autoload" // load .env file automatically
_ "github.com/TheTNB/hitokoto-api/docs" // load API Docs files (Swagger)
"github.com/TheTNB/hitokoto-api/pkg/configs"
"github.com/TheTNB/hitokoto-api/pkg/middleware"
"github.com/TheTNB/hitokoto-api/pkg/routes"
"github.com/TheTNB/hitokoto-api/pkg/utils"
)
// @title Hitokoto
// @version 2.0
// @description Hitokoto API version 2.0
// @contact.name TreeNewBee
// @contact.email haozi@loli.email
// @license.name WTFPL
// @license.url http://www.wtfpl.net/
// @BasePath /
func main() {
// Define Fiber config.
config := configs.FiberConfig()
// Define a new Fiber app with config.
app := fiber.New(config)
// Middlewares.
middleware.FiberMiddleware(app) // Register Fiber's middleware for app.
// Routes.
routes.SwaggerRoute(app) // Register a route for API Docs (Swagger).
routes.PublicRoutes(app) // Register a public routes for app.
routes.NotFoundRoute(app) // Register route for 404 Error.
// Start server (with or without graceful shutdown).
if os.Getenv("STAGE_STATUS") == "dev" {
utils.StartServer(app)
} else {
utils.StartServerWithGracefulShutdown(app)
}
}