Documentation ¶
Index ¶
Constants ¶
View Source
const ( // FullMatchTarget is a match for full regular expression. All regexp router without expression // will use the expression. FullMatchTarget = ".*" // TailMatchTarget is a match expression for tail only. TailMatchTarget = "*" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶
type Container interface { // Set sets key-value into the container. Set(key, value string) // Get gets a value by key from the container. Get(key string) (string, bool) }
Container is a key-value container. It saves key-values from path.
type Inspector ¶
type Inspector interface { // Inspect finds a valid executor to execute target context. // It returns an error if it can't find a valid executor. Inspect(context.Context) (executor.MiddlewareExecutor, error) }
Inspector can select an executor to execute.
type Router ¶
type Router interface { // Target returns the matching target of the node. // It can be a fixed string or a regular expression. Target() string // Kind returns the kind of the router node. Kind() RouteKind // Match find an executor matched by path. // The context contains information to inspect executor. // The container can save key-value pair from the path. // If the router is the leaf node to match the path, it will return // the first executor which Inspect() returns true. Match(ctx context.Context, c Container, path string) (executor.MiddlewareExecutor, error) // AddMiddleware adds middleware to the router node. // If the router matches a path, all middlewares in the router // will be executed by the returned executor. AddMiddleware(ms ...definition.Middleware) // Middlewares returns all middlewares of the router. // Don't modify the returned values. Middlewares() []definition.Middleware // SetInspector sets inspector to the router node. SetInspector(inspector Inspector) // Inspector gets inspector from the router node. // Don't modify the returned values. Inspector() Inspector // Merge merges r to the current router. The type of r should be same // as the current one or it panics. // // For instance: // Router A: /namespaces/ -> {namespace} // Router B: /nameless/ -> {other} // Result: // /name -> spaces/ -> {namespace} // |-> less/ -> {other} Merge(r Router) (Router, error) }
Router describes the interface of a router node.
Click to show internal directories.
Click to hide internal directories.