routing

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package routing manages gateway route configuration, matching, load balancing, traffic splitting, and API versioning.

Index

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 NewManager

func NewManager() *Manager

NewManager creates a new route manager.

func (*Manager) AddRoute

func (rm *Manager) AddRoute(route *bastion.Route) error

AddRoute adds a new route to the table.

func (*Manager) GetRoute

func (rm *Manager) GetRoute(id string) (*bastion.Route, bool)

GetRoute returns a route by ID.

func (*Manager) ListRoutes

func (rm *Manager) ListRoutes() []*bastion.Route

ListRoutes returns all routes.

func (*Manager) MatchRoute

func (rm *Manager) MatchRoute(path, method string) *bastion.Route

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

func (rm *Manager) RemoveByServiceName(serviceName string)

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

func (rm *Manager) RemoveRoute(id string) error

RemoveRoute removes a route by ID.

func (*Manager) RouteCount

func (rm *Manager) RouteCount() int

RouteCount returns the number of routes.

func (*Manager) UpdateRoute

func (rm *Manager) UpdateRoute(route *bastion.Route) error

UpdateRoute updates an existing route.

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

func (ts *TrafficSplitter) FilterTargets(r *http.Request, route *bastion.Route) []*bastion.Target

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL