Documentation ¶
Index ¶
- type Context
- func (ctx *Context) BaseContext() context.Context
- func (ctx *Context) BindJson(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) FormBool(key string, def bool) (bool, bool)
- func (ctx *Context) FormFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) FormFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) FormInt64(key string, def int64) (int64, bool)
- func (ctx *Context) FormStringSlice(key string, def []string) ([]string, bool)
- func (ctx *Context) FromFile(key string) (*multipart.FileHeader, error)
- func (ctx *Context) GetRawData() ([]byte, error)
- func (ctx *Context) GetRequest() *http.Request
- func (ctx *Context) GetResponse() http.ResponseWriter
- 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) 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) 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) QueryString(key string, def string) (string, bool)
- func (ctx *Context) QueryStringSlice(key string, def []string) ([]string, bool)
- 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) 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) *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, handlers ...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
}
func NewContext ¶
func NewContext(r *http.Request, w http.ResponseWriter) *Context
NewContext 初始化一个Context
func (*Context) BaseContext ¶
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) QueryFloat32 ¶
func (*Context) QueryFloat64 ¶
func (*Context) QueryString ¶
func (*Context) QueryStringSlice ¶
func (*Context) SetCookie ¶
func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, httpOnly bool) IResponse
Cookie
func (*Context) SetHandlers ¶
func (ctx *Context) SetHandlers(handlers []ControllerHandler)
func (*Context) SetHasTimeout ¶
func (ctx *Context) SetHasTimeout()
type ControllerHandler ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
服务框架核心结构
func (*Core) Delete ¶
func (c *Core) Delete(url string, handlers ...ControllerHandler)
对应 Method = DELETE
func (*Core) FindRouteByRequest ¶
匹配路由,如果没有匹配到,返回nil
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Use ¶
func (g *Group) Use(middlewares ...ControllerHandler)
type IGroup ¶
type IGroup interface { Get(string, ...ControllerHandler) Post(string, ...ControllerHandler) Put(string, ...ControllerHandler) Delete(string, ...ControllerHandler) Group(prefix string) IGroup // 嵌套中间件 Use(middlewares ...ControllerHandler) }
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{} // 路由匹配中带的参数 // 形如 /book/:id 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) }
代表请求包含的方法
type IResponse ¶
type IResponse interface { // Json 输出 Json(obj interface{}) IResponse // Jsonp 输出 Jsonp(obj interface{}) IResponse //xml 输出 Xml(obj interface{}) IResponse // html 输出 Html(template 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 代表返回方法
Click to show internal directories.
Click to hide internal directories.