Documentation ¶
Index ¶
- Constants
- func ErrorCodeHandler() gin.HandlerFunc
- func Recover() gin.HandlerFunc
- type BizErrorCode
- type BizErrorMessage
- type GinModule
- type GinWrapper
- func (g *GinWrapper) DELETE(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) GET(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) HEAD(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) MATCH(method []string, path string, handler ...HandlerWrapper)
- func (g *GinWrapper) OPTIONS(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) PATCH(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) POST(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) PUT(path string, handler ...HandlerWrapper)
- func (g *GinWrapper) TRACE(path string, handler ...HandlerWrapper)
- type HandlerWrapper
- type Request
- func (r *Request) BindBodyForm(object any)
- func (r *Request) BindBodyJson(object any)
- func (r *Request) BindUriPathParams(object any)
- func (r *Request) BindUriQueryParams(object any)
- func (r *Request) FormFile(name string) *multipart.FileHeader
- func (r *Request) FullPath() string
- func (r *Request) HeaderValue(key string) string
- func (r *Request) HttpMethod() string
- func (r *Request) RawData() []byte
- func (r *Request) RawDataString() string
- func (r *Request) RawGinContext() *gin.Context
- func (r *Request) RequestIP() string
- func (r *Request) SaveUploadedFile(name string, dirPath string, filename ...string)
- func (r *Request) ShouldBindBodyForm(object any)
- func (r *Request) ShouldBindBodyJson(object any)
- func (r *Request) ShouldBindUriQueryParams(object any)
- func (r *Request) UriPathParam(name string) string
- func (r *Request) UriPathParams(names ...string) map[string]string
- func (r *Request) UriQueryParam(name string) (string, bool)
- func (r *Request) UriQueryParamArray(name string) ([]string, bool)
- func (r *Request) UriQueryParamMap(name string) (map[string]string, bool)
- func (r *Request) UriQueryParams(names ...string) map[string]string
- type Response
- type Router
- type RouterInfo
- type Status
- type StatusCode
- type StatusMessage
Constants ¶
const ( StatusCodeSuccess = 200 StatusCodeExceededLimit StatusCodeTimeout StatusCodeException StatusCodeNotFound StatusCodeForbidden StatusCodeMethodNotAllowed = 9007 - iota StatusCodeMediaTypeNotAllowed StatusCodeUploadLimitExceeded StatusCodeBadRequestParameters )
Variables ¶
This section is empty.
Functions ¶
func ErrorCodeHandler ¶
func ErrorCodeHandler() gin.HandlerFunc
func Recover ¶
func Recover() gin.HandlerFunc
Types ¶
type BizErrorCode ¶
type BizErrorCode int
type BizErrorMessage ¶
type BizErrorMessage string
type GinModule ¶
type GinModule struct { // 自定义Module配置 GinModuleConfig *declaration.ModuleConfig GinInterceptor func(instance *gin.Engine) // * 注册业务路由 Routers []Router // * 注册服务监听地址 :8080 (默认) ListenAddress string // ip:port UseErrorCodeHandler bool // 使用错误包装处理器 在出现非200响应码或者异常时,将自动进行转化 // gin config DebugModule bool MaxMultipartMemory int64 DisableMethodNotAllowedError bool ForwardedByClientIP bool }
func (*GinModule) ModuleConfig ¶
func (g *GinModule) ModuleConfig() *declaration.ModuleConfig
type GinWrapper ¶
type GinWrapper struct {
// contains filtered or unexported fields
}
func (*GinWrapper) DELETE ¶
func (g *GinWrapper) DELETE(path string, handler ...HandlerWrapper)
func (*GinWrapper) GET ¶
func (g *GinWrapper) GET(path string, handler ...HandlerWrapper)
func (*GinWrapper) HEAD ¶
func (g *GinWrapper) HEAD(path string, handler ...HandlerWrapper)
func (*GinWrapper) MATCH ¶
func (g *GinWrapper) MATCH(method []string, path string, handler ...HandlerWrapper)
func (*GinWrapper) OPTIONS ¶
func (g *GinWrapper) OPTIONS(path string, handler ...HandlerWrapper)
func (*GinWrapper) PATCH ¶
func (g *GinWrapper) PATCH(path string, handler ...HandlerWrapper)
func (*GinWrapper) POST ¶
func (g *GinWrapper) POST(path string, handler ...HandlerWrapper)
func (*GinWrapper) PUT ¶
func (g *GinWrapper) PUT(path string, handler ...HandlerWrapper)
func (*GinWrapper) TRACE ¶
func (g *GinWrapper) TRACE(path string, handler ...HandlerWrapper)
type HandlerWrapper ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) BindBodyForm ¶
BindBodyForm 将请求body表单数据绑定到from结构体中 任何异常将触发panic响应请求参数错误 `form:""`
func (*Request) BindBodyJson ¶
BindBodyJson 将请求body数据绑定到json结构体中 任何异常将触发panic响应请求参数错误 `json:""`
func (*Request) BindUriPathParams ¶
BindUriPathParams 绑定结构体用于接收UriPath参数 任何异常将触发panic响应请求参数错误 `uri:""`
func (*Request) BindUriQueryParams ¶
BindUriQueryParams 绑定结构体用于接收UriQuery参数 任何异常将触发panic响应请求参数错误 `form:""`
func (*Request) FormFile ¶
func (r *Request) FormFile(name string) *multipart.FileHeader
FormFile 获取上传文件内容 任何异常将触发panic响应请求参数错误 request name: form name
func (*Request) HeaderValue ¶
HeaderValue 获取Head name对应的参数值
func (*Request) RawDataString ¶
RawDataString 将原始请求的body以字符串数据返回 任何异常将触发panic响应请求参数错误
func (*Request) RawGinContext ¶
RawGinContext 获取原始Gin上下文
func (*Request) SaveUploadedFile ¶
SaveUploadedFile 保存上传的文件内容 任何异常将触发panic响应请求参数错误 request name: form name
dirPath: 保存的路径 (文件夹) filename: 保存的文件名 若不指定则为源文件名
func (*Request) ShouldBindBodyForm ¶
ShouldBindBodyForm 将请求body表单数据绑定到from结构体中
func (*Request) ShouldBindBodyJson ¶
ShouldBindBodyJson 将请求body数据绑定到json结构体中
func (*Request) ShouldBindUriQueryParams ¶
ShouldBindUriQueryParams 绑定结构体用于接收UriQuery参数
func (*Request) UriPathParam ¶
UriPathParam 获取path路径参数 /:id/
func (*Request) UriQueryParam ¶
UriQueryParam 获取 uri Query参数值 /?a=b&c=d return string: 参数值(可能是类型零值) bool: 请求方是否传递
func (*Request) UriQueryParamArray ¶
UriQueryParamArray 获取 uri Query参数值 /?a=b&c=d
func (*Request) UriQueryParamMap ¶
type Response ¶
func ResponseBizError ¶
func ResponseBizError(bizErrorCode *BizErrorCode, bizErrorMessage *BizErrorMessage) *Response
func ResponseError ¶
func ResponseError(statusCode StatusCode, statusMessage ...StatusMessage) *Response
ResponseError 其他StatusCode错误
func ResponseSuccess ¶
type Router ¶
type Router interface { RouterInfo() *RouterInfo RegisterHandler(ginWrapper *GinWrapper) }
type RouterInfo ¶
type Status ¶
type Status struct { StatusCode StatusCode `json:"statusCode"` StatusMessage StatusMessage `json:"statusMessage"` BizErrorCode *BizErrorCode `json:"bizErrorCode"` BizErrorMessage *BizErrorMessage `json:"bizErrorMessage"` Timestamp int64 `json:"timestamp"` }
type StatusCode ¶
type StatusCode int
type StatusMessage ¶
type StatusMessage string
func GetStatusMessage ¶
func GetStatusMessage(statusCode StatusCode) StatusMessage