-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (63 loc) · 1.74 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
74
75
76
package main
import (
"fmt"
"todo-list/app/middlewares"
"todo-list/database"
"todo-list/helpers"
"todo-list/routes"
"github.com/gofiber/fiber/v2"
)
func homepage(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
apiDocumentUrl, _ := c.GetRouteURL("api.v1.swagger.documentation", fiber.Map{})
html := `<h1>Welcome to Todo List API !</h1>`
html = html + fmt.Sprintf("Go to <a href='%s'>%s</a> for API Documentation", apiDocumentUrl, apiDocumentUrl)
return c.SendString(html)
}
// @title Todo List API
// @version 1.0
// @description This is a Todo List API swagger
// @contact.name Ramdani
// @contact.url https://github.com/ramdani15/
// @contact.email [email protected]
// @BasePath /
// @schemas http
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and JWT token.
func main() {
app := fiber.New()
// Connect Database
errDb := database.Connect()
if errDb != nil {
panic("Failed to connect Database (" + errDb.Error() + ")")
}
// Connect Cache Client
errCache := database.CacheConnect()
if errCache != nil {
panic("Failed to connect Cache Client (" + errCache.Error() + ")")
}
// Connect Elasticsearh Client
errElastic := database.ElasticConnect()
if errElastic != nil {
panic("Failed to connect Elasticsearch Client (" + errElastic.Error() + ")")
}
// Migrate
errMigrate := database.Migrate()
if errMigrate != nil {
panic(errMigrate.Error())
}
// Seeder
errSeeder := database.DatabaseSeeder()
if errSeeder != nil {
panic(errSeeder.Error())
}
// Set Middleware
middlewares.DefaultMiddlewares(app)
// Routes
routes.MainRoutes(app)
app.Get("/", homepage).Name("homepage")
// Run Server
helpers.StartServer(app)
}