Documentation
¶
Overview ¶
Package routing manages gateway route configuration, matching, load balancing, traffic splitting, and API versioning.
Index ¶
- func NewLoadBalancer(strategy bastion.LoadBalanceStrategy) bastion.LoadBalancer
- type Manager
- func (rm *Manager) AddRoute(route *bastion.Route) error
- func (rm *Manager) GetRoute(id string) (*bastion.Route, bool)
- func (rm *Manager) ListRoutes() []*bastion.Route
- func (rm *Manager) MatchRoute(path, method string) *bastion.Route
- func (rm *Manager) OnRouteChange(fn func(bastion.RouteEvent))
- func (rm *Manager) RemoveByServiceName(serviceName string)
- func (rm *Manager) RemoveBySource(source bastion.RouteSource)
- func (rm *Manager) RemoveRoute(id string) error
- func (rm *Manager) RouteCount() int
- func (rm *Manager) UpdateRoute(route *bastion.Route) error
- type TrafficSplitter
- type VersionMapping
- type VersionRouter
- type VersioningConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLoadBalancer ¶
func NewLoadBalancer(strategy bastion.LoadBalanceStrategy) bastion.LoadBalancer
NewLoadBalancer creates a load balancer for the given strategy.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the dynamic route table with thread-safe operations.
func (*Manager) ListRoutes ¶
ListRoutes returns all routes.
func (*Manager) MatchRoute ¶
MatchRoute finds the best matching route for a request path and method.
func (*Manager) OnRouteChange ¶
func (rm *Manager) OnRouteChange(fn func(bastion.RouteEvent))
OnRouteChange registers a listener for route events.
func (*Manager) RemoveByServiceName ¶
RemoveByServiceName removes all routes for a service.
func (*Manager) RemoveBySource ¶
func (rm *Manager) RemoveBySource(source bastion.RouteSource)
RemoveBySource removes all routes from a specific source.
func (*Manager) RemoveRoute ¶
RemoveRoute removes a route by ID.
func (*Manager) RouteCount ¶
RouteCount returns the number of routes.
type TrafficSplitter ¶
type TrafficSplitter struct {
// contains filtered or unexported fields
}
TrafficSplitter evaluates traffic rules to determine target selection.
func NewTrafficSplitter ¶
func NewTrafficSplitter(enabled bool) *TrafficSplitter
NewTrafficSplitter creates a new traffic splitter.
func (*TrafficSplitter) FilterTargets ¶
FilterTargets filters targets based on the route's traffic policy and request. Returns the filtered targets, or the original targets if no policy applies.
func (*TrafficSplitter) ShouldMirror ¶
func (ts *TrafficSplitter) ShouldMirror(route *bastion.Route) string
ShouldMirror returns the mirror target URL if the request should be mirrored.
type VersionMapping ¶
type VersionMapping struct {
Version string `json:"version"`
TargetTags []string `json:"targetTags,omitempty"`
PathPrefix string `json:"pathPrefix,omitempty"`
}
VersionMapping maps a version label to routing targets.
type VersionRouter ¶
type VersionRouter struct {
// contains filtered or unexported fields
}
VersionRouter resolves the requested API version and selects appropriate targets from a route.
func NewVersionRouter ¶
func NewVersionRouter(cfg VersioningConfig) *VersionRouter
NewVersionRouter creates a new version router.
func (*VersionRouter) FilterTargets ¶
func (vr *VersionRouter) FilterTargets(r *http.Request, targets []*bastion.Target) []*bastion.Target
FilterTargets returns the subset of route targets that match the version mapping's target tags. If no mapping is found, all targets are returned.
func (*VersionRouter) Resolve ¶
func (vr *VersionRouter) Resolve(r *http.Request) *VersionMapping
Resolve extracts the version from the request and returns the matching VersionMapping. Returns nil if versioning is disabled or no match.
type VersioningConfig ¶
type VersioningConfig struct {
// Enabled activates version-aware routing.
Enabled bool `json:"enabled"`
// Strategy is "path" or "header".
Strategy string `json:"strategy"`
// HeaderName is used when Strategy == "header" (e.g. "Accept-Version").
HeaderName string `json:"headerName,omitempty"`
// DefaultVersion is the fallback version when none is specified.
DefaultVersion string `json:"defaultVersion,omitempty"`
// Mappings maps version labels to target tags or upstream groups.
Mappings []VersionMapping `json:"mappings,omitempty"`
}
VersioningConfig configures API version routing.