refactoring of code

This commit is contained in:
Jonas Kaninda
2024-11-17 03:56:47 +01:00
parent 858deb6b72
commit 9dc2dfcbb2
3 changed files with 26 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
*/
import (
"github.com/gorilla/mux"
"github.com/jkaninda/goma-gateway/internal/metrics"
"github.com/jkaninda/goma-gateway/internal/middlewares"
"github.com/jkaninda/goma-gateway/pkg/logger"
"github.com/jkaninda/goma-gateway/util"
@@ -26,9 +27,9 @@ import (
)
func init() {
_ = prometheus.Register(totalRequests)
_ = prometheus.Register(responseStatus)
_ = prometheus.Register(httpDuration)
_ = prometheus.Register(metrics.TotalRequests)
_ = prometheus.Register(metrics.ResponseStatus)
_ = prometheus.Register(metrics.HttpDuration)
}
// Initialize the routes
@@ -265,12 +266,12 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
router.PathPrefix("").Handler(proxyRoute.ProxyHandler())
}
if gateway.EnableMetrics {
pr := PrometheusRoute{
name: route.Name,
path: route.Path,
pr := metrics.PrometheusRoute{
Name: route.Name,
Path: route.Path,
}
// Prometheus endpoint
router.Use(pr.prometheusMiddleware)
router.Use(pr.PrometheusMiddleware)
}
// Apply route Error interceptor middlewares
if len(route.InterceptErrors) != 0 {