Documentation
¶
Index ¶
- func WriteError(w http.ResponseWriter, code ClientError, status int)
- type AddrList
- type AdminConfig
- type AggregationConfig
- type CircuitBreakerConfig
- type ClientError
- type ClientResponse
- type Config
- type FlowConfig
- type GatewayConfig
- type LoadBalancingConfig
- type MetricsConfig
- type MiddlewareConfig
- type OTLPConfig
- type ObservabilityConfig
- type OnConflictConfig
- type PluginConfig
- type PolicyConfig
- type RateLimiterConfig
- type ResponseMeta
- type RetryConfig
- type Router
- type RouterBundle
- type RoutingConfig
- type RoutingConfigSet
- type ServerConfig
- type ServerTLSConfig
- type ServiceConfig
- type TLSConfig
- type TracingConfig
- type TransportConfig
- type UpstreamConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, code ClientError, status int)
Types ¶
type AdminConfig ¶
type AdminConfig struct {
Port int `yaml:"port" validate:"required,min=1,max=65535"`
BindAddr string `yaml:"bind_addr" default:"127.0.0.1"`
Timeout time.Duration `yaml:"timeout" default:"5m"`
HeaderTimeout time.Duration `yaml:"header_timeout" default:"5s"`
EnablePprof bool `yaml:"enable_pprof" default:"false"`
}
type AggregationConfig ¶
type AggregationConfig struct {
BestEffort bool `yaml:"best_effort"`
Strategy string `yaml:"strategy" validate:"required,oneof=array merge namespace"`
OnConflict *OnConflictConfig `yaml:"on_conflict" validate:"required_if=Strategy merge"`
}
type CircuitBreakerConfig ¶
type ClientError ¶
type ClientError string
const ( ClientErrRateLimitExceeded ClientError = "RATE_LIMIT_EXCEEDED" ClientErrPayloadTooLarge ClientError = "PAYLOAD_TOO_LARGE" ClientErrUpstreamBodyTooLarge ClientError = "UPSTREAM_BODY_TOO_LARGE" ClientErrUpstreamError ClientError = "UPSTREAM_ERROR" ClientErrUpstreamMalformed ClientError = "UPSTREAM_MALFORMED" ClientErrInternal ClientError = "INTERNAL" ClientErrAborted ClientError = "ABORTED" ClientErrValueConflict ClientError = "VALUE_CONFLICT" )
func (ClientError) String ¶
func (err ClientError) String() string
type ClientResponse ¶
type ClientResponse struct {
Data json.RawMessage `json:"data,omitempty"`
Errors []ClientError `json:"errors,omitempty"`
Meta ResponseMeta `json:"meta,omitempty"`
}
ClientResponse is an output structure that wraps the final response from the gateway to the client.
type Config ¶
type Config struct {
Schema string `yaml:"schema" validate:"required,oneof=v1"`
Debug bool `yaml:"debug"`
Gateway GatewayConfig `yaml:"gateway" validate:"required"`
}
func LoadConfig ¶
LoadConfig reads, parses, applies defaults, validates, and returns the config.
type FlowConfig ¶
type FlowConfig struct {
Path string `yaml:"path" validate:"required,startswith=/"`
Method string `yaml:"method" validate:"required,oneof=GET POST PUT PATCH DELETE HEAD OPTIONS"`
Passthrough bool `yaml:"passthrough"`
// ParallelUpstreams defaults to 2×NumCPU when unset or zero.
ParallelUpstreams int64 `yaml:"parallel_upstreams"`
Aggregation *AggregationConfig `yaml:"aggregation" validate:"required_if=Passthrough false"`
Upstreams []UpstreamConfig `yaml:"upstreams" validate:"required,min=1,dive,required"`
Plugins []PluginConfig `yaml:"plugins" validate:"omitempty,dive"`
Middlewares []MiddlewareConfig `yaml:"middlewares" validate:"omitempty,dive"`
}
type GatewayConfig ¶
type GatewayConfig struct {
Service ServiceConfig `yaml:"service"`
Server ServerConfig `yaml:"server" validate:"required"`
Admin AdminConfig `yaml:"admin" validate:"required"`
Observability ObservabilityConfig `yaml:"observability"`
Routing RoutingConfig `yaml:"routing" validate:"required"`
}
type LoadBalancingConfig ¶
type LoadBalancingConfig struct {
Mode string `yaml:"mode"`
}
type MetricsConfig ¶
type MetricsConfig struct {
Enabled bool `yaml:"enabled"`
Exporter string `yaml:"exporter" validate:"required_if=Enabled true,omitempty,oneof=otlp prometheus"`
OTLP OTLPConfig `yaml:"otlp"`
}
type MiddlewareConfig ¶
type OTLPConfig ¶
type ObservabilityConfig ¶
type ObservabilityConfig struct {
Tracing TracingConfig `yaml:"tracing"`
Metrics MetricsConfig `yaml:"metrics"`
}
type OnConflictConfig ¶
type PluginConfig ¶
type PolicyConfig ¶
type PolicyConfig struct {
HeaderBlacklist []string `yaml:"header_blacklist"`
AllowedStatuses []int `yaml:"allowed_statuses"`
RequireBody bool `yaml:"require_body"`
MaxResponseBodySize int64 `yaml:"max_response_body_size"`
RetryConfig RetryConfig `yaml:"retry"`
CircuitBreakerConfig CircuitBreakerConfig `yaml:"circuit_breaker"`
LoadBalancingConfig LoadBalancingConfig `yaml:"load_balancing"`
}
type RateLimiterConfig ¶
type ResponseMeta ¶
type RetryConfig ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP handles incoming HTTP requests through the full router pipeline:
- Rate limiting — rejects requests exceeding the configured limit.
- Flow matching — chi router finds the flow by method and path (404 if none).
- Middleware execution — per-flow middlewares wrap the handler.
- Request plugins — run before upstream scatter; may modify the request.
- Upstream scatter — fan-out to all configured upstreams.
- Response aggregation — merge/array/namespace strategies with bestEffort support.
- Response plugins — run after aggregation; may modify headers or body.
- Response writing — status, headers, and JSON body sent to the client.
Status codes: 200 on full success, 206 on partial (bestEffort), 502/500 on failure. Every response carries an X-Request-ID header and a JSON body with data/errors fields.
type RouterBundle ¶
type RouterBundle struct {
Router *Router
MeterProvider otelcommon.Provider
TracerProvider otelcommon.Provider
PromRegistry *prometheus.Registry // nil unless metrics.exporter == "prometheus"
}
func NewRouter ¶
func NewRouter(ctx context.Context, cfgSet RoutingConfigSet, log *zap.Logger) (RouterBundle, error)
type RoutingConfig ¶
type RoutingConfig struct {
RateLimiter RateLimiterConfig `yaml:"rate_limiter" validate:"omitempty"`
TrustedProxies []string `yaml:"trusted_proxies"`
Flows []FlowConfig `yaml:"flows" validate:"min=1,dive,required"`
}
type RoutingConfigSet ¶
type RoutingConfigSet struct {
Routing RoutingConfig
Service ServiceConfig
ServiceVersion string // injected via ldflags
Metrics MetricsConfig
Tracing TracingConfig
}
type ServerConfig ¶
type ServerTLSConfig ¶
type ServerTLSConfig struct {
Enabled bool `yaml:"enabled"`
CertFile string `yaml:"cert_file" validate:"required_if=Enabled true"`
KeyFile string `yaml:"key_file" validate:"required_if=Enabled true"`
MinVersion string `yaml:"min_version" default:"1.2" validate:"omitempty,oneof=1.2 1.3"`
ClientAuth string `yaml:"client_auth" default:"none" validate:"omitempty,oneof=require optional none"`
ClientCAFile string `yaml:"client_ca_file" validate:"required_unless=ClientAuth none"`
}
type ServiceConfig ¶
type ServiceConfig struct {
Name string `yaml:"name" default:"aastro"`
}
type TLSConfig ¶
type TLSConfig struct {
Enabled bool `yaml:"enabled"`
CertFile string `yaml:"cert_file" validate:"required_with=KeyFile"`
KeyFile string `yaml:"key_file" validate:"required_with=CertFile"`
CAFile string `yaml:"ca_file"`
ServerName string `yaml:"server_name"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
MinVersion string `yaml:"min_version" default:"1.2" validate:"omitempty,oneof=1.2 1.3"`
}
type TracingConfig ¶
type TracingConfig struct {
Enabled bool `yaml:"enabled"`
Exporter string `yaml:"exporter" validate:"required_if=Enabled true,omitempty,oneof=otlp"`
SamplingRatio float64 `yaml:"sampling_ratio" default:"1.0" validate:"min=0,max=1"`
OTLP OTLPConfig `yaml:"otlp"`
}
type TransportConfig ¶
type UpstreamConfig ¶
type UpstreamConfig struct {
Name string `yaml:"name" validate:"required"`
Hosts AddrList `yaml:"hosts" validate:"min=1,dive"`
Path string `yaml:"path"`
Method string `yaml:"method"`
Timeout time.Duration `yaml:"timeout" default:"3s"`
ForwardHeaders []string `yaml:"forward_headers"`
ForwardQueries []string `yaml:"forward_queries"`
ForwardParams []string `yaml:"forward_params"`
Policy PolicyConfig `yaml:"policy"`
Transport TransportConfig `yaml:"transport"`
TLS TLSConfig `yaml:"tls"`
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
builtin
|
|
|
middlewares/auth
command
|
|
|
middlewares/compressor
command
|
|
|
middlewares/cors
command
|
|
|
middlewares/logger
command
|
|
|
middlewares/recoverer
command
|
|
|
plugins/camelify
command
|
|
|
plugins/masker
command
|
|
|
plugins/snakeify
command
|
|
|
cmd
|
|
|
aastro
command
|
|
|
aastroctl
command
|
|
|
internal
|
|
|
otelcommon
Package otelcommon builds the shared OpenTelemetry Resource used by both the metric and tracing providers, so signals from the same process share a consistent identity (service.name, service.version, host, process, …) in the observability backend.
|
Package otelcommon builds the shared OpenTelemetry Resource used by both the metric and tracing providers, so signals from the same process share a consistent identity (service.name, service.version, host, process, …) in the observability backend. |
Click to show internal directories.
Click to hide internal directories.