Documentation
¶
Index ¶
- type CircuitBreaker
- type CircuitState
- type HealthStatus
- type Middleware
- type ProxyConfig
- type RateLimitStatus
- type RateLimiter
- type Request
- type Response
- type Service
- func (s *Service) AddMiddleware(middleware *Middleware)
- func (s *Service) DeregisterInstance(instanceID string) error
- func (s *Service) GetInstances(serviceName string) []*ServiceInstance
- func (s *Service) GetMiddlewares() []*Middleware
- func (s *Service) GetRateLimiter(identifier string) *RateLimiter
- func (s *Service) GetRoutes() []*ServiceRoute
- func (s *Service) RegisterInstance(instance *ServiceInstance) error
- func (s *Service) RegisterRoute(route *ServiceRoute) error
- func (s *Service) SelectInstance(serviceName string) *ServiceInstance
- func (s *Service) UpdateInstanceHealth(instanceID string, health HealthStatus) error
- type ServiceInstance
- type ServiceRoute
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
ServiceName string `json:"service_name"`
State CircuitState `json:"state"`
FailureCount int `json:"failure_count"`
FailureThreshold int `json:"failure_threshold"`
Timeout time.Duration `json:"timeout"`
LastFailure time.Time `json:"last_failure"`
}
CircuitBreaker represents a circuit breaker for a service
type CircuitState ¶
type CircuitState int
CircuitState represents the state of a circuit breaker
const ( CircuitStateClosed CircuitState = iota CircuitStateOpen CircuitStateHalfOpen )
func (CircuitState) String ¶
func (c CircuitState) String() string
String returns the string representation of CircuitState
type HealthStatus ¶
type HealthStatus int
HealthStatus represents the health status of a service instance
const ( HealthStatusHealthy HealthStatus = iota HealthStatusUnhealthy HealthStatusUnknown )
func (HealthStatus) String ¶
func (h HealthStatus) String() string
String returns the string representation of HealthStatus
type Middleware ¶
type Middleware struct {
Name string `json:"name"`
Priority int `json:"priority"`
Handler func(ctx context.Context, req *Request) (*Request, error) `json:"-"`
}
Middleware represents a middleware function
type ProxyConfig ¶
type ProxyConfig struct {
Timeout time.Duration `json:"timeout"`
RetryAttempts int `json:"retry_attempts"`
RetryDelay time.Duration `json:"retry_delay"`
CircuitBreaker bool `json:"circuit_breaker"`
LoadBalancer string `json:"load_balancer"` // round_robin, least_connections, etc.
}
ProxyConfig represents proxy configuration
type RateLimitStatus ¶
type RateLimitStatus struct {
Limit int `json:"limit"`
Remaining int `json:"remaining"`
ResetAt time.Time `json:"reset_at"`
}
RateLimitStatus represents the current rate limit status
type RateLimiter ¶
type RateLimiter struct {
ID string `json:"id"`
Limit int `json:"limit"`
Window time.Duration `json:"window"`
Requests int `json:"requests"`
ResetAt time.Time `json:"reset_at"`
}
RateLimiter represents a rate limiter for a user or IP
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow() bool
Allow checks if a request is allowed under the rate limit
func (*RateLimiter) Status ¶
func (r *RateLimiter) Status() *RateLimitStatus
Status returns the current rate limit status
type Request ¶
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
Body []byte `json:"body,omitempty"`
UserID string `json:"user_id,omitempty"`
ClientIP string `json:"client_ip"`
}
Request represents an HTTP request in the gateway
type Response ¶
type Response struct {
StatusCode int `json:"status_code"`
Headers map[string]string `json:"headers"`
Body []byte `json:"body,omitempty"`
Duration time.Duration `json:"duration"`
}
Response represents an HTTP response from the gateway
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides API gateway functionality
func (*Service) AddMiddleware ¶
func (s *Service) AddMiddleware(middleware *Middleware)
AddMiddleware adds a middleware to the gateway
func (*Service) DeregisterInstance ¶
DeregisterInstance removes an instance from the registry
func (*Service) GetInstances ¶
func (s *Service) GetInstances(serviceName string) []*ServiceInstance
GetInstances returns all instances for a service
func (*Service) GetMiddlewares ¶
func (s *Service) GetMiddlewares() []*Middleware
GetMiddlewares returns all registered middlewares
func (*Service) GetRateLimiter ¶
func (s *Service) GetRateLimiter(identifier string) *RateLimiter
GetRateLimiter gets or creates a rate limiter for a user/IP
func (*Service) GetRoutes ¶
func (s *Service) GetRoutes() []*ServiceRoute
GetRoutes returns all registered routes
func (*Service) RegisterInstance ¶
func (s *Service) RegisterInstance(instance *ServiceInstance) error
RegisterInstance registers a service instance
func (*Service) RegisterRoute ¶
func (s *Service) RegisterRoute(route *ServiceRoute) error
RegisterRoute registers a new service route
func (*Service) SelectInstance ¶
func (s *Service) SelectInstance(serviceName string) *ServiceInstance
SelectInstance selects a healthy instance using load balancing
func (*Service) UpdateInstanceHealth ¶
func (s *Service) UpdateInstanceHealth(instanceID string, health HealthStatus) error
UpdateInstanceHealth updates the health status of an instance
type ServiceInstance ¶
type ServiceInstance struct {
ID string `json:"id"`
ServiceName string `json:"service_name"`
Address string `json:"address"`
Port int `json:"port"`
Health HealthStatus `json:"health"`
Metadata map[string]string `json:"metadata"`
LastSeen time.Time `json:"last_seen"`
RegisteredAt time.Time `json:"registered_at"`
}
ServiceInstance represents a service instance in the registry
type ServiceRoute ¶
type ServiceRoute struct {
ID string `json:"id"`
ServiceName string `json:"service_name"`
Path string `json:"path"`
Target string `json:"target"`
Methods []string `json:"methods"`
Middleware []string `json:"middleware"`
Metadata map[string]string `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ServiceRoute represents a route configuration for a service