Documentation
¶
Index ¶
- func ParsePattern(pattern string) []string
- type Context
- func (context *Context) Data(code int, data []byte)
- func (context *Context) Fail(code int, err string)
- func (context *Context) HTML(code int, name string, data interface{})
- func (context *Context) JSON(code int, obj interface{})
- func (context *Context) Next()
- func (context *Context) Param(key string) string
- func (context *Context) PostForm(key string) string
- func (context *Context) Query(key string) string
- func (context *Context) SetHeader(key string, value string)
- func (context *Context) Status(code int)
- func (context *Context) String(code int, format string, values ...interface{})
- type Engine
- func (engine *Engine) AddRoute(method string, pattern string, handler HandleFunc)
- func (engine *Engine) GET(pattern string, handler HandleFunc)
- func (engine *Engine) LoadHTMLGlob(pattern string)
- func (engine *Engine) POST(pattern string, handler HandleFunc)
- func (engine *Engine) Run(addr string) error
- func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (engine *Engine) SetFuncMap(funcMap template.FuncMap)
- type H
- type HandleFunc
- type Router
- type RouterGroup
- func (group *RouterGroup) AddRoute(method string, comp string, handler HandleFunc)
- func (group *RouterGroup) CreateStaticHandler(relativePath string, fs http.FileSystem) HandleFunc
- func (group *RouterGroup) GET(comp string, handler HandleFunc)
- func (group *RouterGroup) Group(prefix string) *RouterGroup
- func (group *RouterGroup) POST(comp string, handler HandleFunc)
- func (group *RouterGroup) Static(relativePath string, root string)
- func (group *RouterGroup) Use(middlewares ...HandleFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
//origin objects
Writer http.ResponseWriter
Req *http.Request
//request info
Path string
Method string
Params map[string]string
//response info
StatusCode int
//middlewares
Middlewares []HandleFunc
// contains filtered or unexported fields
}
上下文
type Engine ¶
type Engine struct {
*RouterGroup
// contains filtered or unexported fields
}
Engine实现ServeHTTP的接口,添加路由映射表
func (*Engine) AddRoute ¶
func (engine *Engine) AddRoute(method string, pattern string, handler HandleFunc)
添加静态路由的方法
func (*Engine) LoadHTMLGlob ¶
func (*Engine) ServeHTTP ¶
func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
解析请求路径,查找路由映射表。如果查到就执行注册的方法,否则返回404
func (*Engine) SetFuncMap ¶
type HandleFunc ¶
type HandleFunc func(context *Context)
定义路由映射的处理方法
func Recovery ¶
func Recovery() HandleFunc
type Router ¶
type Router struct {
Handlers map[string]HandleFunc
// contains filtered or unexported fields
}
type RouterGroup ¶
type RouterGroup struct {
Middlewares []HandleFunc //中间件
// contains filtered or unexported fields
}
路由分组
func (*RouterGroup) AddRoute ¶
func (group *RouterGroup) AddRoute(method string, comp string, handler HandleFunc)
按组添加路由
func (*RouterGroup) CreateStaticHandler ¶
func (group *RouterGroup) CreateStaticHandler(relativePath string, fs http.FileSystem) HandleFunc
创建静态文件服务
func (*RouterGroup) POST ¶
func (group *RouterGroup) POST(comp string, handler HandleFunc)
按组添加POST路由
func (*RouterGroup) Static ¶
func (group *RouterGroup) Static(relativePath string, root string)
启动静态文件服务
Click to show internal directories.
Click to hide internal directories.