-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
80 lines (70 loc) · 2.93 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
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"github.com/RizkiMufrizal/gin-clean-architecture/client/restclient"
"github.com/RizkiMufrizal/gin-clean-architecture/configuration"
"github.com/RizkiMufrizal/gin-clean-architecture/controller"
_ "github.com/RizkiMufrizal/gin-clean-architecture/docs"
"github.com/RizkiMufrizal/gin-clean-architecture/exception"
"github.com/RizkiMufrizal/gin-clean-architecture/middleware"
repository "github.com/RizkiMufrizal/gin-clean-architecture/repository/impl"
service "github.com/RizkiMufrizal/gin-clean-architecture/service/impl"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Gin Clean Architecture
// @version 1.0.0
// @description Baseline project using Gin
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email gin@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:9999
// @BasePath /
// @schemes http https
// @securityDefinitions.apikey JWT
// @in header
// @name Authorization
// @description Authorization For JWT
func main() {
//setup configuration
config := configuration.New()
database := configuration.NewDatabase(config)
redis := configuration.NewRedis(config)
//repository
productRepository := repository.NewProductRepositoryImpl(database)
transactionRepository := repository.NewTransactionRepositoryImpl(database)
transactionDetailRepository := repository.NewTransactionDetailRepositoryImpl(database)
userRepository := repository.NewUserRepositoryImpl(database)
//rest client
httpBinRestClient := restclient.NewHttpBinRestClient()
//service
productService := service.NewProductServiceImpl(&productRepository, redis)
transactionService := service.NewTransactionServiceImpl(&transactionRepository)
transactionDetailService := service.NewTransactionDetailServiceImpl(&transactionDetailRepository)
userService := service.NewUserServiceImpl(&userRepository)
httpBinService := service.NewHttpBinServiceImpl(&httpBinRestClient)
//controller
productController := controller.NewProductController(&productService, config)
transactionController := controller.NewTransactionController(&transactionService, config)
transactionDetailController := controller.NewTransactionDetailController(&transactionDetailService, config)
userController := controller.NewUserController(&userService, config)
httpBinController := controller.NewHttpBinController(&httpBinService)
//setup fiber
gin.SetMode(gin.DebugMode)
app := gin.Default()
app.Use(gin.CustomRecovery(exception.ErrorHandler))
app.Use(middleware.CORSMiddleware())
//routing
productController.Route(app)
transactionController.Route(app)
transactionDetailController.Route(app)
userController.Route(app)
httpBinController.Route(app)
//swagger
app.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
//start app
err := app.Run(config.Get("SERVER.PORT"))
exception.PanicLogging(err)
}