Documentation ¶
Index ¶
- Constants
- func NewCommonResp() *commonResp
- func NewRespRest() *restResp
- func RawGinEngine() *gin.Engine
- type BadHttpCodeResolver
- type BasicAuthAccount
- type BizErrorCode
- type BizErrorMessage
- type GinConfig
- type GinStarter
- type HandlerWrapper
- type Middleware
- type PanicResolver
- type Request
- func (r *Request) BindBodyForm(object any) error
- func (r *Request) BindBodyJson(object any) error
- func (r *Request) BindPathParams(object any) error
- func (r *Request) BindQueryParams(object any) error
- func (r *Request) GetCookie(name string) (string, error)
- func (r *Request) GetFormArray(name string) ([]string, bool)
- func (r *Request) GetFormFile(name string) (*multipart.FileHeader, error)
- func (r *Request) GetFormMap(name string) (map[string]string, bool)
- func (r *Request) GetFormValue(name string) (string, bool)
- func (r *Request) GetHeader(name string) string
- func (r *Request) GetPathParam(name string) string
- func (r *Request) GetPathParams(names ...string) map[string]string
- func (r *Request) GetQueryParam(name string) (string, bool)
- func (r *Request) GetQueryParamArray(name string) ([]string, bool)
- func (r *Request) GetQueryParamMap(name string) (map[string]string, bool)
- func (r *Request) GetQueryParams(names ...string) map[string]string
- func (r *Request) GetRawBodyData() ([]byte, error)
- func (r *Request) GetValue(key string) (interface{}, bool)
- func (r *Request) Host() string
- func (r *Request) HttpMethod() string
- func (r *Request) MustBindBodyForm(object any)
- func (r *Request) MustBindBodyJson(object any)
- func (r *Request) MustBindPathParams(object any)
- func (r *Request) MustBindQueryParams(object any)
- func (r *Request) MustGetCookie(name string) string
- func (r *Request) MustGetFormArray(name string) []string
- func (r *Request) MustGetFormFile(name string) *multipart.FileHeader
- func (r *Request) MustGetFormMap(name string) map[string]string
- func (r *Request) MustGetFormValue(name string) string
- func (r *Request) MustGetQueryParam(name string) string
- func (r *Request) MustGetQueryParamArray(name string) []string
- func (r *Request) MustGetQueryParamMap(name string) map[string]string
- func (r *Request) MustGetQueryParams(names ...string) map[string]string
- func (r *Request) MustGetRawBodyData() []byte
- func (r *Request) MustGetRawBodyString() string
- func (r *Request) MustSaveUploadedFile(name string, dirPath string, filename ...string)
- func (r *Request) Proto() string
- func (r *Request) RawGinContext() *gin.Context
- func (r *Request) RequestFullPath() string
- func (r *Request) RequestIP() string
- func (r *Request) RequestPath() string
- func (r *Request) RouterFullPath() string
- func (r *Request) SaveUploadedFile(name string, dirPath string, filename ...string) error
- func (r *Request) SetValue(key string, value interface{})
- type Response
- func RespAbortWithHttpStatusCode(statusCode int) Response
- func RespHttpStatusCode(statusCode int) Response
- func RespJson(data any, httpStatusCode ...int) Response
- func RespRedirect(url string, httpStatusCode ...int) Response
- func RespRestBadParameters(statusMessage ...string) Response
- func RespRestBizError(bizErrorCode BizErrorCode, bizErrorMessage BizErrorMessage) Response
- func RespRestException(statusMessage ...string) Response
- func RespRestRaw(dataRest *RestRespStruct) Response
- func RespRestStatusError(statusCode StatusCode, statusMessage ...StatusMessage) Response
- func RespRestSuccess(data ...any) Response
- func RespRestUnAuthorized(statusMessage ...string) Response
- func RespTextPlain(data string, httpStatusCode ...int) Response
- func RespToml(data any, httpStatusCode ...int) Response
- func RespXml(data any, httpStatusCode ...int) Response
- func RespYaml(data any, httpStatusCode ...int) Response
- type ResponseCookie
- type ResponseData
- func (r *ResponseData) AddCookie(cookie *ResponseCookie) *ResponseData
- func (r *ResponseData) AddCookies(cookies []*ResponseCookie) *ResponseData
- func (r *ResponseData) AddHeader(name, value string) *ResponseData
- func (r *ResponseData) AddHeaders(headers []*ResponseHeader) *ResponseData
- func (r *ResponseData) SetContentType(contentType string) *ResponseData
- func (r *ResponseData) SetData(data []byte) *ResponseData
- func (r *ResponseData) SetStatusCode(statusCode int) *ResponseData
- type ResponseDataStructDecoder
- type ResponseHeader
- type RestRespStatusStruct
- type RestRespStruct
- func NewRestBadParameters(statusMessage ...string) *RestRespStruct
- func NewRestBizError(bizErrorCode BizErrorCode, bizErrorMessage BizErrorMessage) *RestRespStruct
- func NewRestException(statusMessage ...string) *RestRespStruct
- func NewRestStatusError(statusCode StatusCode, statusMessage ...StatusMessage) *RestRespStruct
- func NewRestSuccess(data ...interface{}) *RestRespStruct
- func NewRestUnauthorized(statusMessage ...string) *RestRespStruct
- type Router
- type RouterInfo
- type RouterWrapper
- func (r *RouterWrapper) DELETE(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) DELETE1(path string, contentType []string, handler ...HandlerWrapper)
- func (r *RouterWrapper) GET(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) HEAD(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) MATCH(method []string, path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) MATCH1(method []string, path string, contentType []string, handler ...HandlerWrapper)
- func (r *RouterWrapper) OPTIONS(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) PATCH(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) PATCH1(path string, contentType []string, handler ...HandlerWrapper)
- func (r *RouterWrapper) POST(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) POST1(path string, contentType []string, handler ...HandlerWrapper)
- func (r *RouterWrapper) PUT(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) PUT1(path string, contentType []string, handler ...HandlerWrapper)
- func (r *RouterWrapper) TRACE(path string, handler ...HandlerWrapper)
- func (r *RouterWrapper) TRACE1(path string, contentType []string, handler ...HandlerWrapper)
- type StatusCode
- type StatusMessage
Constants ¶
const ( StatusCodeSuccess = http.StatusOK StatusCodeExceededLimit = http.StatusTooManyRequests StatusCodeTimeout = http.StatusGatewayTimeout StatusCodeException = http.StatusInternalServerError StatusCodeNotFound = http.StatusNotFound StatusCodeForbidden = http.StatusForbidden StatusCodeMethodNotAllowed = http.StatusMethodNotAllowed StatusCodeMediaTypeNotAllowed = http.StatusUnsupportedMediaType StatusCodeUploadLimitExceeded = http.StatusRequestEntityTooLarge StatusCodeBadRequestParameters = http.StatusBadRequest )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BadHttpCodeResolver ¶ added in v0.1.4
type BasicAuthAccount ¶
type BizErrorCode ¶
type BizErrorCode int
type BizErrorMessage ¶
type BizErrorMessage string
type GinConfig ¶ added in v0.1.14
type GinConfig struct { // 模块组件在启动时执行初始化 InitFunc func(instance *gin.Engine) // * 注册业务路由 Routers []Router // * 注册服务监听地址 :8080 (默认) ListenAddress string // ip:port // 默认情况系统会将捕获的异常详细发给PanicResolver处理,如果不想将细节暴露向外 // 方案 1. 启用隐藏异常细节功能,系统将在触发panic重要错误时不再调用PanicResolver处理,并统一响应500错误 // 方案 2. 如果不想禁用异常时调用PanicResolver, 可以在初始化时手动设置自定义PanicResolver处理器 // * panic 将被分为框架内部错误和框架未知错误 框架内部错误是非敏感错误,不受该参数控制,每次都会触发PanicResolver,例如验证框架错误 HidePanicErrorDetails bool // 全局异常响应处理器 如果不指定则使用默认方式 PanicResolver PanicResolver // 禁用异常http响应码Resolver DisableBadHttpCodeResolver bool // 禁用系统内置的忽略异常响应码 DisableDefaultIgnoreHttpCode bool // 启用异常http响应码Resolver 指定不处理特定的异常响应码 IgnoreHttpCode []int // 启用异常http响应码Resolver 如果不指定则使用默认方式 BadHttpCodeResolver BadHttpCodeResolver // 自定义全局中间件 作用于所有请求 按照顺序执行 GlobalMiddlewares []Middleware // 响应数据的结构体解码器 默认为JSON方式解码 // 在使用NewRespRest响应结构体数据时解码为[]byte数据的解码器 // 如果自实现Response接口将不使用解码器 ResponseDataStructDecoder ResponseDataStructDecoder // 尝试启用TraceId响应 // https://github.com/acexy/golang-toolkit/blob/main/sys/threadlocal.go // 如果工作环境开启EnableLocalTraceId ,将自动响应TranceId头 EnableGoroutineTraceIdResponse bool // ========== gin config DebugModule bool MaxMultipartMemory int64 // 关闭包裹405错误展示,使用404代替 DisableMethodNotAllowedError bool // 禁用尝试获取转发真实IP DisableForwardedByClientIP bool }
type GinStarter ¶
type GinStarter struct { // GinConfig 配置 Config GinConfig // 懒加载函数,用于在实际执行时动态获取配置 该权重高于Config的直接配置 LazyConfig func() GinConfig // 自定义Gin模块的组件属性 GinSetting *parent.Setting }
func (*GinStarter) Setting ¶
func (g *GinStarter) Setting() *parent.Setting
func (*GinStarter) Start ¶
func (g *GinStarter) Start() (interface{}, error)
type HandlerWrapper ¶
HandlerWrapper 定义内部Handler
type Middleware ¶ added in v0.1.3
func BasicAuthMiddleware ¶ added in v0.1.3
func BasicAuthMiddleware(account *BasicAuthAccount, match ...func(request *Request) bool) Middleware
BasicAuthMiddleware 基础权限校验中间件 match 满足指定条件才执行
func MediaTypeMiddleware ¶ added in v0.1.4
func MediaTypeMiddleware(contentType []string, match ...func(request *Request) bool) Middleware
MediaTypeMiddleware 类型校验中间件
type PanicResolver ¶ added in v0.1.4
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) BindBodyForm ¶
BindBodyForm 将请求body表单数据绑定到from结构体中
func (*Request) BindBodyJson ¶
BindBodyJson 将请求body数据绑定到json结构体中
func (*Request) BindPathParams ¶
BindPathParams /:id 绑定结构体用于接收UriPath参数 结构体标签格式 `uri:""`
func (*Request) BindQueryParams ¶
BindQueryParams 绑定结构体用于接收Query参数
func (*Request) GetFormArray ¶ added in v0.1.11
GetFormArray 获取Form表单的值
func (*Request) GetFormFile ¶
func (r *Request) GetFormFile(name string) (*multipart.FileHeader, error)
GetFormFile 获取上传文件内容
func (*Request) GetFormMap ¶ added in v0.1.11
GetFormMap 获取Form表单的值
func (*Request) GetFormValue ¶ added in v0.1.11
GetFormValue 获取Form表单的值
func (*Request) GetPathParam ¶
GetPathParam 获取path路径参数 /:id
func (*Request) GetPathParams ¶
GetPathParams 获取path路径参数 /:id 多个参数
func (*Request) GetQueryParam ¶
GetQueryParam 获取 uri Query参数值 /?a=b&c=d return string: 参数值(可能是类型零值) bool: 请求方是否传递
func (*Request) GetQueryParamArray ¶
GetQueryParamArray 获取 uri Query参数值 /?a=b&a=d 返回切片数据
func (*Request) GetQueryParamMap ¶
GetQueryParamMap 获取 uri Query参数值 /?name[a]=1&name[b]=2 返回map类型数据
func (*Request) GetQueryParams ¶
GetQueryParams 获取 uri Query参数值 /?a=b&c=d 返回map类型数据 如果目标没有传递将, map中将不包含指定的参数名
func (*Request) GetRawBodyData ¶
GetRawBodyData 将请求body以字节数据返回
func (*Request) MustBindBodyForm ¶
MustBindBodyForm 将请求body表单数据绑定到from结构体中 任何错误将触发Panic流程中断
func (*Request) MustBindBodyJson ¶
MustBindBodyJson 将请求body数据绑定到json结构体中 任何错误将触发Panic流程中断
func (*Request) MustBindPathParams ¶
MustBindPathParams /:id 绑定结构体用于接收UriPath参数 结构体标签格式 `uri:""` 任何错误将触发Panic流程中断
func (*Request) MustBindQueryParams ¶
MustBindQueryParams 绑定结构体用于接收Query参数以及POST表单符合条件的数据 任何错误将触发Panic流程中断
func (*Request) MustGetCookie ¶
MustGetCookie 获取Cookie name对应的参数值 任何错误将触发Panic流程中断
func (*Request) MustGetFormArray ¶ added in v0.1.11
MustGetFormArray 获取Form表单的值 任何错误将触发Panic流程中断
func (*Request) MustGetFormFile ¶
func (r *Request) MustGetFormFile(name string) *multipart.FileHeader
MustGetFormFile 获取上传文件内容 任何错误将触发Panic流程中断
func (*Request) MustGetFormMap ¶ added in v0.1.11
MustGetFormMap 获取Form表单的值 任何错误将触发Panic流程中断
func (*Request) MustGetFormValue ¶ added in v0.1.11
MustGetFormValue 获取Form表单的值 任何错误将触发Panic流程中断
func (*Request) MustGetQueryParam ¶
MustGetQueryParam 获取 uri Query参数值 /?a=b&c=d 如果没有发送指定参数将触发异常中断流程
func (*Request) MustGetQueryParamArray ¶
MustGetQueryParamArray 获取 uri Query参数值 /?a=b&a=d 返回切片数据 如果参数未设置将触发异常中断流程
func (*Request) MustGetQueryParamMap ¶
MustGetQueryParamMap 获取 uri Query参数值 /?name[a]=1&name[b]=2 返回map类型数据 如果参数未设置将触发异常中断流程
func (*Request) MustGetQueryParams ¶
MustGetQueryParams 获取 uri Query参数值 /?a=b&c=d 返回map类型数据 任何一个指定的参数没有传递将触发异常中断流程
func (*Request) MustGetRawBodyData ¶
MustGetRawBodyData 将请求body以字节数据返回 任何错误将触发Panic流程中断
func (*Request) MustGetRawBodyString ¶ added in v0.1.10
MustGetRawBodyString 将请求body以字符串返回 任何错误将触发Panic流程中断
func (*Request) MustSaveUploadedFile ¶
MustSaveUploadedFile 保存上传的文件内容 name: form name dirPath: 保存的路径 (文件夹) filename: 保存的文件名 若不指定则为源文件名 任何错误将触发Panic流程中断
func (*Request) RawGinContext ¶
RawGinContext 获取原始Gin上下文
func (*Request) RequestFullPath ¶ added in v0.1.3
RequestFullPath 获取请求完整路径
func (*Request) RequestPath ¶ added in v0.1.3
RequestPath 获取请求路径
func (*Request) RouterFullPath ¶ added in v0.1.3
RouterFullPath 当前请求的注册路由路径
func (*Request) SaveUploadedFile ¶
SaveUploadedFile 保存上传的文件内容 name: form name dirPath: 保存的路径 (文件夹) filename: 保存的文件名 若不指定则为源文件名
type Response ¶
type Response interface { // Data 响应的Body数据 Data() *ResponseData }
Response 标准响应 用户可以通过自定义实现该接口定义自己的响应结构体 也可以使用NewRespRest来创建自定义响应结构体
func RespAbortWithHttpStatusCode ¶
RespAbortWithHttpStatusCode 设置响应状态码并设置忽略执行后续handler
func RespHttpStatusCode ¶
RespHttpStatusCode 设置响应状态码
func RespRedirect ¶
RespRedirect 响应重定向
func RespRestBadParameters ¶ added in v0.1.9
RespRestBadParameters 响应标准格式的Rest参数错误
func RespRestBizError ¶
func RespRestBizError(bizErrorCode BizErrorCode, bizErrorMessage BizErrorMessage) Response
RespRestBizError 响应标准格式的Rest业务错误
func RespRestException ¶
RespRestException 响应标准格式的Rest系统异常错误
func RespRestRaw ¶ added in v0.1.10
func RespRestRaw(dataRest *RestRespStruct) Response
RespRestRaw 响应标准格式的Rest原始数据
func RespRestStatusError ¶
func RespRestStatusError(statusCode StatusCode, statusMessage ...StatusMessage) Response
RespRestStatusError 响应标准格式的Rest状态错误
func RespRestUnAuthorized ¶ added in v0.1.9
RespRestUnAuthorized 响应标准格式的Rest未授权错误
func RespTextPlain ¶
RespTextPlain 响应Json数据
type ResponseCookie ¶
type ResponseCookie struct {
// contains filtered or unexported fields
}
ResponseCookie 响应Cookie
type ResponseData ¶
type ResponseData struct {
// contains filtered or unexported fields
}
ResponseData 标准响应数据内容
func NewEmptyResponseData ¶ added in v0.1.2
func NewEmptyResponseData() *ResponseData
func NewResponseData ¶
func NewResponseData(contentType string, body []byte) *ResponseData
func NewResponseDataWithStatusCode ¶ added in v0.1.4
func NewResponseDataWithStatusCode(contentType string, body []byte, statusCode int) *ResponseData
func (*ResponseData) AddCookie ¶
func (r *ResponseData) AddCookie(cookie *ResponseCookie) *ResponseData
func (*ResponseData) AddCookies ¶
func (r *ResponseData) AddCookies(cookies []*ResponseCookie) *ResponseData
func (*ResponseData) AddHeader ¶
func (r *ResponseData) AddHeader(name, value string) *ResponseData
func (*ResponseData) AddHeaders ¶
func (r *ResponseData) AddHeaders(headers []*ResponseHeader) *ResponseData
func (*ResponseData) SetContentType ¶
func (r *ResponseData) SetContentType(contentType string) *ResponseData
func (*ResponseData) SetData ¶
func (r *ResponseData) SetData(data []byte) *ResponseData
func (*ResponseData) SetStatusCode ¶
func (r *ResponseData) SetStatusCode(statusCode int) *ResponseData
type ResponseDataStructDecoder ¶
ResponseDataStructDecoder 针对Response.Data() 响应的时结构体数据时的解码为[]byte功能 默认为JSON解码器 用户可以自定义实现该接口 实现自定义解码器
type ResponseHeader ¶
type ResponseHeader struct {
// contains filtered or unexported fields
}
ResponseHeader 响应头
func NewHeader ¶
func NewHeader(name, value string) *ResponseHeader
type RestRespStatusStruct ¶
type RestRespStatusStruct struct { // 标识请求系统状态 200 标识网络请求层面的成功 见StatusCode StatusCode StatusCode `json:"statusCode"` StatusMessage StatusMessage `json:"statusMessage"` // 业务错误码 仅当StatusCode为200时进入业务错误判断 BizErrorCode *BizErrorCode `json:"bizErrorCode"` BizErrorMessage *BizErrorMessage `json:"bizErrorMessage"` // 系统响应时间戳 Timestamp int64 `json:"timestamp"` }
RestRespStatusStruct 框架默认的Rest请求状态结构
type RestRespStruct ¶
type RestRespStruct struct { // 请求状态描述 Status *RestRespStatusStruct `json:"status"` // 仅当StatusCode为200 无业务错误码BizErrorCode 响应成功数据 Data any `json:"data"` }
RestRespStruct 框架默认的Rest请求结构
func NewRestBadParameters ¶ added in v0.1.12
func NewRestBadParameters(statusMessage ...string) *RestRespStruct
NewRestBadParameters 响应标准参数错误Rest结构体
func NewRestBizError ¶ added in v0.1.10
func NewRestBizError(bizErrorCode BizErrorCode, bizErrorMessage BizErrorMessage) *RestRespStruct
NewRestBizError 响应标准业务错误Rest结构体
func NewRestException ¶ added in v0.1.10
func NewRestException(statusMessage ...string) *RestRespStruct
NewRestException 响应标准异常Rest结构体
func NewRestStatusError ¶ added in v0.1.10
func NewRestStatusError(statusCode StatusCode, statusMessage ...StatusMessage) *RestRespStruct
NewRestStatusError 响应标准错误Rest结构体
func NewRestSuccess ¶ added in v0.1.10
func NewRestSuccess(data ...interface{}) *RestRespStruct
NewRestSuccess 响应标准成功Rest结构体
func NewRestUnauthorized ¶ added in v0.1.10
func NewRestUnauthorized(statusMessage ...string) *RestRespStruct
NewRestUnauthorized 响应标准未授权Rest结构体
type Router ¶
type Router interface { // Info 定义路由信息 Info() *RouterInfo // Handlers 注册处理器 Handlers(router *RouterWrapper) }
type RouterInfo ¶
type RouterInfo struct { // GroupPath 路由分组路径 GroupPath string // 该Router下的中间件执行器 Middlewares []Middleware }
type RouterWrapper ¶
type RouterWrapper struct {
// contains filtered or unexported fields
}
RouterWrapper 定义路由包装器
func (*RouterWrapper) DELETE ¶
func (r *RouterWrapper) DELETE(path string, handler ...HandlerWrapper)
func (*RouterWrapper) DELETE1 ¶ added in v0.1.4
func (r *RouterWrapper) DELETE1(path string, contentType []string, handler ...HandlerWrapper)
func (*RouterWrapper) GET ¶
func (r *RouterWrapper) GET(path string, handler ...HandlerWrapper)
func (*RouterWrapper) HEAD ¶
func (r *RouterWrapper) HEAD(path string, handler ...HandlerWrapper)
func (*RouterWrapper) MATCH ¶
func (r *RouterWrapper) MATCH(method []string, path string, handler ...HandlerWrapper)
func (*RouterWrapper) MATCH1 ¶ added in v0.1.4
func (r *RouterWrapper) MATCH1(method []string, path string, contentType []string, handler ...HandlerWrapper)
func (*RouterWrapper) OPTIONS ¶
func (r *RouterWrapper) OPTIONS(path string, handler ...HandlerWrapper)
func (*RouterWrapper) PATCH ¶
func (r *RouterWrapper) PATCH(path string, handler ...HandlerWrapper)
func (*RouterWrapper) PATCH1 ¶ added in v0.1.4
func (r *RouterWrapper) PATCH1(path string, contentType []string, handler ...HandlerWrapper)
func (*RouterWrapper) POST ¶
func (r *RouterWrapper) POST(path string, handler ...HandlerWrapper)
func (*RouterWrapper) POST1 ¶ added in v0.1.4
func (r *RouterWrapper) POST1(path string, contentType []string, handler ...HandlerWrapper)
func (*RouterWrapper) PUT ¶
func (r *RouterWrapper) PUT(path string, handler ...HandlerWrapper)
func (*RouterWrapper) PUT1 ¶ added in v0.1.4
func (r *RouterWrapper) PUT1(path string, contentType []string, handler ...HandlerWrapper)
func (*RouterWrapper) TRACE ¶
func (r *RouterWrapper) TRACE(path string, handler ...HandlerWrapper)
func (*RouterWrapper) TRACE1 ¶ added in v0.1.4
func (r *RouterWrapper) TRACE1(path string, contentType []string, handler ...HandlerWrapper)
type StatusCode ¶
type StatusCode int
type StatusMessage ¶
type StatusMessage string
func GetStatusMessage ¶
func GetStatusMessage(statusCode StatusCode) StatusMessage