Documentation ¶
Index ¶
- Constants
- func Failure(c *gin.Context, code int, format string, args ...interface{})
- func FailureGeneric(c *gin.Context, format string, args ...interface{})
- func Post[R any](baseUrl string, apiUrl string, headers map[string]interface{}, ...) (rsp R, err error)
- func PostFile[R any](baseUrl string, apiUrl string, headers map[string]interface{}, ...) (rsp R, err error)
- func Recovery() gin.HandlerFunc
- func Router[P any, R any](handler RouterHandler[P, R], opt *RouterOptions) gin.HandlerFunc
- func Success[T any](c *gin.Context, data T)
- type Response
- type RouterHandler
- type RouterOptions
Constants ¶
View Source
const ( ResponseCodeOK = 0 // 成功 ResponseCodeFail = 1 // 通用失败 )
常用状态码
Variables ¶
This section is empty.
Functions ¶
func FailureGeneric ¶
未知业务错误
func Post ¶
func Post[R any]( baseUrl string, apiUrl string, headers map[string]interface{}, requestBody interface{}, hasResponse bool, ) (rsp R, err error)
发送内部请求(POST),并解析返回值。
baseUrl:基地址 apiUrl:URL后面的相对地址 headers:HTTP头信息,大小写敏感 requestBody:请求的Body hasResponse:是否解析应答
func PostFile ¶
func PostFile[R any]( baseUrl string, apiUrl string, headers map[string]interface{}, requestBodyKey string, requestBody interface{}, fileKey string, fileName string, fileReader io.Reader, hasResponse bool, ) (rsp R, err error)
发送内部文件请求(POST),并解析返回值。
baseUrl:基地址 apiUrl:URL后面的相对地址 headers:HTTP头信息,大小写敏感 requestBodyKey:请求Body存放在表单的哪个键 requestBody:请求Body fileKey:文件存放在表单的哪个键 fileName:文件名称 fileReader:文件读取句柄 hasResponse:是否解析应答
func Router ¶
func Router[P any, R any]( handler RouterHandler[P, R], opt *RouterOptions, ) gin.HandlerFunc
路由封装函数
Types ¶
type Response ¶
type Response[T any] struct { Code int `json:"code"` // 状态码 Message string `json:"message"` // 错误消息 Data T `json:"data,omitempty"` // (code=OK) 数据区 Timestamp int64 `json:"timestamp"` // 时间戳 }
返回结果格式
type RouterOptions ¶
type RouterOptions struct { FileJsonKey string // 有值时表示是文件路由,记录Json字段存放的PostForm键名称 NoRequest bool // 无需解析请求,默认值false NoResponse bool // 无需返回应答,默认值false }
通用路由处理的选项
Click to show internal directories.
Click to hide internal directories.