-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
116 lines (96 loc) · 4.03 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"log"
"os"
"github.com/erikrios/reog-apps-apis/config"
"github.com/erikrios/reog-apps-apis/controller"
_ "github.com/erikrios/reog-apps-apis/docs"
"github.com/erikrios/reog-apps-apis/middleware"
dr "github.com/erikrios/reog-apps-apis/repository/address"
ar "github.com/erikrios/reog-apps-apis/repository/admin"
gr "github.com/erikrios/reog-apps-apis/repository/group"
pr "github.com/erikrios/reog-apps-apis/repository/property"
ssr "github.com/erikrios/reog-apps-apis/repository/showschedule"
vr "github.com/erikrios/reog-apps-apis/repository/village"
ds "github.com/erikrios/reog-apps-apis/service/address"
as "github.com/erikrios/reog-apps-apis/service/admin"
gs "github.com/erikrios/reog-apps-apis/service/group"
ps "github.com/erikrios/reog-apps-apis/service/property"
sss "github.com/erikrios/reog-apps-apis/service/showschedule"
"github.com/erikrios/reog-apps-apis/utils/generator"
"github.com/erikrios/reog-apps-apis/utils/logging"
_ "github.com/erikrios/reog-apps-apis/validation"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
echoSwagger "github.com/swaggo/echo-swagger"
)
// @title Reog Apps API
// @version 1.0
// @description API for Reog Group in Ponorogo
// @termsOfService http://swagger.io/terms/
// @contact.name Erik Rio Setiawan
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @host 103.183.74.19:80
// @BasePath /api/v1
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
if err := godotenv.Load(".env"); err != nil {
log.Printf("Error loading .env file: %s\n", err.Error())
}
db, err := config.NewPostgreSQLDatabase()
if err != nil {
log.Fatalln(err.Error())
} else {
log.Printf("Successfully connected to database with instance address: %p\n", db)
}
client, err := config.NewMongoDBDatabase()
if err != nil {
log.Println(err)
}
config.MigratePostgreSQLDatabase(db)
config.SetInitialDataPostgreSQLDatabase(db)
port := ":" + os.Getenv("PORT")
passwordGenerator := generator.NewBcryptPasswordGenerator()
tokenGenerator := generator.NewJWTTokenGenerator()
idGenerator := generator.NewNanoidIDGenerator()
qrCodeGenerator := generator.NewQRCodeGeneratorImpl()
logger := logging.NewMongoLogging(client)
adminRepository := ar.NewAdminRepositoryImpl(db, logger)
groupRepository := gr.NewGroupRepositoryImpl(db, logger)
villageRepository := vr.NewVillageRepositoryImpl(logger)
addressRepository := dr.NewAddressRepositoryImpl(db, logger)
propertyRepository := pr.NewPropertyRepositoryImpl(db, logger)
showScheduleRepository := ssr.NewShowScheduleRepositoryImpl(db, logger)
adminService := as.NewAdminServiceImpl(adminRepository, passwordGenerator, tokenGenerator)
groupService := gs.NewGroupServiceImpl(groupRepository, villageRepository, idGenerator, qrCodeGenerator)
addressService := ds.NewAddressServiceImpl(addressRepository, villageRepository)
propertyService := ps.NewPropertyServiceImpl(propertyRepository, groupRepository, idGenerator, qrCodeGenerator)
showScheduleService := sss.NewShowScheduleServiceImpl(showScheduleRepository, groupRepository, idGenerator)
adminsController := controller.NewAdminsController(adminService)
groupsController := controller.NewGroupsController(groupService, propertyService, addressService)
showSchedulesController := controller.NewShowSchedulesController(showScheduleService)
e := echo.New()
if os.Getenv("ENV") == "production" {
middleware.BodyLimit(e)
middleware.Gzip(e)
middleware.RateLimiter(e)
middleware.Recover(e)
middleware.Secure(e)
middleware.RemoveTrailingSlash(e)
} else {
middleware.Logger(e)
middleware.RemoveTrailingSlash(e)
}
e.GET("/*", echoSwagger.WrapHandler)
g := e.Group("/api/v1")
adminsController.Route(g)
groupsController.Route(g)
showSchedulesController.Route(g)
e.Logger.Fatal(e.Start(port))
}