Documentation
¶
Overview ¶
Package denco provides fast URL router.
Index ¶
- Constants
- Variables
- func CleanPath(p string) string
- func NextSeparator(path string, start int) int
- type Mux
- func (m *Mux) Any(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Build() (http.Handler, error)
- func (m *Mux) Delete(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Get(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Group(pattern string, fn func(), handlers ...http.HandlerFunc)
- func (m *Mux) Head(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Options(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Patch(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Post(pattern string, handlers ...http.HandlerFunc)
- func (m *Mux) Put(pattern string, handlers ...http.HandlerFunc)
- type Param
- type Params
- type Record
- type ResponseWriter
- type Router
Constants ¶
const ( // ParamCharacter is a special character for path parameter. ParamCharacter = ':' // WildcardCharacter is a special character for wildcard path parameter. WildcardCharacter = '*' // TerminationCharacter is a special character for end of path. TerminationCharacter = '#' // MaxSize is max size of records and internal slice. MaxSize = (1 << 22) - 1 )
Variables ¶
var NotFound = http.HandlerFunc(http.NotFound)
Functions ¶
func NextSeparator ¶
NextSeparator returns an index of next separator in path.
Types ¶
type Mux ¶
type Mux struct {
NotFound http.HandlerFunc
// contains filtered or unexported fields
}
type Record ¶
type Record struct {
// Key for router construction.
Key string
// Result value for Key.
Value interface{}
}
Record represents a record data for router construction.
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Flusher
// Status returns the status code of the response or 200 if the response has
// not been written (as this is the default response code in net/http)
Status() int
// Written returns whether or not the ResponseWriter has been written.
Written() bool
// Size returns the size of the response body.
Size() int
// Before allows for a function to be called before the ResponseWriter has been written to. This is
// useful for setting headers or any other operations that must happen before a response has been written.
Before(func(ResponseWriter))
}
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type Router ¶
type Router struct {
// SizeHint expects the maximum number of path parameters in records to Build.
// SizeHint will be used to determine the capacity of the memory to allocate.
// By default, SizeHint will be determined from given records to Build.
SizeHint int
// contains filtered or unexported fields
}
Router represents a URL router.
func (*Router) Lookup ¶
Lookup returns data and path parameters that associated with path. params is a slice of the Param that arranged in the order in which parameters appeared. e.g. when built routing path is "/path/to/:id/:name" and given path is "/path/to/1/alice". params order is [{"id": "1"}, {"name": "alice"}], not [{"name": "alice"}, {"id": "1"}].