Documentation
¶
Index ¶
- Constants
- func IsDebugging() bool
- func SetMode(mode int)
- func SetWriter(writer io.Writer)
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) ClientIP() string
- func (ctx *Context) Cookie(key string) (string, error)
- func (ctx *Context) Get(key string) (interface{}, bool)
- func (ctx Context) GetAllPostForm() url.Values
- func (ctx Context) GetAllQuery() url.Values
- func (ctx *Context) GetDefaultQuery(key, defaultVal string) string
- func (ctx *Context) GetPostForm(key string) string
- func (ctx *Context) GetPostFormArray(key string) []string
- func (ctx *Context) GetPostFormFile(key string) *multipart.FileHeader
- func (ctx *Context) GetPostFormFileArray(key string) (list []*multipart.FileHeader)
- func (ctx *Context) GetPostFormMap(key string) (dicts map[string]string, exists bool)
- func (ctx *Context) GetQuery(key string) string
- func (ctx *Context) GetQueryArray(key string) (list []string)
- func (ctx *Context) GetQueryMap(key string) (dicts map[string]string, exists bool)
- func (ctx *Context) GetRequestHeader(key string) string
- func (ctx *Context) HTML(code int, html string)
- func (ctx *Context) JSON(code int, val M)
- func (ctx *Context) Next()
- func (ctx *Context) NotFound()
- func (ctx *Context) Param(key string) string
- func (ctx *Context) Redirect(code int, location string)
- func (ctx *Context) Render(tplName string, params map[string]interface{})
- func (ctx *Context) SavePostFormFile(file *multipart.FileHeader, dst string) error
- func (ctx *Context) Set(key string, val interface{})
- func (ctx *Context) ShouldBindBodyWith(obj interface{}, bb binding.IBindingBody) (err error)
- func (ctx *Context) ShouldBindBodyWithJSON(obj interface{}) (err error)
- func (ctx *Context) ShouldBindWith(obj interface{}, b binding.IBinding) error
- func (ctx *Context) ShouldBindWithJSON(obj interface{}) error
- func (ctx *Context) String(code int, content string)
- type HandlerFunc
- type HandlerFuncRecover
- type LoggerConf
- type LoggerFormatterParam
- type M
- type Router
- func (router *Router) Delete(path string, handler HandlerFunc)
- func (router *Router) Domain(domain string, handler ...HandlerFunc) *Router
- func (router *Router) Get(path string, handler HandlerFunc)
- func (router *Router) Group(path string, handler ...HandlerFunc) *Router
- func (router *Router) Head(path string, handler HandlerFunc)
- func (router *Router) LoadTemplates(tplRoot string, funcs map[string]interface{})
- func (router *Router) NotFound(handler ...HandlerFunc)
- func (router *Router) Options(path string, handler HandlerFunc)
- func (router *Router) Patch(path string, handler HandlerFunc)
- func (router *Router) Post(path string, handler HandlerFunc)
- func (router *Router) Put(path string, handler HandlerFunc)
- func (router *Router) Run(addr string) error
- func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (router *Router) StaticFile(prefix, root string, listDir bool)
- func (router *Router) Stop(ctx context.Context) (e error)
- func (router *Router) Use(handler ...HandlerFunc)
Constants ¶
const ( // ModeDebug debug mode ModeDebug = iota // ModeTest test mode ModeTest // ModeProduct product mode ModeProduct )
const BodyBytesKey = "cotton/bbk"
BodyBytesKey indicates a default body bytes key.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct { Request *http.Request Response responseWriter // contains filtered or unexported fields }
Context context for request
func (Context) GetAllPostForm ¶ added in v0.4.1
GetAllPostForm get all post form value
func (Context) GetAllQuery ¶ added in v0.4.6
GetAllQuery get all query value
func (*Context) GetDefaultQuery ¶
GetDefaultQuery get default query
func (*Context) GetPostForm ¶ added in v0.3.0
GetPostForm get postform param
func (*Context) GetPostFormArray ¶ added in v0.3.0
GetPostFormArray get postform param array
func (*Context) GetPostFormFile ¶ added in v0.3.0
func (ctx *Context) GetPostFormFile(key string) *multipart.FileHeader
GetPostFormFile get postform file
func (*Context) GetPostFormFileArray ¶ added in v0.3.0
func (ctx *Context) GetPostFormFileArray(key string) (list []*multipart.FileHeader)
GetPostFormFileArray get postform files
func (*Context) GetPostFormMap ¶ added in v0.3.0
GetPostFormMap get postform param map
func (*Context) GetQueryArray ¶ added in v0.3.0
GetQueryArray get query array url?list[]=1&list[]=2
GetQueryArray("list[]") => ["1", "2"]
func (*Context) GetQueryMap ¶ added in v0.3.0
GetQueryMap get query map
func (*Context) GetRequestHeader ¶ added in v0.3.0
GetRequestHeader get request header, short for ctx.Request.Header.Get
func (*Context) Param ¶
Param returns the value of the URL param.
router.GET("/user/:id", func(c *gin.Context) { // a GET request to /user/john id := c.Param("id") // id == "john" })
func (*Context) SavePostFormFile ¶ added in v0.3.0
func (ctx *Context) SavePostFormFile(file *multipart.FileHeader, dst string) error
SavePostFormFile save file
func (*Context) ShouldBindBodyWith ¶ added in v0.6.0
func (ctx *Context) ShouldBindBodyWith(obj interface{}, bb binding.IBindingBody) (err error)
ShouldBindBodyWith bind body
func (*Context) ShouldBindBodyWithJSON ¶ added in v0.6.0
ShouldBindBodyWithJSON bind body with json
func (*Context) ShouldBindWith ¶ added in v0.6.0
ShouldBindWith bind
func (*Context) ShouldBindWithJSON ¶ added in v0.6.0
ShouldBindWithJSON bind with json
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc handler func
func LoggerWidthConf ¶
func LoggerWidthConf(conf LoggerConf) HandlerFunc
LoggerWidthConf get logger with config
func RecoverWithWriter ¶
func RecoverWithWriter(writer io.Writer, handler ...HandlerFuncRecover) HandlerFunc
RecoverWithWriter recover with wirter
type HandlerFuncRecover ¶
type HandlerFuncRecover func(ctx *Context, err interface{})
HandlerFuncRecover handler func for recover
type LoggerConf ¶
type LoggerConf struct { Formatter func(param LoggerFormatterParam, ctx *Context) string Writer io.Writer }
LoggerConf config for logger
type LoggerFormatterParam ¶
type LoggerFormatterParam struct { Host string Method string StatusCode int TimeStamp time.Time Latency time.Duration ClientIP string Path string }
LoggerFormatterParam param to formatter
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router router struct
func (*Router) Delete ¶
func (router *Router) Delete(path string, handler HandlerFunc)
Delete router delete method
func (*Router) Domain ¶ added in v0.4.3
func (router *Router) Domain(domain string, handler ...HandlerFunc) *Router
Domain support domain
func (*Router) Get ¶
func (router *Router) Get(path string, handler HandlerFunc)
Get router get method
func (*Router) Group ¶
func (router *Router) Group(path string, handler ...HandlerFunc) *Router
Group get group router
func (*Router) Head ¶
func (router *Router) Head(path string, handler HandlerFunc)
Head router head method
func (*Router) LoadTemplates ¶ added in v0.3.0
LoadTemplates load template files
funcs is functions register to template example:
router.LoadTemplates(root, map[string]interface{}{ "md5": func(str string) string { return str + "_md5" }, })
func (*Router) NotFound ¶ added in v0.3.0
func (router *Router) NotFound(handler ...HandlerFunc)
NotFound custom NotFoundHandler
func (*Router) Options ¶
func (router *Router) Options(path string, handler HandlerFunc)
Options router options method
func (*Router) Patch ¶
func (router *Router) Patch(path string, handler HandlerFunc)
Patch router patch method
func (*Router) Post ¶
func (router *Router) Post(path string, handler HandlerFunc)
Post router post method
func (*Router) Put ¶
func (router *Router) Put(path string, handler HandlerFunc)
Put router put method
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serve http handler
func (*Router) StaticFile ¶ added in v0.3.0
StaticFile static file handler
panic when prefix has ':' or '*'; and when open root error
you can use `ctx.Param("filepath")` to get relativepath