Config API
The Config struct defines the main configuration for API Gateway.
Type Definition
type Config struct {
Port int64 `config:"port"`
BaseURI string `config:"baseuri"`
Backend route.Backend `config:"backend"`
Routes []route.Route `config:"routes"`
Cache Cache `config:"cache"`
HealthCheck HealthCheck `config:"healthcheck"`
RateLimit RateLimit `config:"rate_limit"`
}Fields
Port
Port int64The port the gateway listens on. Default: 8080
BaseURI
BaseURI stringBase URI prefix for all routes. When set, only requests starting with this prefix are accepted.
Backend
Backend route.BackendDefault backend service. Used when no route matches.
Routes
Routes []route.RouteArray of route definitions. See Route API for details.
Cache
Cache CacheCache configuration. See Cache Configuration.
HealthCheck
HealthCheck HealthCheckHealth check configuration. See Health Check Configuration.
Cache Configuration
type Cache struct {
Host string `config:"host"`
Port int64 `config:"port"`
Username string `config:"username"`
Password string `config:"password"`
DB int64 `config:"db"`
Prefix string `config:"prefix"`
}Fields
Host(string): Redis host. Default:127.0.0.1Port(int64): Redis port. Default:6379Username(string): Redis username (optional)Password(string): Redis password (optional)DB(int64): Redis database number. Default:0Prefix(string): Key prefix. Default:gozoox-api-gateway:
Health Check Configuration
type HealthCheck struct {
Outer HealthCheckOuter `config:"outer"`
Inner HealthCheckInner `config:"inner"`
}Outer Health Check
type HealthCheckOuter struct {
Enable bool `config:"enable"`
Path string `config:"path"`
Ok bool `config:"ok"`
}Enable(bool): Enable external health check endpointPath(string): Health check endpoint path. Default:/healthzOk(bool): Always return OK. Default:true
Inner Health Check
type HealthCheckInner struct {
Enable bool `config:"enable"`
Interval int64 `config:"interval"`
Timeout int64 `config:"timeout"`
}Enable(bool): Enable internal service health checksInterval(int64): Check interval in seconds. Default:30Timeout(int64): Request timeout in seconds. Default:5
Rate Limit Configuration
type RateLimit struct {
Enable bool `config:"enable"`
Algorithm string `config:"algorithm,default=token-bucket"`
KeyType string `config:"key_type,default=ip"`
KeyHeader string `config:"key_header"`
Limit int64 `config:"limit"`
Window int64 `config:"window"`
Burst int64 `config:"burst"`
Message string `config:"message,default=Too Many Requests"`
Headers map[string]string `config:"headers"`
}Counters are stored only through zoox.Application.Cache() (configure top-level cache for Redis; otherwise the framework default applies). Same struct is used on the root config and on each route’s rate_limit override.
Fields
YAML keys are snake_case (key_type, …); the table uses Go struct field names. Required? means the field must be set for an effective policy; Default applies when omitted. Summary is short; meaning, defaults, usage, and YAML examples for each key are in the Rate limiting plugin — Field details guide.
| Field | Go type | Required? | Default | Summary |
|---|---|---|---|---|
Limit | int64 | Yes | — | YAML limit: quota per window. Details |
Window | int64 | Yes | — | YAML window: window length in seconds. Details |
Enable | bool | No | false | YAML enable: scope flag. Details |
Algorithm | string | No | token-bucket | YAML algorithm. Details |
KeyType | string | No | ip | YAML key_type. Details |
KeyHeader | string | No | (empty) | YAML key_header. Details |
Burst | int64 | No | 0 | YAML burst. Details |
Message | string | No | Too Many Requests | YAML message. Details |
Headers | map[string]string | No | (empty) | YAML headers. Details |
Example
cfg := &config.Config{
Port: 8080,
BaseURI: "/v1",
Cache: config.Cache{
Host: "127.0.0.1",
Port: 6379,
DB: 0,
},
HealthCheck: config.HealthCheck{
Outer: config.HealthCheckOuter{
Enable: true,
Path: "/healthz",
},
Inner: config.HealthCheckInner{
Enable: true,
Interval: 30,
Timeout: 5,
},
},
Routes: []route.Route{
// ... routes
},
}See Also
- Route API - Route configuration
- Configuration Guide - Configuration guide