-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
44 lines (36 loc) · 1.09 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
package main
import (
"gin-gorm-clean-template/common"
"gin-gorm-clean-template/config"
"gin-gorm-clean-template/controller"
"gin-gorm-clean-template/repository"
"gin-gorm-clean-template/routes"
"gin-gorm-clean-template/service"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"gorm.io/gorm"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
res := common.BuildErrorResponse("Gagal Terhubung ke Server", err.Error(), common.EmptyObj{})
(*gin.Context).JSON((&gin.Context{}), http.StatusBadGateway, res)
return
}
var (
db *gorm.DB = config.SetupDatabaseConnection()
jwtService service.JWTService = service.NewJWTService()
userRepository repository.UserRepository = repository.NewUserRepository(db)
userService service.UserService = service.NewUserService(userRepository)
userController controller.UserController = controller.NewUserController(userService, jwtService)
)
server := gin.Default()
routes.UserRoutes(server, userController, jwtService)
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
server.Run("127.0.0.1:" + port)
}