6
6
"github.com/gin-gonic/gin"
7
7
"github.com/gin-gonic/gin/binding"
8
8
"github.com/go-playground/validator/v10"
9
- "github.com/naeemaei/golang-clean-web-api/api/middlewares "
10
- "github.com/naeemaei/golang-clean-web-api/api/routers "
11
- validation "github.com/naeemaei/golang-clean-web-api/api/validations "
9
+ "github.com/naeemaei/golang-clean-web-api/api/middleware "
10
+ "github.com/naeemaei/golang-clean-web-api/api/router "
11
+ validation "github.com/naeemaei/golang-clean-web-api/api/validation "
12
12
"github.com/naeemaei/golang-clean-web-api/config"
13
13
"github.com/naeemaei/golang-clean-web-api/docs"
14
14
"github.com/naeemaei/golang-clean-web-api/pkg/logging"
@@ -27,10 +27,10 @@ func InitServer(cfg *config.Config) {
27
27
RegisterValidators ()
28
28
RegisterPrometheus ()
29
29
30
- r .Use (middlewares .DefaultStructuredLogger (cfg ))
31
- r .Use (middlewares .Cors (cfg ))
32
- r .Use (middlewares .Prometheus ())
33
- r .Use (gin .Logger (), gin .CustomRecovery (middlewares .ErrorHandler ) /*middlewares .TestMiddleware()*/ , middlewares .LimitByRequest ())
30
+ r .Use (middleware .DefaultStructuredLogger (cfg ))
31
+ r .Use (middleware .Cors (cfg ))
32
+ r .Use (middleware .Prometheus ())
33
+ r .Use (gin .Logger (), gin .CustomRecovery (middleware .ErrorHandler ) /*middleware .TestMiddleware()*/ , middleware .LimitByRequest ())
34
34
35
35
RegisterRoutes (r , cfg )
36
36
RegisterSwagger (r , cfg )
@@ -49,63 +49,63 @@ func RegisterRoutes(r *gin.Engine, cfg *config.Config) {
49
49
{
50
50
// Test
51
51
health := v1 .Group ("/health" )
52
- testRouter := v1 .Group ("/test" /*middlewares .Authentication(cfg), middlewares .Authorization([]string{"admin"})*/ )
52
+ testRouter := v1 .Group ("/test" /*middleware .Authentication(cfg), middleware .Authorization([]string{"admin"})*/ )
53
53
54
54
// User
55
55
users := v1 .Group ("/users" )
56
56
57
57
// Base
58
- countries := v1 .Group ("/countries" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
59
- cities := v1 .Group ("/cities" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
60
- files := v1 .Group ("/files" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
61
- companies := v1 .Group ("/companies" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
62
- colors := v1 .Group ("/colors" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
63
- years := v1 .Group ("/years" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
58
+ countries := v1 .Group ("/countries" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
59
+ cities := v1 .Group ("/cities" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
60
+ files := v1 .Group ("/files" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
61
+ companies := v1 .Group ("/companies" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
62
+ colors := v1 .Group ("/colors" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
63
+ years := v1 .Group ("/years" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
64
64
65
65
// Property
66
- properties := v1 .Group ("/properties" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
67
- propertyCategories := v1 .Group ("/property-categories" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
66
+ properties := v1 .Group ("/properties" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
67
+ propertyCategories := v1 .Group ("/property-categories" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
68
68
69
69
// Car
70
- carTypes := v1 .Group ("/car-types" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
71
- gearboxes := v1 .Group ("/gearboxes" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
72
- carModels := v1 .Group ("/car-models" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
73
- carModelColors := v1 .Group ("/car-model-colors" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
74
- carModelYears := v1 .Group ("/car-model-years" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
75
- carModelPriceHistories := v1 .Group ("/car-model-price-histories" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
76
- carModelImages := v1 .Group ("/car-model-images" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
77
- carModelProperties := v1 .Group ("/car-model-properties" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" }))
78
- carModelComments := v1 .Group ("/car-model-comments" , middlewares .Authentication (cfg ), middlewares .Authorization ([]string {"admin" , "default" }))
70
+ carTypes := v1 .Group ("/car-types" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
71
+ gearboxes := v1 .Group ("/gearboxes" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
72
+ carModels := v1 .Group ("/car-models" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
73
+ carModelColors := v1 .Group ("/car-model-colors" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
74
+ carModelYears := v1 .Group ("/car-model-years" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
75
+ carModelPriceHistories := v1 .Group ("/car-model-price-histories" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
76
+ carModelImages := v1 .Group ("/car-model-images" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
77
+ carModelProperties := v1 .Group ("/car-model-properties" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" }))
78
+ carModelComments := v1 .Group ("/car-model-comments" , middleware .Authentication (cfg ), middleware .Authorization ([]string {"admin" , "default" }))
79
79
80
80
// Test
81
- routers .Health (health )
82
- routers .TestRouter (testRouter )
81
+ router .Health (health )
82
+ router .TestRouter (testRouter )
83
83
84
84
// User
85
- routers .User (users , cfg )
85
+ router .User (users , cfg )
86
86
87
87
// Base
88
- routers .Country (countries , cfg )
89
- routers .City (cities , cfg )
90
- routers .File (files , cfg )
91
- routers .Company (companies , cfg )
92
- routers .Color (colors , cfg )
93
- routers .Year (years , cfg )
88
+ router .Country (countries , cfg )
89
+ router .City (cities , cfg )
90
+ router .File (files , cfg )
91
+ router .Company (companies , cfg )
92
+ router .Color (colors , cfg )
93
+ router .Year (years , cfg )
94
94
95
95
// Property
96
- routers .Property (properties , cfg )
97
- routers .PropertyCategory (propertyCategories , cfg )
96
+ router .Property (properties , cfg )
97
+ router .PropertyCategory (propertyCategories , cfg )
98
98
99
99
// Car
100
- routers .CarType (carTypes , cfg )
101
- routers .Gearbox (gearboxes , cfg )
102
- routers .CarModel (carModels , cfg )
103
- routers .CarModelColor (carModelColors , cfg )
104
- routers .CarModelYear (carModelYears , cfg )
105
- routers .CarModelPriceHistory (carModelPriceHistories , cfg )
106
- routers .CarModelImage (carModelImages , cfg )
107
- routers .CarModelProperty (carModelProperties , cfg )
108
- routers .CarModelComment (carModelComments , cfg )
100
+ router .CarType (carTypes , cfg )
101
+ router .Gearbox (gearboxes , cfg )
102
+ router .CarModel (carModels , cfg )
103
+ router .CarModelColor (carModelColors , cfg )
104
+ router .CarModelYear (carModelYears , cfg )
105
+ router .CarModelPriceHistory (carModelPriceHistories , cfg )
106
+ router .CarModelImage (carModelImages , cfg )
107
+ router .CarModelProperty (carModelProperties , cfg )
108
+ router .CarModelComment (carModelComments , cfg )
109
109
110
110
r .Static ("/static" , "./uploads" )
111
111
@@ -115,7 +115,7 @@ func RegisterRoutes(r *gin.Engine, cfg *config.Config) {
115
115
v2 := api .Group ("/v2" )
116
116
{
117
117
health := v2 .Group ("/health" )
118
- routers .Health (health )
118
+ router .Health (health )
119
119
}
120
120
}
121
121
@@ -144,14 +144,14 @@ func RegisterSwagger(r *gin.Engine, cfg *config.Config) {
144
144
r .GET ("/swagger/*any" , ginSwagger .WrapHandler (swaggerFiles .Handler ))
145
145
}
146
146
147
- func RegisterPrometheus (){
147
+ func RegisterPrometheus () {
148
148
err := prometheus .Register (metrics .DbCall )
149
149
if err != nil {
150
150
logger .Error (logging .Prometheus , logging .Startup , err .Error (), nil )
151
151
}
152
-
152
+
153
153
err = prometheus .Register (metrics .HttpDuration )
154
154
if err != nil {
155
155
logger .Error (logging .Prometheus , logging .Startup , err .Error (), nil )
156
156
}
157
- }
157
+ }
0 commit comments