From e3edd37cd30b190015b48800040d5eade030ea6d Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Fri, 22 Nov 2024 18:19:20 +0100 Subject: [PATCH] chore: omit empty config --- README.md | 2 +- internal/config.go | 20 +++----------------- internal/gateway_type.go | 18 +++++++++--------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 4aac71d..f34aa05 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ It's designed to be straightforward and efficient, offering a rich set of featur Use a round-robin algorithm for efficient load distribution. ### Configuration and Flexibility -- **Support for Multiple Route Configuration Files** +- **Support for Multiple Route and Middleware Configuration Files** Organize routes across multiple `.yml` or `.yaml` files. - **TLS Support** diff --git a/internal/config.go b/internal/config.go index 7b2f569..73aaf37 100644 --- a/internal/config.go +++ b/internal/config.go @@ -133,23 +133,9 @@ func initConfig(configFile string) error { conf := &GatewayConfig{ Version: util.ConfigVersion, GatewayConfig: Gateway{ - WriteTimeout: 15, - ReadTimeout: 15, - IdleTimeout: 30, - AccessLog: "/dev/Stdout", - ErrorLog: "/dev/stderr", - DisableRouteHealthCheckError: false, - DisableDisplayRouteOnStart: false, - RateLimit: 0, - InterceptErrors: []int{405, 500}, - Cors: Cors{ - Origins: []string{"http://localhost:8080", "https://example.com"}, - Headers: map[string]string{ - "Access-Control-Allow-Headers": "Origin, Authorization, Accept, Content-Type, Access-Control-Allow-Headers", - "Access-Control-Allow-Credentials": "true", - "Access-Control-Max-Age": "1728000", - }, - }, + WriteTimeout: 15, + ReadTimeout: 15, + IdleTimeout: 30, Routes: []Route{ { Name: "Example", diff --git a/internal/gateway_type.go b/internal/gateway_type.go index dd04ec7..25eddba 100644 --- a/internal/gateway_type.go +++ b/internal/gateway_type.go @@ -32,26 +32,26 @@ type Gateway struct { // IdleTimeout defines proxy idle timeout IdleTimeout int `yaml:"idleTimeout" env:"GOMA_IDLE_TIMEOUT, overwrite"` // RateLimit Defines the number of request peer minutes - RateLimit int `yaml:"rateLimit" env:"GOMA_RATE_LIMIT, overwrite"` + RateLimit int `yaml:"rateLimit,omitempty" env:"GOMA_RATE_LIMIT, overwrite"` // BlockCommonExploits enable, disable block common exploits - BlockCommonExploits bool `yaml:"blockCommonExploits"` - AccessLog string `yaml:"accessLog" env:"GOMA_ACCESS_LOG, overwrite"` - ErrorLog string `yaml:"errorLog" env:"GOMA_ERROR_LOG=, overwrite"` + BlockCommonExploits bool `yaml:"blockCommonExploits,omitempty"` + AccessLog string `yaml:"accessLog,omitempty" env:"GOMA_ACCESS_LOG, overwrite"` + ErrorLog string `yaml:"errorLog,omitempty" env:"GOMA_ERROR_LOG=, overwrite"` LogLevel string `yaml:"logLevel" env:"GOMA_LOG_LEVEL, overwrite"` // DisableHealthCheckStatus enable and disable routes health check DisableHealthCheckStatus bool `yaml:"disableHealthCheckStatus"` // DisableRouteHealthCheckError allows enabling and disabling backend healthcheck errors - DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError"` + DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError,omitempty"` // Disable allows enabling and disabling displaying routes on start - DisableDisplayRouteOnStart bool `yaml:"disableDisplayRouteOnStart"` + DisableDisplayRouteOnStart bool `yaml:"disableDisplayRouteOnStart,omitempty"` // DisableKeepAlive allows enabling and disabling KeepALive server - DisableKeepAlive bool `yaml:"disableKeepAlive"` + DisableKeepAlive bool `yaml:"disableKeepAlive,omitempty"` EnableMetrics bool `yaml:"enableMetrics"` // InterceptErrors holds the status codes to intercept the error from backend - InterceptErrors []int `yaml:"interceptErrors"` + InterceptErrors []int `yaml:"interceptErrors,omitempty"` // Cors holds proxy global cors - Cors Cors `yaml:"cors"` + Cors Cors `yaml:"cors,omitempty"` // ExtraRoutes additional routes from defined directory ExtraRoutes ExtraRouteConfig `yaml:"extraRoutes"` // Routes holds proxy routes