Documentation
¶
Overview ¶
Package routers provides the router interface and the implementation of different routing policies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // MALL represents the methodType that can match all methods. MALL = mCONNECT | mDELETE | mGET | mHEAD | mOPTIONS | mPATCH | mPOST | mPUT | mTRACE // Methods represents the mapping of http method and methodType. Methods = map[string]MethodType{ http.MethodGet: mGET, http.MethodHead: mHEAD, http.MethodPost: mPOST, http.MethodPut: mPUT, http.MethodPatch: mPATCH, http.MethodDelete: mDELETE, http.MethodConnect: mCONNECT, http.MethodOptions: mOPTIONS, http.MethodTrace: mTRACE, } )
Functions ¶
Types ¶
type Header ¶
type Header struct { Key string `json:"key" jsonschema:"required"` Values []string `json:"values,omitempty" jsonschema:"omitempty,uniqueItems=true"` Regexp string `json:"regexp,omitempty" jsonschema:"omitempty,format=regexp"` // contains filtered or unexported fields }
Header is the third level entry of router. A header entry is always under a specific path entry, that is to mean the headers entry will only be checked after a path entry matched. However, the headers entry has a higher priority than the path entry itself.
type Headers ¶
type Headers []*Header
Headers represents the set of headers.
type Host ¶
type Host struct { IsRegexp bool `json:"isRegexp" jsonschema:"omitempty"` Value string `json:"value" jsonschema:"required"` // contains filtered or unexported fields }
Host defines the host match rule.
type Kind ¶
type Kind struct { // Name is the name of the router kind. Name string // Description is the description of the router. Description string // CreateInstance creates a new router instance of the kind. CreateInstance func(rules Rules) Router }
Kind contains the meta data and functions of a router kind.
type MethodType ¶
type MethodType uint
MethodType represents the bit-operated representation of the http method.
type Params ¶
type Params struct {
Keys, Values []string
}
Params are used to store the variables in the search path and their corresponding values.
type Path ¶
type Path struct { IPFilterSpec *ipfilter.Spec `json:"ipFilter,omitempty" jsonschema:"omitempty"` Path string `json:"path,omitempty" jsonschema:"omitempty,pattern=^/"` PathPrefix string `json:"pathPrefix,omitempty" jsonschema:"omitempty,pattern=^/"` PathRegexp string `json:"pathRegexp,omitempty" jsonschema:"omitempty,format=regexp"` RewriteTarget string `json:"rewriteTarget" jsonschema:"omitempty"` Methods []string `json:"methods,omitempty" jsonschema:"omitempty,uniqueItems=true,format=httpmethod-array"` Backend string `json:"backend" jsonschema:"required"` ClientMaxBodySize int64 `json:"clientMaxBodySize" jsonschema:"omitempty"` Headers Headers `json:"headers" jsonschema:"omitempty"` Queries Queries `json:"queries,omitempty" jsonschema:"omitempty"` MatchAllHeader bool `json:"matchAllHeader" jsonschema:"omitempty"` MatchAllQuery bool `json:"matchAllQuery" jsonschema:"omitempty"` // contains filtered or unexported fields }
Path is second level entry of router.
func (*Path) GetBackend ¶
GetBackend is used to get the backend corresponding to the route.
func (*Path) GetClientMaxBodySize ¶
GetClientMaxBodySize is used to get the clientMaxBodySize corresponding to the route.
func (*Path) Match ¶
func (p *Path) Match(context *RouteContext) bool
Match is the matching function of path.
type Queries ¶
type Queries []*Query
Queries represents the set of queries.
type Query ¶
type Query struct { Key string `json:"key" jsonschema:"required"` Values []string `json:"values,omitempty" jsonschema:"omitempty,uniqueItems=true"` Regexp string `json:"regexp,omitempty" jsonschema:"omitempty,format=regexp"` // contains filtered or unexported fields }
Query is the third level entry.
type Route ¶
type Route interface { // Rewrite for path rewriting. Rewrite(context *RouteContext) // GetBackend is used to get the backend corresponding to the route. GetBackend() string // GetClientMaxBodySize is used to get the clientMaxBodySize corresponding to the route. GetClientMaxBodySize() int64 }
Route is the corresponding route interface for different routing policies.
type RouteContext ¶
type RouteContext struct { // Request is httpprot.Request. Request *httpprot.Request // Path represents the path of the request. Path string // Method represents the MethodType corresponding to the http method. Method MethodType // Params are used to store the variables in the search path and their corresponding values. Params Params // Cacheable means whether the route can be cached or not. Cacheable bool // Route represents the results of this search Route Route HeaderMismatch, MethodMismatch, QueryMismatch, IPMismatch bool // contains filtered or unexported fields }
RouteContext is the context container in the route search
func NewContext ¶
func NewContext(req *httpprot.Request) *RouteContext
NewContext creates a context instance.
func (*RouteContext) GetCaptures ¶
func (ctx *RouteContext) GetCaptures() map[string]string
GetCaptures is used to get and cache path parameter mappings.
func (*RouteContext) GetHeader ¶
func (ctx *RouteContext) GetHeader() http.Header
GetHeader is used to get request http header.
func (*RouteContext) GetHost ¶
func (ctx *RouteContext) GetHost() string
GetHost is used to get and cache host.
func (*RouteContext) GetQueries ¶
func (ctx *RouteContext) GetQueries() url.Values
GetQueries is used to get and cache query params.
type Router ¶
type Router interface { // Search performs a route search and populates the context with search-related information. Search(context *RouteContext) }
Router is the interface for route search.
type Rule ¶
type Rule struct { // NOTICE: If the field is a pointer, it must have `omitempty` in tag `json` // when it has `omitempty` in tag `jsonschema`. // Otherwise it will output null value, which is invalid in json schema (the type is object). // the original reason is the jsonscheme(genjs) has not support multiple types. // Reference: https://github.com/alecthomas/jsonschema/issues/30 // In the future if we have the scenario where we need marshal the field, but omitempty // in the schema, we are suppose to support multiple types on our own. IPFilterSpec *ipfilter.Spec `json:"ipFilter,omitempty" jsonschema:"omitempty"` Host string `json:"host" jsonschema:"omitempty"` HostRegexp string `json:"hostRegexp" jsonschema:"omitempty,format=regexp"` Hosts []Host `json:"hosts" jsonschema:"omitempty"` Paths Paths `json:"paths" jsonschema:"omitempty"` // contains filtered or unexported fields }
Rule is first level entry of router.
func (*Rule) MatchHost ¶
func (rule *Rule) MatchHost(ctx *RouteContext) bool
MatchHost matches the host of the request to the rule.
Directories
¶
Path | Synopsis |
---|---|
Package ordered provides the router implementation of ordered routing policy.
|
Package ordered provides the router implementation of ordered routing policy. |
Package radixtree provides the router implementation of radix tree routing policy.
|
Package radixtree provides the router implementation of radix tree routing policy. |