urlmap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do:

  • host rules: exact host (with port, then without) beats the longest wildcard suffix ("*.example.com", "*-example.com"), which beats "*"; no match uses the URL map's defaults;
  • path rules: the longest matching path wins ("/a/*" matches "/a/" and below, never "/a"); an exact path beats a prefix of equal length; no match uses the path matcher's defaults;
  • route rules: the lowest priority whose any matchRule matches (path prefix/full/regex/template, header and query parameter matches);
  • actions: service, routeAction (weighted backend services, URL rewrite, timeout, retries, ...), urlRedirect; header actions apply from the most specific level (weighted backend, rule, path matcher, map).

Validate reports the configuration errors GCP rejects, and RunTests runs a URL map's tests[] (urlMaps.validate, insert).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedirectCode

func RedirectCode(c string) int

RedirectCode maps redirectResponseCode to an HTTP status.

func RunTests

func RunTests(m *compute.UrlMap, same func(a, b string) bool) []*compute.TestFailure

RunTests evaluates m's tests[] and returns the failures. same reports whether two service references name the same resource.

func Validate

func Validate(m *compute.UrlMap) []string

Validate returns the errors GCP reports for an invalid URL map (empty when valid).

func WalkServices

func WalkServices(m *compute.UrlMap, fn func(field string, ref *string) error) error

WalkServices calls fn for every backend reference in m (default services, rule services, weighted backends, mirrors, error services and test expectations) with the request field path, so callers can canonicalise and check them.

Types

type Redirect

type Redirect struct {
	Code     int
	Location string
}

Redirect is a computed redirect response.

type Request

type Request struct {
	// Scheme is "http" or "https".
	Scheme string
	Method string
	// Host is the Host header (or :authority), possibly with a port.
	Host string
	// Path is the URL path (without query).
	Path string
	// RawQuery is the query string without "?".
	RawQuery string
	Header   http.Header
}

Request is the routing input.

type Result

type Result struct {
	// Redirect is set when the request is answered with a redirect.
	Redirect *Redirect
	// Service is the selected backend service or bucket (as written in
	// the URL map, normally a selfLink).
	Service string
	// Action is the effective route action (nil when none).
	Action *compute.HttpRouteAction
	// HeaderActions apply in order (most specific first).
	HeaderActions []*compute.HttpHeaderAction
	// Host and Path are the request host and path after URL rewrites.
	Host, Path string
	// ErrorPolicy is the effective custom error response policy.
	ErrorPolicy *compute.CustomErrorResponsePolicy
	// PathMatcher names the matched path matcher ("" for map defaults).
	PathMatcher string
}

Result is the routing decision.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is a compiled URL map. It is immutable and safe for concurrent use.

func Compile

func Compile(m *compute.UrlMap) (*Router, error)

Compile prepares m for routing. It fails on configurations Validate rejects.

func (*Router) Route

func (rt *Router) Route(req *Request, pick func(total int64) int64) *Result

Route selects the action for req. pick chooses among weighted backends (nil uses a random choice proportional to weight).

Jump to

Keyboard shortcuts

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