route

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package route extracts HTTP endpoints from a Go project's source and maps each to the handler function that serves it. Each web framework has its own registration API, so detection is delegated to per-framework Extractors. The net/http extractor is the universal base.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor interface {
	Name() string
	// Match reports whether the package uses this framework (by imports).
	Match(pkg *packages.Package) bool
	// Extract walks the package syntax and returns its routes.
	Extract(pkg *packages.Package) []Route
}

Extractor detects routes for a single framework.

func Default

func Default() []Extractor

Default returns the built-in extractors (auto-detected per package).

type Route

type Route struct {
	Method  string      // GET/POST/... or "ANY"
	Path    string      // URL path (best-effort; "" when dynamic/unknown)
	Handler *types.Func // resolved handler func, or nil if unresolvable (e.g. inline closure)
	Pos     token.Pos   // position of the route registration site (for click-to-source)
}

Route is one detected HTTP endpoint.

func Extract

func Extract(pkgs []*packages.Package, extractors []Extractor) []Route

Extract runs the given extractors over all packages, returning every route found. An extractor only runs on a package it Match-es.

Jump to

Keyboard shortcuts

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