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 (*Recorder) Err ¶
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 ¶
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 ¶
HandleFunc records handler under pattern, converting it to an http.Handler the same way *http.ServeMux does.
func (*Recorder) Has ¶
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.
type Route ¶
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.