Documentation ¶
Index ¶
- type CallbackHandler
- type Config
- type Context
- func (ctx *Context) Abort() *Context
- func (ctx *Context) AllFormValue() url.Values
- func (ctx *Context) AllPathValue() []Param
- func (ctx *Context) AllQueryValue() url.Values
- func (ctx *Context) EngineConfig() Config
- func (ctx *Context) FileFromFS(filepath string, fs http.FileSystem)
- func (ctx *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (ctx *Context) FormFiles(name string) ([]*multipart.FileHeader, error)
- func (ctx *Context) FormParam(key string) (string, bool)
- func (ctx *Context) FormParams(key string) ([]string, bool)
- func (ctx *Context) FormValue(key string) string
- func (ctx *Context) FormValues(key string) []string
- func (ctx *Context) FullPath() string
- func (ctx *Context) GetValue(key any) any
- func (ctx *Context) InitFormCache() error
- func (ctx *Context) IsAborted() bool
- func (ctx *Context) JSON(status int, data any, charset ...string) error
- func (ctx *Context) NoContent() error
- func (ctx *Context) ParseJSON(obj any) error
- func (ctx *Context) PathParam(key string) (string, bool)
- func (ctx *Context) PathValue(key string) string
- func (ctx *Context) QueryParam(key string) (string, bool)
- func (ctx *Context) QueryParams(key string) ([]string, bool)
- func (ctx *Context) QueryValue(key string) string
- func (ctx *Context) QueryValues(key string) []string
- func (ctx *Context) Redirect(code int, url string) error
- func (ctx *Context) SaveFile(fileHeader *multipart.FileHeader, savePath string, perm os.FileMode) error
- func (ctx *Context) ServeFile(filePath string)
- func (ctx *Context) SetValue(key, value any)
- func (ctx *Context) StatusCode(code int) (err error)
- func (ctx *Context) String(status int, data string, charset ...string) (err error)
- type Engine
- type Handler
- type HandlersChain
- type Node
- type Param
- type Params
- type Router
- type RouterGroup
- func (group *RouterGroup) DELETE(relativePath string, handlers ...Handler)
- func (group *RouterGroup) GET(relativePath string, handlers ...Handler)
- func (group *RouterGroup) Group(relativePath string, handlers ...Handler) *RouterGroup
- func (group *RouterGroup) HEAD(relativePath string, handlers ...Handler)
- func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...Handler)
- func (group *RouterGroup) Match(methods []string, relativePath string, handlers ...Handler)
- func (group *RouterGroup) OPTIONS(relativePath string, handlers ...Handler)
- func (group *RouterGroup) PATCH(relativePath string, handlers ...Handler)
- func (group *RouterGroup) POST(relativePath string, handlers ...Handler)
- func (group *RouterGroup) PUT(relativePath string, handlers ...Handler)
- func (group *RouterGroup) Static(relativePath, localPath string, listDir bool)
- func (group *RouterGroup) StaticFile(relativePath, filePath string)
- func (group *RouterGroup) StaticFileFS(relativePath, filePath string, fs http.FileSystem)
- func (group *RouterGroup) Use(handlers ...Handler)
- type Routes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { MaxMultipartMemory int64 // 允许的请求Body大小(默认32 << 20 = 32MB) Recovery bool // 自动恢复panic,防止进程退出 HandleMethodNotAllowed bool // 不处理 405 错误(可以减少路由匹配时间),以 404 错误返回 ErrorHandler CallbackHandler // 错误回调处理器 AfterHandler CallbackHandler // 后置回调处理器,总是会在其它处理器全部执行完之后执行 }
Config 引擎参数配置
type Context ¶
type Context struct { Request *http.Request ResponseWriter http.ResponseWriter Status int // 处理器执行结果的状态码(HTTP) Error error // 处理器执行错误时的消息 // contains filtered or unexported fields }
Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.
func (*Context) AllFormValue ¶
AllFormValue 获取所有Form参数
func (*Context) AllQueryValue ¶
AllQueryValue 获取所有GET参数
func (*Context) FileFromFS ¶
func (ctx *Context) FileFromFS(filepath string, fs http.FileSystem)
FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
func (*Context) FormFile ¶
func (ctx *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile 根据参数名获取上传的第一个文件
func (*Context) FormFiles ¶
func (ctx *Context) FormFiles(name string) ([]*multipart.FileHeader, error)
FormFiles 根据参数名获取上传的所有文件
func (*Context) FormParams ¶
FormParams 获取某个Form参数的所有值,并判断参数是否存在
func (*Context) FormValues ¶
FormValues 获取某个Form参数的所有值
func (*Context) QueryParam ¶
QueryParam 获取某个GET参数的第一个值,并判断参数是否存在
func (*Context) QueryParams ¶
QueryParams 获取某个GET参数的所有值,并判断参数是否存在
func (*Context) QueryValue ¶
QueryValue 获取某个GET参数的第一个值
func (*Context) QueryValues ¶
QueryValues 获取某个GET参数的所有值
func (*Context) SaveFile ¶
func (ctx *Context) SaveFile(fileHeader *multipart.FileHeader, savePath string, perm os.FileMode) error
SaveFile 保存上传的文件到本地路径
func (*Context) StatusCode ¶ added in v2.0.1
StatusCode 输出状态码
type Engine ¶
type Engine struct { RouterGroup // contains filtered or unexported fields }
Engine 引擎
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Router ¶
type Router interface { Routes Group(string, ...Handler) *RouterGroup }
Router 路由器接口,包括单路由和路由组
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup 路由组
func (*RouterGroup) DELETE ¶
func (group *RouterGroup) DELETE(relativePath string, handlers ...Handler)
DELETE 注册DELETE方法的路由
func (*RouterGroup) GET ¶
func (group *RouterGroup) GET(relativePath string, handlers ...Handler)
GET 注册GET方法的路由
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(relativePath string, handlers ...Handler) *RouterGroup
Group 注册路由组
func (*RouterGroup) HEAD ¶
func (group *RouterGroup) HEAD(relativePath string, handlers ...Handler)
HEAD 注册HEAD方法的路由
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...Handler)
Handle 注册自定义方法的路由
func (*RouterGroup) Match ¶
func (group *RouterGroup) Match(methods []string, relativePath string, handlers ...Handler)
Match 为一个路径同时注册多个方法的路由
func (*RouterGroup) OPTIONS ¶
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...Handler)
OPTIONS 注册OPTIONS方法的路由
func (*RouterGroup) PATCH ¶
func (group *RouterGroup) PATCH(relativePath string, handlers ...Handler)
PATCH 注册PATCH方法的路由
func (*RouterGroup) POST ¶
func (group *RouterGroup) POST(relativePath string, handlers ...Handler)
POST 注册POST方法的路由
func (*RouterGroup) PUT ¶
func (group *RouterGroup) PUT(relativePath string, handlers ...Handler)
PUT 注册PUT方法的路由
func (*RouterGroup) Static ¶ added in v2.2.0
func (group *RouterGroup) Static(relativePath, localPath string, listDir bool)
Static 注册一个指向服务端本地目录的静态路由,例如: Static("/public", "./public")
func (*RouterGroup) StaticFile ¶
func (group *RouterGroup) StaticFile(relativePath, filePath string)
StaticFile 注册一个指向服务端本地文件的静态路由,例如: StaticFile("favicon.ico", "./resources/favicon.ico")
func (*RouterGroup) StaticFileFS ¶
func (group *RouterGroup) StaticFileFS(relativePath, filePath string, fs http.FileSystem)
StaticFileFS 与StaticFile函数类型,但可以自定义文件系统,例如: StaticFileFS("favicon.ico", "./resources/favicon.ico", Dir{".", false})
func (*RouterGroup) Use ¶ added in v2.1.0
func (group *RouterGroup) Use(handlers ...Handler)
Use 使用中间件
type Routes ¶
type Routes interface { Use(...Handler) After(...Handler) Handle(string, string, ...Handler) GET(string, ...Handler) POST(string, ...Handler) DELETE(string, ...Handler) PATCH(string, ...Handler) PUT(string, ...Handler) OPTIONS(string, ...Handler) HEAD(string, ...Handler) Match([]string, string, ...Handler) }
Routes 定义所有路由器接口