-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
57 lines (46 loc) · 1.44 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
package main
import (
"log"
"time"
"webapp/config"
"webapp/database"
"webapp/docs"
"webapp/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
docs.SwaggerInfo.Title = "Task Board API"
docs.SwaggerInfo.Description = "Backend for the task management board on the project, similar to the github issue."
docs.SwaggerInfo.Version = "1.0"
docs.SwaggerInfo.Host = "localhost:8080"
docs.SwaggerInfo.BasePath = "/api/v1"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
config.LoadConfig()
db, err := database.InitDB(config.GetConfig().DatabaseURL)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"*"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "*"
},
MaxAge: 12 * time.Hour,
}))
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
routes.RegisterRoutes(r, db)
r.Run(config.GetConfig().ServerPort)
}