-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.13 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
package main
import (
"ClearningPatternGO/app/config"
database "ClearningPatternGO/app/databases"
routesV1 "ClearningPatternGO/modules/v1/routes"
"ClearningPatternGO/pkg/html"
error "ClearningPatternGO/pkg/http-error"
"log"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func setup() (*gorm.DB, config.Conf, *gin.Engine) {
conf, err := config.Init()
gin.SetMode(conf.App.Mode)
if err != nil {
log.Fatal(err)
}
db := database.Init(conf)
router := gin.Default()
router.Use(cors.Default())
cookieStore := cookie.NewStore([]byte(conf.App.Secret_key))
router.Use(sessions.Sessions("cleaningpatterngo", cookieStore))
router.HTMLRender = html.Render("./public")
//Error Handling for 404 Not Found Page and Method Not Allowed
router.NoRoute(error.PageNotFound())
router.NoMethod(error.NoMethod())
return db, conf, router
}
func main() {
conf, err := config.Init()
if err != nil {
log.Fatal(err)
}
router := routesV1.Init(setup()) //Version 1
//fmt.Println("Starter " + conf.App.Name)
router.Run(":" + conf.App.Port)
}