Documentation
¶
Overview ¶
Package router implements first-match HTTP request routing.
Routes are evaluated in order. The first route whose path pattern, domain pattern, and method filter match the incoming request is selected. If no route matches, the router returns nil and the caller should respond with 404.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MatchResult ¶
type MatchResult struct {
RouteIndex int // index of the matched route in the service's route list
Action string // resolved action name
DomainPattern string // the pattern from config, e.g. "*.myapp.dev"
MatchDomain string // captured "*" wildcard value(s), e.g. "sub" for *.myapp.dev
MatchGlob string // captured "**" glob suffix, e.g. "example.com" for *.storage.**
MatchPath string // the path pattern, e.g. "/api/*"
Domain string // actual request host (no port)
Path string // actual request path
Target string // selected target from balancer (empty if no balancer)
Vars map[string]string // route-level variables from "set"
// Speed limiting — populated from route config.
// Shared buckets are route-wide; BPS rates are for per-connection bucket creation.
DownloadBucket *throttle.Bucket // shared download bucket (nil when per-conn or no limit)
UploadBucket *throttle.Bucket // shared upload bucket (nil when per-conn or no limit)
DownloadBps int64 // per-connection download bytes/sec (0 = no limit)
UploadBps int64 // per-connection upload bytes/sec (0 = no limit)
// contains filtered or unexported fields
}
MatchResult holds data captured during route matching, available to handlers.
func GetMatchResult ¶
func GetMatchResult(r *http.Request) *MatchResult
GetMatchResult retrieves the MatchResult from request context.
func (*MatchResult) Done ¶
func (m *MatchResult) Done()
Done signals that the request/connection has completed. For connection-tracking balancers (e.g. leastconn), this decrements the active connection counter. Safe to call multiple times or on nil.
func (*MatchResult) RouteID ¶
func (m *MatchResult) RouteID(service string) string
RouteID returns a compact identifier for this route (e.g. "web:0").
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router holds compiled routes for a single service.
func (*Router) HasSpeed ¶
HasSpeed returns true if any route in this router has speed limiting configured.
func (*Router) Match ¶
Match finds the first matching route and returns the enriched request with MatchResult stored in context, plus the action name.
func (*Router) MatchAction ¶
MatchAction returns only the action name for the matching route, without allocating a MatchResult or modifying the request context. Used by the handler fast path when plugins and access logging are disabled.
func (*Router) RouteBalancer ¶
RouteBalancer returns the balancer instance for the route at the given index. Returns nil if the index is out of range or the route has no balancer.