spec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spec holds the New API route table and the parser that derives it from upstream router source.

The table is the contract between this server and a New API release. It is regenerated by cmd/routesync from the exact git tag of the running instance, so "which endpoints exist" is never a guess.

Index

Constants

View Source
const UpstreamVersion = "v1.0.0-rc.47"

UpstreamVersion is the New API git tag this table was extracted from.

Variables

View Source
var Routes = []Route{}/* 312 elements not displayed */

Routes is every admin (method, path) pair registered by that release.

Functions

func CanonicalPath

func CanonicalPath(p string) string

CanonicalPath strips a trailing slash, except for the root.

func GroupOf

func GroupOf(path string) string

GroupOf derives the grouping bucket for a path.

func Has

func Has(method, path string) bool

Has reports whether the pair is in the table, ignoring a trailing-slash difference.

func Index

func Index(routes []Route) map[string]Route

Index maps a route key to the route.

func Paths

func Paths() []string

Paths returns every registered path, for diagnostics.

func Resolve

func Resolve(method, path string) (resolved string, ok bool)

Resolve maps a method+path onto the spelling the running release actually registered, tolerating a missing or extra trailing slash.

Gin treats "/api/log" and "/api/log/" as different routes. New API is not consistent about which one it registers, and a mismatch is expensive: a GET survives the 301 redirect, but a POST or PUT turns into a GET and silently loses its body. Resolving against the table turns that class of bug into a non-event.

ok is false when the pair is not in the table at all; the caller should then decide whether to send it anyway (api_request) or fail.

func SortRoutes

func SortRoutes(routes []Route)

Sort orders routes by path then method for stable output.

func Validate

func Validate(routes []Route) error

Validate rejects obviously malformed routes before they reach the table.

Types

type Route

type Route struct {
	Method string `json:"method"`
	Path   string `json:"path"`
	// Group is the first path segment after /api, e.g. "channel".
	Group  string `json:"group"`
	Source string `json:"source,omitempty"`
}

Route is one registered (method, path) pair on the admin surface.

func Diff

func Diff(local, upstream []Route) (missing, stale []Route)

Diff reports which routes exist upstream but not locally (missing), and which exist locally but no longer exist upstream (stale).

func Filter

func Filter(routes []Route, prefix string) []Route

Filter returns the routes whose path starts with prefix.

func Match

func Match(method, path string) (Route, bool)

Match reports whether a concrete request path matches a registered route, treating ":param" segments as single-segment wildcards.

Has answers "is this exact spelling in the table"; Match answers "would the gateway route this request". Tools call concrete paths such as /api/channel/7, so Match is the right question to ask about them.

func ParseRouterFile

func ParseRouterFile(source string) []Route

ParseRouterFile extracts every admin route registered in one New API router Go source file.

Three registration styles coexist in New API and a regex for only one of them produces a wildly wrong table:

channelRoute.GET("/test/:id", handler)                       // direct
handlePermissionRoute(channelRoute, "GET", "/ops", perm, h)   // helper, often multi-line
var channelPermissionRoutes = []permissionRoute{             // table-driven, invisible
    {method: http.MethodGet, path: "/priority/order", ...},  //   to the two above
}

Returns the routes and the parser's best guess at the file's primary /api group.

func (Route) Key

func (r Route) Key() string

Key is the comparable identity of a route.

Gin registers "/api/channel" and "/api/channel/" as distinct paths, so the table preserves exactly what upstream declares. Comparison ignores the trailing slash because New API is not consistent about which form it uses.

Jump to

Keyboard shortcuts

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