Documentation ¶
Index ¶
- type Context
- func (ctx *Context) BaseContext() context.Context
- func (ctx *Context) BindJson(obj interface{}) error
- func (ctx *Context) BindJsonTest(obj interface{}) error
- func (ctx *Context) BindXml(obj interface{}) error
- func (ctx *Context) ClientIp() string
- func (ctx *Context) Cookie(key string) (string, bool)
- func (ctx *Context) Cookies() map[string]string
- func (ctx *Context) Deadline() (deadline time.Time, ok bool)
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) Err() error
- func (ctx *Context) Form(key string) interface{}
- func (ctx *Context) FormAll() map[string][]string
- func (ctx *Context) FormAllTest() map[string][]string
- func (ctx *Context) FormBool(key string, def bool) (bool, bool)
- func (ctx *Context) FormFile(key string) (*multipart.FileHeader, error)
- func (ctx *Context) FormFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) FormFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) FormInt(key string, def int) (int, bool)
- func (ctx *Context) FormInt64(key string, def int64) (int64, bool)
- func (ctx *Context) FormIntTest(key string, def int) int
- func (ctx *Context) FormString(key string, def string) (string, bool)
- func (ctx *Context) FormStringSlice(key string, def []string) ([]string, bool)
- func (ctx *Context) FormStringTest(key string, def string) string
- func (ctx *Context) GetRawData() ([]byte, error)
- func (ctx *Context) GetRequest() *http.Request
- func (ctx *Context) GetResponse() http.ResponseWriter
- func (ctx *Context) HTML(status int, obj interface{}, template string) error
- func (ctx *Context) HasTimeout() bool
- func (ctx *Context) Header(key string) (string, bool)
- func (ctx *Context) Headers() map[string][]string
- func (ctx *Context) Host() string
- func (ctx *Context) Html(file string, obj interface{}) IResponse
- func (ctx *Context) Json(obj interface{}) IResponse
- func (ctx *Context) JsonTest(status int, obj interface{}) error
- func (ctx *Context) Jsonp(obj interface{}) IResponse
- func (ctx *Context) Method() string
- func (ctx *Context) Next() error
- func (ctx *Context) Param(key string) interface{}
- func (ctx *Context) ParamBool(key string, def bool) (bool, bool)
- func (ctx *Context) ParamFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) ParamFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) ParamInt(key string, def int) (int, bool)
- func (ctx *Context) ParamInt64(key string, def int64) (int64, bool)
- func (ctx *Context) ParamString(key string, def string) (string, bool)
- func (ctx *Context) Query(key string) interface{}
- func (ctx *Context) QueryAll() map[string][]string
- func (ctx *Context) QueryAllTest() map[string][]string
- func (ctx *Context) QueryArray(key string, def []string) []string
- func (ctx *Context) QueryBool(key string, def bool) (bool, bool)
- func (ctx *Context) QueryFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) QueryFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) QueryInt(key string, def int) (int, bool)
- func (ctx *Context) QueryInt64(key string, def int64) (int64, bool)
- func (ctx *Context) QueryIntTest(key string, def int) int
- func (ctx *Context) QueryString(key string, def string) (string, bool)
- func (ctx *Context) QueryStringSlice(key string, def []string) ([]string, bool)
- func (ctx *Context) QueryStringTest(key string, def string) string
- func (ctx *Context) Redirect(path string) IResponse
- func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, ...) IResponse
- func (ctx *Context) SetHandlers(handlers []ControllerHandler)
- func (ctx *Context) SetHasTimeout()
- func (ctx *Context) SetHeader(key string, val string) IResponse
- func (ctx *Context) SetOkStatus() IResponse
- func (ctx *Context) SetParams(params map[string]string)
- func (ctx *Context) SetStatus(code int) IResponse
- func (ctx *Context) Text(format string, values ...interface{}) IResponse
- func (ctx *Context) TextTest(status int, obj string) error
- func (ctx *Context) Uri() string
- func (ctx *Context) Value(key interface{}) interface{}
- func (ctx *Context) WriterMux() *sync.Mutex
- func (ctx *Context) Xml(obj interface{}) IResponse
- type ControllerHandler
- type Core
- func (c *Core) Delete(url string, handlers ...ControllerHandler)
- func (c *Core) FindRouteByRequest(request *http.Request) []ControllerHandler
- func (c *Core) FindRouteNodeByRequest(request *http.Request) *node
- func (c *Core) Get(url string, handlers ...ControllerHandler)
- func (c *Core) Group(prefix string) IGroup
- func (c *Core) Post(url string, handlers ...ControllerHandler)
- func (c *Core) Put(url string, handlers ...ControllerHandler)
- func (c *Core) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (c *Core) Use(middlewares ...ControllerHandler)
- type Group
- func (g *Group) Delete(uri string, handler ...ControllerHandler)
- func (g *Group) Get(uri string, handlers ...ControllerHandler)
- func (g *Group) Group(uri string) IGroup
- func (g *Group) Post(uri string, handlers ...ControllerHandler)
- func (g *Group) Put(uri string, handlers ...ControllerHandler)
- func (g *Group) Use(middlewares ...ControllerHandler)
- type IGroup
- type IRequest
- type IResponse
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context 自定义 Context
func NewContext ¶
func NewContext(r *http.Request, w http.ResponseWriter) *Context
func (*Context) BaseContext ¶
func (*Context) BindJsonTest ¶
func (*Context) FormAllTest ¶
FormAll 提取所有表单参数
func (*Context) FormFile ¶
func (ctx *Context) FormFile(key string) (*multipart.FileHeader, error)
FormFile 获取上传文件
func (*Context) FormFloat32 ¶
func (*Context) FormFloat64 ¶
func (*Context) FormStringSlice ¶
func (*Context) GetRequest ¶
func (*Context) GetResponse ¶
func (ctx *Context) GetResponse() http.ResponseWriter
func (*Context) HasTimeout ¶
func (*Context) ParamFloat32 ¶
func (*Context) ParamFloat64 ¶
func (*Context) ParamString ¶
func (*Context) QueryAllTest ¶
QueryAll 提取所有query参数 map[string][]string: http://example.com/search?tag=science&tag=technology&tag=math result:map["tag"][]string{"science", "technology", "math"}
func (*Context) QueryArray ¶
QueryArray 获取query的指定key值
func (*Context) QueryFloat32 ¶
QueryFloat32 获取query的转为float32数据
func (*Context) QueryFloat64 ¶
QueryFloat64 获取query的转我float64数据
func (*Context) QueryInt64 ¶
QueryInt64 获取请求中的参数转为int64
func (*Context) QueryIntTest ¶
QueryInt 获取query指定key的int值
func (*Context) QueryString ¶
QueryString 获取query的字符串数据
func (*Context) QueryStringSlice ¶
QueryStringSlice 将参数转为切片
func (*Context) QueryStringTest ¶
QueryString 获取query指定key的string值
func (*Context) SetCookie ¶
func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, httpOnly bool) IResponse
SetCookie 设置cookie
func (*Context) SetHandlers ¶
func (ctx *Context) SetHandlers(handlers []ControllerHandler)
SetHandlers 将涉及到的中间件和控制器加入ctx中
func (*Context) SetHasTimeout ¶
func (ctx *Context) SetHasTimeout()
type ControllerHandler ¶
func TimeoutHandler ¶
func TimeoutHandler(function ControllerHandler, d time.Duration) ControllerHandler
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core 框架核心结构 框架的核心,负责路由匹配,server接口实现,初始路由,注册方法
func (*Core) Delete ¶
func (c *Core) Delete(url string, handlers ...ControllerHandler)
Delete DELETE方法路由注册
func (*Core) FindRouteByRequest ¶
func (c *Core) FindRouteByRequest(request *http.Request) []ControllerHandler
FindRouteByRequest 匹配路由,如果没有匹配到,返回nil
func (*Core) FindRouteNodeByRequest ¶
FindRouteNodeByRequest 匹配路由,如果没有匹配到,返回nil
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 前缀匹配的具体实现者
func (*Group) Delete ¶
func (g *Group) Delete(uri string, handler ...ControllerHandler)
func (*Group) Get ¶
func (g *Group) Get(uri string, handlers ...ControllerHandler)
func (*Group) Post ¶
func (g *Group) Post(uri string, handlers ...ControllerHandler)
func (*Group) Put ¶
func (g *Group) Put(uri string, handlers ...ControllerHandler)
type IGroup ¶
type IGroup interface { Get(string, ...ControllerHandler) Post(string, ...ControllerHandler) Put(string, ...ControllerHandler) Delete(string, ...ControllerHandler) Use(middlewares ...ControllerHandler) Group(uri string) IGroup }
IGroup 代表前缀分组
type IRequest ¶
type IRequest interface { // 请求地址 url 中带的参数 // 形如: foo.com?a=1&b=bar&c[]=bar QueryInt(key string, def int) (int, bool) QueryInt64(key string, def int64) (int64, bool) QueryFloat64(key string, def float64) (float64, bool) QueryFloat32(key string, def float32) (float32, bool) QueryBool(key string, def bool) (bool, bool) QueryString(key string, def string) (string, bool) QueryStringSlice(key string, def []string) ([]string, bool) Query(key string) interface{} ParamInt(key string, def int) (int, bool) ParamInt64(key string, def int64) (int64, bool) ParamFloat64(key string, def float64) (float64, bool) ParamFloat32(key string, def float32) (float32, bool) ParamBool(key string, def bool) (bool, bool) ParamString(key string, def string) (string, bool) Param(key string) interface{} // form 表单中带的参数 FormInt(key string, def int) (int, bool) FormInt64(key string, def int64) (int64, bool) FormFloat64(key string, def float64) (float64, bool) FormFloat32(key string, def float32) (float32, bool) FormBool(key string, def bool) (bool, bool) FormString(key string, def string) (string, bool) FormStringSlice(key string, def []string) ([]string, bool) FormFile(key string) (*multipart.FileHeader, error) Form(key string) interface{} // json body BindJson(obj interface{}) error // xml body BindXml(obj interface{}) error // 其他格式 GetRawData() ([]byte, error) // 基础信息 Uri() string Method() string Host() string ClientIp() string // header Headers() map[string][]string Header(key string) (string, bool) // cookie Cookies() map[string]string Cookie(key string) (string, bool) }
IRequest 代表请求包含的方法
type IResponse ¶
type IResponse interface { // Json输出 Json(obj interface{}) IResponse // Jsonp输出 Jsonp(obj interface{}) IResponse //xml输出 Xml(obj interface{}) IResponse // html输出 Html(file string, obj interface{}) IResponse // string Text(format string, values ...interface{}) IResponse // 重定向 Redirect(path string) IResponse // header SetHeader(key string, val string) IResponse // Cookie SetCookie(key string, val string, maxAge int, path, domain string, secure, httpOnly bool) IResponse // 设置状态码 SetStatus(code int) IResponse // 设置200状态 SetOkStatus() IResponse }
IResponse 代表返回方法
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree 前缀树
func (*Tree) AddRouter ¶
func (tree *Tree) AddRouter(uri string, handlers []ControllerHandler) error
AddRouter 增加路由节点, 路由节点有先后顺序
/book/list /book/:id (冲突) /book/:id/name /book/:student/age /:user/name(冲突) /:user/name/:age
func (*Tree) FindHandler ¶
func (tree *Tree) FindHandler(uri string) []ControllerHandler
FindHandler 匹配uri
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package gin implements a HTTP web framework called gin.
|
Package gin implements a HTTP web framework called gin. |