-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.12 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
package main
import (
"fmt"
"os"
"github.com/zetsux/gin-gorm-clean-starter/api/v1/controller"
"github.com/zetsux/gin-gorm-clean-starter/api/v1/router"
"github.com/zetsux/gin-gorm-clean-starter/common/middleware"
"github.com/zetsux/gin-gorm-clean-starter/config"
"github.com/zetsux/gin-gorm-clean-starter/core/repository"
"github.com/zetsux/gin-gorm-clean-starter/core/service"
"github.com/gin-gonic/gin"
)
func main() {
var (
db = config.DBSetup()
txR = repository.NewTxRepository(db)
userR = repository.NewUserRepository(txR)
jwtS = service.NewJWTService()
userS = service.NewUserService(userR)
fileC = controller.NewFileController()
userC = controller.NewUserController(userS, jwtS)
)
defer config.DBClose(db)
// Setting Up Server
server := gin.Default()
server.Use(
middleware.CORSMiddleware(),
)
// Setting Up Routes
router.FileRouter(server, fileC)
router.UserRouter(server, userC, jwtS)
// Running in localhost:8080
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
err := server.Run(":" + port)
if err != nil {
fmt.Println("Server failed to start: ", err)
return
}
}