Documentation
¶
Index ¶
- type Gateway
- func (gw *Gateway) AddRoute(config RouteConfig) error
- func (gw *Gateway) GetStats() *GatewayStats
- func (gw *Gateway) ListRoutes() map[string]*Route
- func (gw *Gateway) RemoveRoute(path string)
- func (gw *Gateway) Start() error
- func (gw *Gateway) Stop(ctx context.Context) error
- func (gw *Gateway) Use(middleware MiddlewareFunc)
- type GatewayConfig
- type GatewayStats
- type MiddlewareFunc
- type RewriteRule
- type Route
- type RouteConfig
- type RouteStats
- type TransformConfig
- type TransformRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway represents an API gateway
func NewGateway ¶
func NewGateway(config *GatewayConfig, logger *slog.Logger) (*Gateway, error)
NewGateway creates a new API gateway
func (*Gateway) AddRoute ¶
func (gw *Gateway) AddRoute(config RouteConfig) error
AddRoute adds a new route to the gateway
func (*Gateway) GetStats ¶
func (gw *Gateway) GetStats() *GatewayStats
GetStats returns gateway statistics
func (*Gateway) ListRoutes ¶
ListRoutes returns all configured routes
func (*Gateway) RemoveRoute ¶
RemoveRoute removes a route from the gateway
func (*Gateway) Use ¶
func (gw *Gateway) Use(middleware MiddlewareFunc)
Use adds middleware to the gateway
type GatewayConfig ¶
type GatewayConfig struct {
Name string
ListenAddr string
UpstreamTimeout time.Duration
MaxRetries int
RetryDelay time.Duration
RateLimitConfig *ratelimit.RateLimitConfig
Routes []RouteConfig
}
GatewayConfig holds the configuration for the API gateway
type GatewayStats ¶
type GatewayStats struct {
TotalRequests int64
SuccessfulRequests int64
FailedRequests int64
AverageResponseTime time.Duration
LastRequestTime time.Time
RouteStats map[string]*RouteStats
}
GatewayStats holds gateway statistics
type MiddlewareFunc ¶
MiddlewareFunc represents a middleware function
type RewriteRule ¶
RewriteRule defines a URL rewrite rule
type Route ¶
type Route struct {
Path string
Methods map[string]bool
UpstreamURL *url.URL
StripPrefix string
AddHeaders map[string]string
Transform *TransformConfig
RewriteRules []RewriteRule
}
Route represents a configured route
type RouteConfig ¶
type RouteConfig struct {
Path string `json:"path"`
Methods []string `json:"methods"`
UpstreamURL string `json:"upstream_url"`
StripPrefix string `json:"strip_prefix,omitempty"`
AddHeaders map[string]string `json:"add_headers,omitempty"`
Transform *TransformConfig `json:"transform,omitempty"`
RewriteRules []RewriteRule `json:"rewrite_rules,omitempty"`
}
RouteConfig defines a route configuration
type RouteStats ¶
type RouteStats struct {
RequestCount int64
SuccessCount int64
ErrorCount int64
AverageResponseTime time.Duration
LastRequestTime time.Time
}
RouteStats holds statistics for a specific route
type TransformConfig ¶
type TransformConfig struct {
Request *TransformRule `json:"request,omitempty"`
Response *TransformRule `json:"response,omitempty"`
}
TransformConfig defines request/response transformation rules
type TransformRule ¶
type TransformRule struct {
AddFields map[string]interface{} `json:"add_fields,omitempty"`
RemoveFields []string `json:"remove_fields,omitempty"`
RenameFields map[string]string `json:"rename_fields,omitempty"`
FilterFields []string `json:"filter_fields,omitempty"`
}
TransformRule defines a transformation rule