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
- Variables
- func CanonicalPath(p string) string
- func GroupOf(path string) string
- func Has(method, path string) bool
- func Index(routes []Route) map[string]Route
- func Paths() []string
- func Resolve(method, path string) (resolved string, ok bool)
- func SortRoutes(routes []Route)
- func Validate(routes []Route) error
- type Route
Constants ¶
const UpstreamVersion = "v1.0.0-rc.47"
UpstreamVersion is the New API git tag this table was extracted from.
Variables ¶
var Routes = []Route{}/* 312 elements not displayed */
Routes is every admin (method, path) pair registered by that release.
Functions ¶
func CanonicalPath ¶
CanonicalPath strips a trailing slash, except for the root.
func Resolve ¶
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.
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 ¶
Diff reports which routes exist upstream but not locally (missing), and which exist locally but no longer exist upstream (stale).
func Match ¶
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 ¶
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.