feat: add enable, disable route health check access link
This commit is contained in:
@@ -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: "/",
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestMiddleware(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "forbidden path acces",
|
||||
Name: "forbidden path access",
|
||||
Type: "access",
|
||||
Paths: []string{"/", "/admin"},
|
||||
Rule: BasicRuleMiddleware{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user