-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.go
79 lines (69 loc) · 2.89 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
package main
import (
"github.com/RizkiMufrizal/gofiber-clean-architecture/client/restclient"
"github.com/RizkiMufrizal/gofiber-clean-architecture/configuration"
"github.com/RizkiMufrizal/gofiber-clean-architecture/controller"
_ "github.com/RizkiMufrizal/gofiber-clean-architecture/docs"
"github.com/RizkiMufrizal/gofiber-clean-architecture/exception"
repository "github.com/RizkiMufrizal/gofiber-clean-architecture/repository/impl"
service "github.com/RizkiMufrizal/gofiber-clean-architecture/service/impl"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/swagger"
)
// @title Go Fiber Clean Architecture
// @version 1.0.0
// @description Baseline project using Go Fiber
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email [email protected]
// @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
app := fiber.New(configuration.NewFiberConfiguration())
app.Use(recover.New())
app.Use(cors.New())
//routing
productController.Route(app)
transactionController.Route(app)
transactionDetailController.Route(app)
userController.Route(app)
httpBinController.Route(app)
//swagger
app.Get("/swagger/*", swagger.HandlerDefault)
//start app
err := app.Listen(config.Get("SERVER.PORT"))
exception.PanicLogging(err)
}