Documentation
¶
Index ¶
- Variables
- func DetectConflict(newRoute *RouteRule, existingRoutes []RouteRule) error
- func IsSystemRoute(name string) bool
- func ValidateMatcher(matcher RouteMatcher) error
- func ValidateMatchers(matchers []RouteMatcher) error
- func ValidatePriority(priority int) error
- func ValidateRoute(route *RouteRule) error
- func ValidateRouteName(name string) error
- func ValidateURL(targetURL string) error
- type BodyFieldMatcher
- type BodyRegexMatcher
- type CompositeMatcher
- type Config
- type HeaderMatcher
- type Matcher
- type MethodMatcher
- type PathMatcher
- type QueryParamMatcher
- type RouteCondition
- type RouteMatcher
- type RouteRule
- type RouteRules
- type Router
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRouteName = errors.New("invalid route name: must be alphanumeric with hyphens or underscores") ErrRouteNameRequired = errors.New("route name is required") ErrInvalidURL = errors.New("invalid target URL") ErrInvalidMatcher = errors.New("invalid route matcher configuration") ErrInvalidRegex = errors.New("invalid regex pattern in matcher") ErrRouteConflict = errors.New("route conflicts with existing route") ErrSystemRouteProtected = errors.New("system route cannot be modified or deleted") ErrRouteNotFound = errors.New("route not found") ErrInvalidPriority = errors.New("invalid priority: must be between 0 and 1000") ErrNoMatchers = errors.New("route must have at least one matcher or be a default rule") ErrMultipleDefaultRoutes = errors.New("only one default route is allowed") ErrInvalidStripPrefix = errors.New("strip_prefix must start with /") )
Route validation and management errors.
var ErrNoMatchingRoute = errors.New("no matching route found")
ErrNoMatchingRoute indicates that no route matched the request.
Functions ¶
func DetectConflict ¶
DetectConflict checks if a new route conflicts with existing routes. This is a basic implementation that checks for exact name conflicts. More sophisticated conflict detection could check for overlapping matchers.
func IsSystemRoute ¶
IsSystemRoute checks if a route is a protected system route.
func ValidateMatcher ¶
func ValidateMatcher(matcher RouteMatcher) error
ValidateMatcher checks if a single route matcher is valid.
func ValidateMatchers ¶
func ValidateMatchers(matchers []RouteMatcher) error
ValidateMatchers checks if route matchers are valid.
func ValidatePriority ¶
ValidatePriority checks if priority is within valid range.
func ValidateRoute ¶
ValidateRoute performs comprehensive validation on a route rule.
func ValidateRouteName ¶
ValidateRouteName checks if a route name is valid. Valid names contain only alphanumeric characters, hyphens, and underscores.
func ValidateURL ¶
ValidateURL checks if a target URL is valid.
Types ¶
type BodyFieldMatcher ¶
BodyFieldMatcher matches against a specific field in the request body (JSON).
type BodyRegexMatcher ¶
type BodyRegexMatcher struct {
Pattern string
}
BodyRegexMatcher matches against the entire request body using regex.
type CompositeMatcher ¶
type CompositeMatcher struct {
Matchers []Matcher
}
CompositeMatcher allows combining multiple matchers with AND logic.
type Config ¶
type Config struct {
Routes []RouteRule `json:"routes"`
DefaultURL string `json:"default_url,omitempty"` // Fallback if no default rule is defined
}
Config contains the routing configuration.
type HeaderMatcher ¶
HeaderMatcher matches against a specific header value.
type Matcher ¶
Matcher defines the interface for request matching logic.
func CreateCompositeMatcher ¶
func CreateCompositeMatcher(matchers []RouteMatcher) Matcher
CreateCompositeMatcher creates a composite matcher from multiple RouteMatcher configurations.
func CreateMatcher ¶
func CreateMatcher(rm RouteMatcher) Matcher
CreateMatcher creates matchers from RouteMatcher configuration.
type MethodMatcher ¶
MethodMatcher matches against the HTTP method.
type PathMatcher ¶
PathMatcher matches against the request path.
type QueryParamMatcher ¶
QueryParamMatcher matches against a query parameter value.
type RouteCondition ¶
type RouteCondition string
RouteCondition defines the type of condition to match.
const ( RouteConditionPath RouteCondition = "path" RouteConditionMethod RouteCondition = "method" RouteConditionHeader RouteCondition = "header" RouteConditionBodyField RouteCondition = "body_field" RouteConditionBodyRegex RouteCondition = "body_regex" RouteConditionQueryParam RouteCondition = "query_param" )
type RouteMatcher ¶
type RouteMatcher struct {
Condition RouteCondition `json:"condition"`
Field string `json:"field,omitempty"` // For headers, query params, or body fields
Pattern string `json:"pattern"` // Pattern to match (can be regex or exact)
IsRegex bool `json:"is_regex,omitempty"` // Whether pattern is a regex
}
RouteMatcher defines a single matching condition (for configuration).
type RouteRule ¶
type RouteRule struct {
Name string `json:"name"`
TargetURL string `json:"target_url"`
Matchers []RouteMatcher `json:"matchers"` // All matchers must match (AND logic)
Priority int `json:"priority"` // Higher priority rules are checked first
DefaultRule bool `json:"default_rule"` // If true, this rule matches when no others do
StripPrefix string `json:"strip_prefix,omitempty"` // Prefix to strip from the path
Enabled *bool `json:"enabled,omitempty"` // If false, route is skipped. Defaults to true if not set.
EventType string `json:"event_type,omitempty"` // Event type for audit logging
ATLS bool `json:"atls,omitempty"` // Whether aTLS is expected for this route
// contains filtered or unexported fields
}
RouteRule defines a complete routing rule.
type RouteRules ¶
type RouteRules []RouteRule
RouteRules implements sort.Interface for []RouteRule based on Priority field. Routes are sorted in descending order of priority (higher priority first).
func (RouteRules) Len ¶
func (r RouteRules) Len() int
func (RouteRules) Less ¶
func (r RouteRules) Less(i, j int) bool
func (RouteRules) Swap ¶
func (r RouteRules) Swap(i, j int)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) DetermineTarget ¶
func (*Router) UpdateRoutes ¶
UpdateRoutes atomically replaces the current routes with new ones. This allows runtime modification of routes without restart.