Help us shape the future of Go! Take the 2026 Go Developer Survey

router

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package router holds the registration sink core route registration writes to.

Core handlers register on a Recorder instead of the real *http.ServeMux so the server can install each recorded pattern later — wrapped, where a plugin has claimed it with a route override. Nothing here knows about plugins, overrides, or the server; it only records what was registered, in order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Recorder

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

Recorder records route registrations instead of serving them.

It deliberately has no ServeHTTP: a Recorder is a registration sink, not a router, so it is impossible to ship a build where the recorder is serving traffic. Registrations are kept in insertion order, so installing them onto a real mux reproduces the original registration sequence.

A Recorder is not safe for concurrent use; route registration happens on the single startup goroutine.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns an empty Recorder.

func (*Recorder) Err

func (rec *Recorder) Err() error

Err returns the first registration error, or nil. Callers check it once, after all core routes have been registered and before anything is installed.

func (*Recorder) Handle

func (rec *Recorder) Handle(pattern string, handler http.Handler)

Handle records handler under pattern. A duplicate pattern, an empty pattern, or a nil handler records an error (if none is recorded yet) and makes the call a no-op, keeping the first handler registered for that pattern.

func (*Recorder) HandleFunc

func (rec *Recorder) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc records handler under pattern, converting it to an http.Handler the same way *http.ServeMux does.

func (*Recorder) Has

func (rec *Recorder) Has(pattern string) bool

Has reports whether pattern was recorded. The match is an exact string comparison on the full `"METHOD /path/{wildcard}"` pattern: "GET /x" and "GET /x" are distinct patterns to ServeMux too, and a fuzzy match would let a route override silently attach to a route its author did not mean.

func (*Recorder) Routes

func (rec *Recorder) Routes() []Route

Routes returns the recorded routes in registration order. The slice is a copy, so a caller cannot append into the recorder's own storage.

type Route

type Route struct {
	Pattern string
	Handler http.Handler
}

Route is one recorded registration: the pattern exactly as it was passed in, and the handler to serve it.

type Router

type Router interface {
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

Router is the subset of *http.ServeMux that route registration uses. *http.ServeMux satisfies it, so a caller can register on a real mux or on a Recorder without either side knowing which. The public plugin contracts (pdk.Plugin, plugin.Plugin) keep *http.ServeMux — this interface exists for core route registration only.

Jump to

Keyboard shortcuts

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