Documentation ¶
Index ¶
- Constants
- func Default() *gin.Engine
- func DisableBindValidation()
- func EnableJsonDecoderDisallowUnknownFields()
- func EnableJsonDecoderUseNumber()
- func InitRouting(engine *gin.Engine) *gin.Engine
- func New() *gin.Engine
- func NewRouter(e *gin.Engine) *_Router
- func Register(method, path string, handlers ...HandlerFunc) error
- func SetMode(value string)
- func WrapHandler(hd HandlerFunc) gin.HandlerFunc
- type BasicHandler
- type Context
- func (c *Context) AllowCORS()
- func (c *Context) BaseFile() string
- func (c *Context) BaseURL() string
- func (c *Context) BuildUrl(path string, params H) *urlBuilder
- func (c *Context) ContentType() string
- func (c *Context) Domain() string
- func (c *Context) Error(msg string, url ...string)
- func (c *Context) Ext() string
- func (c *Context) Fail(msg string, url ...string)
- func (c *Context) FailWithData(msg string, data interface{}, url ...string)
- func (c *Context) Forbidden(msg string, url ...string)
- func (c *Context) GetIP() string
- func (c *Context) GetToken(name ...string) string
- func (c *Context) GetUserAgent() string
- func (c *Context) Host() string
- func (c *Context) IsAjax() bool
- func (c *Context) IsConnect() bool
- func (c *Context) IsDelete() bool
- func (c *Context) IsGet() bool
- func (c *Context) IsHead() bool
- func (c *Context) IsJson() bool
- func (c *Context) IsOptions() bool
- func (c *Context) IsPatch() bool
- func (c *Context) IsPjax() bool
- func (c *Context) IsPost() bool
- func (c *Context) IsPut() bool
- func (c *Context) IsSsl() bool
- func (c *Context) IsTrace() bool
- func (c *Context) Method() string
- func (c *Context) NotFound(msg string, url ...string)
- func (c *Context) PageResponse(list interface{}, total int64, page, pageSize int)
- func (c *Context) PanDomain() string
- func (c *Context) Param(param string, defaultValue ...string) string
- func (c *Context) Port() string
- func (c *Context) Protocol() string
- func (c *Context) Redirect(location string)
- func (c *Context) RedirectPermanent(location string)
- func (c *Context) RemotePort() string
- func (c *Context) RequireParams(params ...string) bool
- func (c *Context) Response(httpStatus, code int, msg string, data interface{}, url ...string)
- func (c *Context) Root() string
- func (c *Context) RootDomain() string
- func (c *Context) RootUrl() string
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, config UploadConfig) (string, error)
- func (c *Context) Scheme() string
- func (c *Context) SubDomain() string
- func (c *Context) Success(data interface{}, url ...string)
- func (c *Context) SuccessWithMsg(msg string, data interface{}, url ...string)
- func (c *Context) Time() time.Time
- func (c *Context) Type() string
- func (c *Context) URL() string
- func (c *Context) ValidateFile(file *multipart.FileHeader, config UploadConfig) error
- type Controller
- func (c *Controller) CONNECT(relativePath, action string) *Controller
- func (c *Controller) DELETE(relativePath, action string) *Controller
- func (c *Controller) GET(relativePath, action string) *Controller
- func (c *Controller) Group(relativePath, action string) *Controller
- func (c *Controller) HEAD(relativePath, action string) *Controller
- func (c *Controller) OPTIONS(relativePath, action string) *Controller
- func (c *Controller) PATCH(relativePath, action string) *Controller
- func (c *Controller) POST(relativePath, action string) *Controller
- func (c *Controller) PUT(relativePath, action string) *Controller
- func (c *Controller) Resource(relativePath string) *Controller
- func (c *Controller) TRACE(relativePath, action string) *Controller
- func (c *Controller) Use(action string) *Controller
- type H
- type Handler
- type HandlerFunc
- type UploadConfig
Constants ¶
const ( SuccessCode = 200 // 成功状态码 FailCode = 400 // 失败状态码 ErrorCode = 500 // 错误状态码 ForbiddenCode = 403 // 禁止访问状态码 NotFound = 404 // 资源不存在状态码 )
const ( MethodAny = "ANY" MethodGet = "GET" MethodHead = "HEAD" MethodPost = "POST" MethodPut = "PUT" MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" MethodConnect = "CONNECT" MethodOptions = "OPTIONS" MethodTrace = "TRACE" )
const ( EnvGinMode = "GIN_MODE" DebugMode = "debug" ReleaseMode = "release" TestMode = "test" )
Variables ¶
This section is empty.
Functions ¶
func EnableJsonDecoderDisallowUnknownFields ¶
func EnableJsonDecoderDisallowUnknownFields()
EnableJsonDecoderDisallowUnknownFields 设置 binding.EnableDecoderDisallowUnknownFields 为 true,以调用 JSON 解码器实例的 DisallowUnknownFields 方法。
func EnableJsonDecoderUseNumber ¶
func EnableJsonDecoderUseNumber()
EnableJsonDecoderUseNumber 设置 binding.EnableDecoderUseNumber 为 true,以调用 JSON 解码器实例的 UseNumber 方法。
func InitRouting ¶
InitRouting 初始化路由前请先调用 Register 注册路由
func WrapHandler ¶
func WrapHandler(hd HandlerFunc) gin.HandlerFunc
WrapHandler 方法用于将自定义的处理函数转换为 gin.HandlerFunc 类型
Types ¶
type BasicHandler ¶
type BasicHandler struct {
Handlers map[string]HandlerFunc
}
BasicHandler 结构体用于存储处理函数
func (*BasicHandler) GetHandler ¶
func (b *BasicHandler) GetHandler(action string) HandlerFunc
GetHandler 方法根据动作获取处理函数
func (*BasicHandler) SetHandler ¶
func (b *BasicHandler) SetHandler(action string, handlerFunc HandlerFunc)
SetHandler 方法用于设置处理函数
type Context ¶
func (*Context) ContentType ¶
ContentType 获取当前请求的CONTENT_TYPE
func (*Context) FailWithData ¶
FailWithData 失败响应(带数据)
func (*Context) PageResponse ¶
PageResponse 分页响应
func (*Context) RedirectPermanent ¶
RedirectPermanent 永久重定向
func (*Context) RequireParams ¶
RequireParams 检查必需参数
func (*Context) SaveUploadedFile ¶
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, config UploadConfig) (string, error)
SaveUploadedFile 保存上传文件
func (*Context) SuccessWithMsg ¶
SuccessWithMsg 成功响应(自定义消息)
func (*Context) ValidateFile ¶
func (c *Context) ValidateFile(file *multipart.FileHeader, config UploadConfig) error
ValidateFile 验证上传文件
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller 结构体,包含 router 和 Handler
func (*Controller) CONNECT ¶
func (c *Controller) CONNECT(relativePath, action string) *Controller
CONNECT 方法用于在 Controller 中注册 CONNECT 请求的路由
func (*Controller) DELETE ¶
func (c *Controller) DELETE(relativePath, action string) *Controller
DELETE 方法用于在 Controller 中注册 DELETE 请求的路由
func (*Controller) GET ¶
func (c *Controller) GET(relativePath, action string) *Controller
GET 方法用于在 Controller 中注册 GET 请求的路由
func (*Controller) Group ¶
func (c *Controller) Group(relativePath, action string) *Controller
Group 方法用于在 Controller 中创建路由组
func (*Controller) HEAD ¶
func (c *Controller) HEAD(relativePath, action string) *Controller
HEAD 方法用于在 Controller 中注册 HEAD 请求的路由
func (*Controller) OPTIONS ¶
func (c *Controller) OPTIONS(relativePath, action string) *Controller
OPTIONS 方法用于在 Controller 中注册 OPTIONS 请求的路由
func (*Controller) PATCH ¶
func (c *Controller) PATCH(relativePath, action string) *Controller
PATCH 方法用于在 Controller 中注册 PATCH 请求的路由
func (*Controller) POST ¶
func (c *Controller) POST(relativePath, action string) *Controller
POST 方法用于在 Controller 中注册 POST 请求的路由
func (*Controller) PUT ¶
func (c *Controller) PUT(relativePath, action string) *Controller
PUT 方法用于在 Controller 中注册 PUT 请求的路由
func (*Controller) Resource ¶
func (c *Controller) Resource(relativePath string) *Controller
Resource 方法用于在 Controller 中注册 RESTful 风格的路由
func (*Controller) TRACE ¶
func (c *Controller) TRACE(relativePath, action string) *Controller
TRACE 方法用于在 Controller 中注册 TRACE 请求的路由
func (*Controller) Use ¶
func (c *Controller) Use(action string) *Controller
Use 方法用于在 Controller 中注册中间件
type Handler ¶
type Handler interface { GetHandler(action string) HandlerFunc Clone() Handler }
Handler 接口定义了处理程序的基本方法
type UploadConfig ¶
type UploadConfig struct { AllowedExts []string // 允许的文件扩展名 MaxSize int64 // 最大文件大小(字节) SavePath string // 保存路径 }
UploadConfig 文件上传相关方法