-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (58 loc) · 1.7 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
package main
import (
"log"
"github.com/gofiber/contrib/swagger"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/kayprogrammer/socialnet-v6/config"
"github.com/kayprogrammer/socialnet-v6/database"
"github.com/kayprogrammer/socialnet-v6/initials"
"github.com/kayprogrammer/socialnet-v6/routes"
_ "github.com/kayprogrammer/socialnet-v6/docs"
)
// @title SOCIALNET API
// @version 6.0
// @description.markdown api
// @Accept json
// @Produce json
// @BasePath /api/v6
// @Security BearerAuth
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Type 'Bearer jwt_string' to correctly set the API Key
func main() {
cfg := config.GetConfig()
db := database.ConnectDb(cfg)
sqlDb, _ := db.DB()
initials.CreateInitialData(cfg, db)
app := fiber.New()
// CORS config
app.Use(cors.New(cors.Config{
AllowOrigins: cfg.CORSAllowedOrigins,
AllowHeaders: "Origin, Content-Type, Accept, Authorization, Access-Control-Allow-Origin, Content-Disposition",
AllowCredentials: true,
AllowMethods: "GET, POST, PUT, PATCH, DELETE, OPTIONS",
}))
// Swagger Config
swaggerCfg := swagger.Config{
FilePath: "./docs/swagger.json",
Path: "/",
Title: "SOCIALNET API Documentation",
CacheAge: 1,
}
app.Use(swagger.New(swaggerCfg))
// Register Routes & Sockets
app.Use("/ws", func(c *fiber.Ctx) error {
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
return c.Next()
}
return fiber.ErrUpgradeRequired
})
routes.SetupRoutes(app, db)
defer sqlDb.Close()
log.Fatal(app.Listen(":8000"))
}