feat: add enable, disable route health check access link

This commit is contained in:
2024-11-04 06:52:41 +01:00
parent 4601377c4b
commit e81de80654
6 changed files with 26 additions and 20 deletions

View File

@@ -152,6 +152,8 @@ type Gateway struct {
RateLimiter int `yaml:"rateLimiter" env:"GOMA_RATE_LIMITER, overwrite"`
AccessLog string `yaml:"accessLog" env:"GOMA_ACCESS_LOG, overwrite"`
ErrorLog string `yaml:"errorLog" env:"GOMA_ERROR_LOG=, overwrite"`
// DisableHealthCheckStatus enable and disable routes health check
DisableHealthCheckStatus bool `yaml:"disableHealthCheckStatus"`
// DisableRouteHealthCheckError allows enabling and disabling backend healthcheck errors
DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError"`
//Disable allows enabling and disabling displaying routes on start
@@ -288,6 +290,7 @@ func initConfig(configFile string) {
},
{
Name: "Hostname example",
Host: "http://example.localhost",
Path: "/",
Destination: "https://example.com",
Rewrite: "/",

View File

@@ -40,7 +40,7 @@ func TestMiddleware(t *testing.T) {
},
},
{
Name: "forbidden path acces",
Name: "forbidden path access",
Type: "access",
Paths: []string{"/", "/admin"},
Rule: BasicRuleMiddleware{

View File

@@ -23,6 +23,7 @@ import (
"time"
)
// Initialize the routes
func (gatewayServer GatewayServer) Initialize() *mux.Router {
gateway := gatewayServer.gateway
middlewares := gatewayServer.middlewares
@@ -31,9 +32,13 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
DisableRouteHealthCheckError: gateway.DisableRouteHealthCheckError,
Routes: gateway.Routes,
}
// Define the health check route
r.HandleFunc("/healthz", heath.HealthCheckHandler).Methods("GET")
// Routes health check
if !gateway.DisableHealthCheckStatus {
r.HandleFunc("/healthz", heath.HealthCheckHandler).Methods("GET")
}
// Readiness
r.HandleFunc("/readyz", heath.HealthReadyHandler).Methods("GET")
if gateway.RateLimiter != 0 {
//rateLimiter := middleware.NewRateLimiter(gateway.RateLimiter, time.Minute)
limiter := middleware.NewRateLimiterWindow(gateway.RateLimiter, time.Minute) // requests per minute