-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (58 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
package main
import (
"log"
"github.com/LitPad/backend/config"
"github.com/LitPad/backend/database"
_ "github.com/LitPad/backend/docs"
"github.com/LitPad/backend/initials"
"github.com/LitPad/backend/internetcomputer"
"github.com/LitPad/backend/routes"
"github.com/gofiber/contrib/swagger"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
// @title LITPAD API
// @description.markdown api
// @version 1.0
// @Accept json
// @Produce json
// @BasePath /api/v1
// @Security BearerAuth
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Type 'Bearer jwt_string' to correctly set the API Key
func main() {
// Load config
conf := config.GetConfig()
// Get Database
db := database.ConnectDb(conf)
// Create initial data
initials.CreateInitialData(db, conf)
// Initialize ICP
privateKey := []byte(conf.ICPPrivateKey)
publicKey := []byte(conf.ICPPublicKey)
walletService, err := internetcomputer.NewWalletService(privateKey, publicKey)
if err != nil{
log.Fatal("Failed to initialize Internet computer wallet system: ", err)
}
app := fiber.New()
// CORS config
app.Use(cors.New(cors.Config{
AllowOrigins: conf.CORSAllowedOrigins,
AllowHeaders: "Origin, Content-Type, Accept, Authorization, Access-Control-Allow-Origin, Content-Disposition",
AllowCredentials: conf.CORSAllowCredentials,
AllowMethods: "GET, POST, PUT, PATCH, DELETE, OPTIONS",
}))
// Swagger Config
swaggerCfg := swagger.Config{
FilePath: "./docs/swagger.json",
Path: "/",
Title: "LITPAD API Documentation",
CacheAge: 1,
}
app.Use(swagger.New(swaggerCfg))
// Register Routes & Sockets
routes.SetupRoutes(app, db, walletService)
log.Fatal(app.Listen(":" + conf.Port))
}