route

package
v1.21.70 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package route is the registration point for every HTTP route an application serves, so routes it writes itself are observed like generated operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meta

type Meta struct {
	// Entity and Verb name the operation the way a generated one is named, so
	// one trail reads consistently whichever surface produced the entry.
	Entity string
	Verb   string
	// ReadOnly declares that the route changes nothing. It defaults to false so
	// an undeclared route is treated as a mutation: over-recording is recoverable,
	// a missing record is not.
	ReadOnly bool
	// IDParam names the wildcard in the pattern holding the record the call acts
	// on, e.g. "id" for "DELETE /api/v1/monitors/{id}". Empty when the route
	// addresses a collection.
	IDParam string
	// SelfRouted marks a mount whose handler does its own method and sub-path
	// dispatch, so no single declaration can describe what a request to it did.
	// Verb then comes from the request method and ReadOnly from whether that
	// method is safe - deliberately coarser than a declaration, and opt-in at
	// the registration site so it reads as a known gap rather than an accident.
	// A route setting it has not finished migrating: splitting it into declared
	// routes, or into entity operations, is what removes it.
	SelfRouted bool
}

Meta is what a route declares about itself at its registration site. Nothing here is derived from the URL: a listener reading an event never has to decompose a path or infer intent from a method, which is the whole reason the declaration lives next to the handler.

type Router

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

Router registers routes onto a mux and observes the ones the application wrote itself. Generated routes are mounted unobserved: clicky already reports them at the entity layer, and reporting them again here would double every entry in the trail.

func NewRouter

func NewRouter(mux *http.ServeMux) *Router

NewRouter routes through mux, or through a fresh one when mux is nil.

func (*Router) MountGenerated

func (r *Router) MountGenerated(pattern string, handler http.Handler)

MountGenerated registers a route clicky generated from a registered entity or command. It is deliberately unobserved: those operations are already reported at the entity layer, and reporting them again at the transport would double every generated entry in the trail. Application routes use Raw.

func (*Router) Raw

func (r *Router) Raw(pattern string, handler http.Handler, meta Meta)

Raw registers a handler the application wrote itself. The handler is called exactly as it would be on a bare mux — its response, streaming and connection handling all reach the client untouched — and its completion is reported to every operation listener.

func (*Router) RawFunc

func (r *Router) RawFunc(pattern string, handler http.HandlerFunc, meta Meta)

RawFunc is Raw for a handler function.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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