routedump

package
v1.27.0 Latest Latest
Warning

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

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

Documentation

Overview

Package routedump is the wire format between a Nucleus application that prints its route table at boot (NUCLEUS_PRINT_ROUTES=1, read by pkg/nucleus.RunContext) and the `nucleus routes` command that runs the application to read it. Both sides import this package so the document shape, the environment variable and the line marker cannot drift apart.

The document travels on the application's stdout, where the structured logger also writes, so it is emitted as ONE line carrying a schema marker that no log line can start with; Parse scans stdout for that line and ignores everything else.

Index

Constants

View Source
const EnvVar = "NUCLEUS_PRINT_ROUTES"

EnvVar is the environment variable the application reads at boot. Any value other than empty, "0" or "false" turns the dump on.

View Source
const Schema = "nucleus.routes/v1"

Schema identifies the document version; it doubles as the line marker Parse looks for.

Variables

This section is empty.

Functions

func Enabled

func Enabled(value string) bool

Enabled reports whether an environment value asks for the dump.

func Encode

func Encode(w io.Writer, doc Document) error

Encode writes doc as a single line ending in "\n". The schema field is forced to Schema and placed first, so the line starts with the marker Parse searches for regardless of what the caller filled in.

Types

type Document

type Document struct {
	Schema string  `json:"schema"`
	Env    string  `json:"env"`
	Routes []Route `json:"routes"`
}

Document is what the application prints.

func Parse

func Parse(stdout []byte) (doc Document, found bool, err error)

Parse finds the document line in an application's captured stdout. It returns found=false when no line carries the marker (the binary did not honour the variable — an older framework, or a main that never reaches nucleus.Run), and an error when the marker line does not decode.

type Route

type Route struct {
	// Method is the HTTP method, or "*" when the entry answers every method
	// (a mounted subtree or a method-less Handle).
	Method string `json:"method"`
	// Pattern is the full request path pattern, module prefix applied.
	Pattern string `json:"pattern"`
	// Module names the module that registered the route; empty for the
	// framework's own routes.
	Module string `json:"module,omitempty"`
	// Middlewares counts the middleware wrapped around the entry at
	// registration time.
	Middlewares int `json:"middlewares"`
}

Route is one entry of the application's route table.

Jump to

Keyboard shortcuts

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