Documentation
¶
Overview ¶
Package routes is the inventory of an application's routes (driftgate/routes.json), the routes excluded from checking (driftgate/exclusions.yaml), and coverage: which routes no catalog request reaches.
Index ¶
Constants ¶
const Multipart = "multipart/form-data"
Multipart is the body type of a route that takes files.
const Version = 1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Kind string `json:"kind"` // route-added, route-removed, route-changed
Route string `json:"route"`
What string `json:"what,omitempty"`
}
Change is a difference between two inventories.
func DiffInventories ¶
DiffInventories lists routes that were added, removed or changed.
type Coverage ¶
type Coverage struct {
Covered []string // route keys reached by a request
Excluded map[string]string // route key → reason
Uncovered []string // neither reached by a request that should succeed nor excluded
Negative []string // reached only by requests that expect an error (not-found, invalid-param…); also in Uncovered
Requests map[string][]string // route key → request IDs
Unknown []string // requests that reach no route
Stale []string // exclusions that match no route
NoBody []string // routes that take a body and have no sample
}
Coverage is the result of checking a catalog against the inventory.
type Exclusion ¶
type Exclusion struct {
Target string `yaml:"target,omitempty"` // only routes of this service; empty: every service
Route string `yaml:"route"` // "METHOD /path" glob; without a method it matches every method
Reason string `yaml:"reason"`
}
Exclusion is a route that is deliberately not checked.
type Exclusions ¶
Exclusions is driftgate/exclusions.yaml.
func LoadExclusions ¶
func LoadExclusions(path string) (*Exclusions, error)
LoadExclusions reads exclusions.yaml; a missing file excludes nothing.
func (*Exclusions) Excluded ¶
func (e *Exclusions) Excluded(r Route) *Exclusion
Excluded returns the exclusion that covers the route, if any.
func (*Exclusions) ExcludedUnit ¶
func (e *Exclusions) ExcludedUnit(r Route, unit string) *Exclusion
ExcludedUnit returns the exclusion that covers one method of the route.
type FileField ¶
FileField is a field of a multipart body that takes a file, with the synthetic kind (upload.Kinds) a generated request sends in it.
type Inventory ¶
Inventory is driftgate/routes.json.
func LoadInventory ¶
LoadInventory reads routes.json; a missing file is an empty inventory.
type Route ¶
type Route struct {
Methods []string `json:"methods"` // "*" means any method
Path string `json:"path"`
Target string `json:"target,omitempty"` // the service, with several targets
Domain string `json:"domain,omitempty"`
Name string `json:"name,omitempty"`
Action string `json:"action,omitempty"`
File string `json:"file,omitempty"` // source file of the action, relative to the project root, with :line when known
Middleware []string `json:"middleware,omitempty"`
Auth bool `json:"auth,omitempty"` // needs an authenticated identity
Body json.RawMessage `json:"body,omitempty"` // sample request body
Query map[string]string `json:"query,omitempty"` // required query parameters with sample values
BodySource string `json:"body_source,omitempty"`
BodyType string `json:"body_type,omitempty"` // media type of the body when not application/json
Files []FileField `json:"files,omitempty"` // file fields of a multipart/form-data body
Source string `json:"source"` // adapter that found it
}
Route is one route of the application. A path names its parameters in braces: {id} is required, {id?} optional, {slug*} takes the rest of the path (one or more segments) and {slug*?} the rest or nothing.
func Match ¶
Match finds the route a request reaches: of the routes whose method and path match, the most specific one.
func (Route) Pattern ¶
Pattern returns a regular expression that matches the request paths of the route. A segment may hold several parameters (/files/{name}.{ext}); an optional parameter that fills a whole segment makes the segment optional, one inside a segment (user-{group?}) only its value.
func (Route) Units ¶
Units lists the methods a route is checked with: each one, since they usually have separate handlers (GET and POST of a Next.js route), except that PUT and PATCH of one route are the same handler (Laravel Route::match, resource update) and count as PUT. A route that takes any method counts as GET.