 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package routing defines the HTTP routes for Traffic Ops and provides tools to register those routes with appropriate middleware.
Index ¶
- Constants
- func CompileRoutes(routes map[string][]PathHandler) map[string][]CompiledRoute
- func CreateRouteMap(rs []Route, rawRoutes []RawRoute, perlRouteIDs, disabledRouteIDs []int, ...) (map[string][]PathHandler, map[api.Version]struct{})
- func DBStatsHandler(db *sqlx.DB) http.HandlerFunc
- func GetRouteIDMap(IDs []int) map[int]struct{}
- func Handler(routes map[string][]CompiledRoute, versions map[api.Version]struct{}, ...)
- func IsRequestAPIAndUnknownVersion(req *http.Request, versions map[api.Version]struct{}) bool
- func MemoryStatsHandler() http.HandlerFunc
- func RegisterRoutes(d ServerData) error
- func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error)
- type CompiledRoute
- type PathHandler
- type RawRoute
- type Route
- type ServerData
- type ThrottledHandler
Constants ¶
const Authenticated = true
    Authenticated ...
const NoAuth = false
    NoAuth ...
const RoutePrefix = "^api" // TODO config?
    RoutePrefix ...
Variables ¶
This section is empty.
Functions ¶
func CompileRoutes ¶
func CompileRoutes(routes map[string][]PathHandler) map[string][]CompiledRoute
CompileRoutes - takes a map of methods to paths and handlers, and returns a map of methods to CompiledRoutes
func CreateRouteMap ¶
func CreateRouteMap(rs []Route, rawRoutes []RawRoute, perlRouteIDs, disabledRouteIDs []int, perlHandler http.HandlerFunc, authBase middleware.AuthBase, reqTimeOutSeconds int) (map[string][]PathHandler, map[api.Version]struct{})
CreateRouteMap returns a map of methods to a slice of paths and handlers; wrapping the handlers in the appropriate middleware. Uses Semantic Versioning: routes are added to every subsequent minor version, but not subsequent major versions. For example, a 1.2 route is added to 1.3 but not 2.1. Also truncates '2.0' to '2', creating succinct major versions. Returns the map of routes, and a map of API versions served.
func DBStatsHandler ¶
func DBStatsHandler(db *sqlx.DB) http.HandlerFunc
func GetRouteIDMap ¶
GetRouteIDMap takes a []int Route IDs and converts it into a map for fast lookup.
func Handler ¶
func Handler( routes map[string][]CompiledRoute, versions map[api.Version]struct{}, catchall http.Handler, db *sqlx.DB, cfg *config.Config, getReqID func() uint64, plugins plugin.Plugins, w http.ResponseWriter, r *http.Request, )
Handler - generic handler func used by the Handlers hooking into the routes
func IsRequestAPIAndUnknownVersion ¶
IsRequestAPIAndUnknownVersion returns true if the request starts with `/api` and is a version not in the list of versions.
func MemoryStatsHandler ¶
func MemoryStatsHandler() http.HandlerFunc
func RegisterRoutes ¶
func RegisterRoutes(d ServerData) error
RegisterRoutes - parses the routes and registers the handlers with the Go Router
Types ¶
type CompiledRoute ¶
CompiledRoute ...
type PathHandler ¶
type PathHandler struct {
	Path    string
	Handler http.HandlerFunc
	ID      int
}
    PathHandler ...
type RawRoute ¶
type RawRoute struct {
	// Order matters! Do not reorder this! Routes() uses positional construction for readability.
	Method            string
	Path              string
	Handler           http.HandlerFunc
	RequiredPrivLevel int
	Authenticated     bool
	Middlewares       []middleware.Middleware
}
    RawRoute is an HTTP route to be served at the root, rather than under /api/version. Raw Routes should be rare, and almost exclusively converted old Perl routes which have yet to be moved to an API path.
type Route ¶
type Route struct {
	// Order matters! Do not reorder this! Routes() uses positional construction for readability.
	Version           api.Version
	Method            string
	Path              string
	Handler           http.HandlerFunc
	RequiredPrivLevel int
	Authenticated     bool
	Middlewares       []middleware.Middleware
	ID                int  // unique ID for referencing this Route
	CanBypassToPerl   bool // if true, this Route can be passed through to Perl
}
    Route ...
type ServerData ¶
type ServerData struct {
	config.Config
	DB        *sqlx.DB
	Profiling *bool // Yes this is a field in the config but we want to live reload this value and NOT the entire config
	Plugins   plugin.Plugins
}
    ServerData ...
type ThrottledHandler ¶
ThrottledHandler ...
func CreateThrottledHandler ¶
func CreateThrottledHandler(handler http.Handler, maxConcurrentCalls int) ThrottledHandler
CreateThrottledHandler takes a handler, and a max and uses a channel to insure the handler is used concurrently by only max number of routines
func (ThrottledHandler) ServeHTTP ¶
func (m ThrottledHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
       Directories
      ¶
      Directories
      ¶
    
    | Path | Synopsis | 
|---|---|
| Package middleware provides symbols for HTTP "middleware" which wraps handlers to perform common behaviors, such as authentication, headers, and compression. | Package middleware provides symbols for HTTP "middleware" which wraps handlers to perform common behaviors, such as authentication, headers, and compression. |