Documentation ¶
Overview ¶
Package router supplies a router interface ane some implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Router ¶
type Router interface { // Range traverses all the registered routes. Range(func(name, path, method string, handler interface{})) // Path generates a url path by the path name and parameters. // // Return "" if there is not the route path named name. Path(name string, params ...interface{}) string // Add adds the route and returns the number of the parameters // if there are the parameters in the route path. // // name is the name of the path, which is optional and must be unique // if not empty. // // If method is empty, handler is the handler of all the methods supported // by the implementation. Or, it is only that of the given method. // // For the parameter in the path, the format is determined by the implementation. Add(name, path, method string, handler interface{}) (paramNum int, err error) // Del deletes the given route. // // If method is empty, deletes all the routes associated with the path. // Or, only delete the given method for the path. Del(path, method string) (err error) // Match matches the route by path and method, puts the path parameters // into pnames and pvalues, then returns the handler and the number // of the path paramethers. // // If pnames or pvalues is empty, it will ignore the path paramethers // when finding the route handler. // // Return (nil, 0) if not found the route handler. Match(path, method string, pnames, pvalues []string) (handler interface{}, pn int) }
Router is a router manager based on the path with the optional method.
func NewLockRouter ¶
NewLockRouter returns a new lock Router based on the original router r. So it's safe to access and modify the routes concurrently and safely.
Notice: the wrapped router must not panic.
Click to show internal directories.
Click to hide internal directories.