Documentation
¶
Index ¶
- Variables
- func HostMatcher(host, dst string) bool
- func RegisterRule(rule string, matcher func(string) Matcher)
- type Context
- type Error
- type ErrorHandlerFunc
- type Forest
- func (e *Forest) MethodNotAllowed(handlers ...HandlerFunc) *Route
- func (e *Forest) Mount(child *Forest, opts ...GroupOption)
- func (e *Forest) MountGroup(child *Group, opts ...GroupOption)
- func (e *Forest) NewContext(w http.ResponseWriter, r *http.Request) *context
- func (e *Forest) NotFound(handlers ...HandlerFunc) *Route
- func (e *Forest) Route(name string) *Route
- func (e *Forest) Routes() []*Route
- func (e *Forest) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (e *Forest) SetOptions(opts ...Option)
- func (e *Forest) Shutdown(ctx stdcontext.Context) error
- func (e *Forest) Start(addr string) error
- func (e *Forest) StartTLS(addr string, certFile, keyFile string) error
- func (e *Forest) URL(name string, args ...interface{}) string
- func (e *Forest) Use(middlewares ...HandlerFunc) *Forest
- type Group
- func (g *Group) Add(method string, path string, handlers ...HandlerFunc) *Route
- func (g *Group) Any(path string, handlers ...HandlerFunc) Routes
- func (g *Group) CONNECT(path string, handlers ...HandlerFunc) *Route
- func (g *Group) DELETE(path string, handlers ...HandlerFunc) *Route
- func (g *Group) GET(path string, handlers ...HandlerFunc) *Route
- func (g *Group) Group(opts ...GroupOption) *Group
- func (g *Group) HEAD(path string, handlers ...HandlerFunc) *Route
- func (g *Group) Mount(child *Group, opts ...GroupOption)
- func (g *Group) Name() string
- func (g *Group) OPTIONS(path string, handlers ...HandlerFunc) *Route
- func (g *Group) PATCH(path string, handlers ...HandlerFunc) *Route
- func (g *Group) POST(path string, handlers ...HandlerFunc) *Route
- func (g *Group) PUT(path string, handlers ...HandlerFunc) *Route
- func (g *Group) SetOptions(opts ...GroupOption)
- func (g *Group) Static(path, root string, middlewares ...HandlerFunc) *Route
- func (g *Group) StaticFS(path string, fs http.FileSystem, middlewares ...HandlerFunc) *Route
- func (g *Group) StaticFile(path, file string, middlewares ...HandlerFunc) *Route
- func (g *Group) TRACE(path string, handlers ...HandlerFunc) *Route
- func (g *Group) Use(middlewares ...HandlerFunc) *Group
- type GroupOption
- type H
- type HandlerFunc
- type Logger
- type Matcher
- type Option
- type Response
- type Route
- func (r *Route) Desc() string
- func (r *Route) ErrorHandle(err error, c Context)
- func (r *Route) Forest() *Forest
- func (r *Route) Group() *Group
- func (r *Route) Handlers() []HandlerFunc
- func (r *Route) Host() string
- func (r *Route) Logger() Logger
- func (r *Route) Method() string
- func (r *Route) Named(name string, desc ...string) *Route
- func (r *Route) Path() string
- func (r *Route) Render(w http.ResponseWriter, name string, data interface{}) error
- func (r *Route) String() string
- func (r *Route) URL(args ...interface{}) string
- type Routes
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = NewError(http.StatusNotFound) ErrMethodNotAllowed = NewError(http.StatusMethodNotAllowed) ErrInternalServerError = NewError(http.StatusInternalServerError) NotFoundMessage = []byte(ErrNotFound.Error()) MethodNotAllowedMessage = []byte(ErrMethodNotAllowed.Error()) NotFoundHandler = func(c Context) error { return c.Bytes(http.StatusNotFound, NotFoundMessage) } MethodNotAllowedHandler = func(c Context) error { return c.Bytes(http.StatusMethodNotAllowed, MethodNotAllowedMessage) } ErrorHandler = func(err error, c Context) { if err == nil { return } e, ok := err.(*Error) if !ok { e = ErrInternalServerError } if resp := c.Response(); !resp.Written() { c.String(e.Code, e.Error()) } } )
Functions ¶
func HostMatcher ¶
func RegisterRule ¶
Types ¶
type Context ¶
type Context interface { Forest() *Forest Logger() Logger Route() *Route Request() *http.Request Response() *Response Next() error NextWith(Context) error Get(string) interface{} Set(string, interface{}) Param(string) string Params() map[string]string FormParam(string, ...string) string FormParams() (url.Values, error) QueryParam(string, ...string) string QueryParams() url.Values Cookie(string, ...*http.Cookie) (*http.Cookie, error) Cookies() []*http.Cookie SetCookie(*http.Cookie) Bind(interface{}) error BindWith(interface{}, binder.Binder) error BindParams(interface{}) error BindHeader(interface{}) error XML(int, interface{}) error JSON(int, interface{}) error JSONP(int, string, interface{}) error HTML(int, string) error Bytes(int, []byte) error String(int, string, ...interface{}) error Blob(int, string, []byte) error Render(int, string, interface{}) error RenderWith(int, render.Renderer) error File(string) error FileFromFS(string, http.FileSystem) error URL(string, ...interface{}) string Status(int) error Redirect(int, string, ...interface{}) error }
func NewContext ¶
func NewContext(r *http.Request, w http.ResponseWriter) Context
type ErrorHandlerFunc ¶
type Forest ¶
func (*Forest) MethodNotAllowed ¶
func (e *Forest) MethodNotAllowed(handlers ...HandlerFunc) *Route
func (*Forest) Mount ¶
func (e *Forest) Mount(child *Forest, opts ...GroupOption)
func (*Forest) MountGroup ¶
func (e *Forest) MountGroup(child *Group, opts ...GroupOption)
func (*Forest) NewContext ¶
func (e *Forest) NewContext(w http.ResponseWriter, r *http.Request) *context
func (*Forest) NotFound ¶
func (e *Forest) NotFound(handlers ...HandlerFunc) *Route
func (*Forest) SetOptions ¶
func (*Forest) Use ¶
func (e *Forest) Use(middlewares ...HandlerFunc) *Forest
type Group ¶
type Group struct { Logger Logger Renderer render.TemplateRenderer ErrorHandler ErrorHandlerFunc // contains filtered or unexported fields }
func NewGroup ¶
func NewGroup(opts ...GroupOption) *Group
func (*Group) Group ¶
func (g *Group) Group(opts ...GroupOption) *Group
func (*Group) Mount ¶
func (g *Group) Mount(child *Group, opts ...GroupOption)
func (*Group) SetOptions ¶
func (g *Group) SetOptions(opts ...GroupOption)
func (*Group) StaticFS ¶
func (g *Group) StaticFS(path string, fs http.FileSystem, middlewares ...HandlerFunc) *Route
func (*Group) StaticFile ¶
func (g *Group) StaticFile(path, file string, middlewares ...HandlerFunc) *Route
func (*Group) Use ¶
func (g *Group) Use(middlewares ...HandlerFunc) *Group
type GroupOption ¶
type GroupOption func(*Group)
func WithHost ¶
func WithHost(host string) GroupOption
func WithMiddlewares ¶
func WithMiddlewares(handlers ...HandlerFunc) GroupOption
func WithName ¶
func WithName(name string) GroupOption
func WithPrefix ¶
func WithPrefix(prefix string) GroupOption
func (GroupOption) Forest ¶
func (opt GroupOption) Forest() Option
type HandlerFunc ¶
func WrapHandler ¶
func WrapHandler(h http.Handler) HandlerFunc
func WrapHandlerFunc ¶
func WrapHandlerFunc(h http.HandlerFunc) HandlerFunc
type Logger ¶
type Logger interface { Info(...interface{}) Warn(...interface{}) Print(...interface{}) Error(...interface{}) Fatal(...interface{}) Panic(...interface{}) Infoln(...interface{}) Warnln(...interface{}) Println(...interface{}) Errorln(...interface{}) Fatalln(...interface{}) Panicln(...interface{}) Infof(string, ...interface{}) Warnf(string, ...interface{}) Printf(string, ...interface{}) Errorf(string, ...interface{}) Fatalf(string, ...interface{}) Panicf(string, ...interface{}) }
type Option ¶
type Option func(*Forest)
func Middlewares ¶
func Middlewares(handlers ...HandlerFunc) Option
func (Option) Group ¶
func (opt Option) Group() GroupOption
type Response ¶
type Response struct { http.ResponseWriter Size int Status int }
func NewResponse ¶
func NewResponse(w http.ResponseWriter) *Response
func (*Response) WriteHeader ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.