Documentation
¶
Index ¶
- Variables
- func EasyHandler(cf CheckFunc, lf LogicFunc, req interface{}) gin.HandlerFunc
- func Handler(cf BusinessLogic, lf BusinessLogic, req interface{}) gin.HandlerFunc
- func URLPatterns(route RouteAdapter, path string, childRoute DoChildRouteFunc, ...)
- type BaseReqInter
- type BaseRespHeader
- type BaseRespInter
- type BusinessLogic
- type CheckFunc
- type DoChildRouteFunc
- type LogicFunc
- type Request
- type Response
- type RouteAdapter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( SuccessRespHeader = BaseRespHeader{Code: http.StatusOK, Msg: "ok"} SystemErrorRespHeader = BaseRespHeader{Code: http.StatusInternalServerError, Msg: "系统异常"} ParamErrorRespHeader = BaseRespHeader{Code: http.StatusBadRequest, Msg: "参数错误"} ForbiddenErrorRespHeader = BaseRespHeader{Code: http.StatusForbidden, Msg: "拒绝服务"} )
Functions ¶
func EasyHandler ¶
func EasyHandler(cf CheckFunc, lf LogicFunc, req interface{}) gin.HandlerFunc
解析请求,整合检查请求参数,响应逻辑,并响应
Example ¶
engine := gin.Default()
defer engine.Run(":8888")
URLPatterns(engine, "/ping", func(g *gin.RouterGroup) {
g.POST("/", EasyHandler(easyCheck, easyServer, TestResp{}))
})
func Handler ¶
func Handler(cf BusinessLogic, lf BusinessLogic, req interface{}) gin.HandlerFunc
Handler 类似于 EasyHandler, 但 cf 和 lf 都可以用于 net/rpc
Example ¶
engine := gin.Default()
defer engine.Run(":8888")
URLPatterns(engine, "/ping", func(g *gin.RouterGroup) {
g.POST("/", Handler(server, check, TestReq{}))
})
func URLPatterns ¶
func URLPatterns(route RouteAdapter, path string, childRoute DoChildRouteFunc, middles ...gin.HandlerFunc)
URL 调度器
Types ¶
type BaseReqInter ¶
type BaseRespHeader ¶
type BaseRespInter ¶
type BaseRespInter interface{}
type BusinessLogic ¶
type CheckFunc ¶
type CheckFunc func(ctx *gin.Context, req BaseReqInter) (BaseRespInter, error)
type DoChildRouteFunc ¶
type DoChildRouteFunc func(g *gin.RouterGroup) // 子路由
type LogicFunc ¶
type LogicFunc func(ctx *gin.Context, req BaseReqInter) BaseRespInter
type Request ¶
type Request struct {
Ctx *gin.Context
Req BaseReqInter
}
type Response ¶
type Response struct {
RespCode int
Resp BaseRespInter
}
type RouteAdapter ¶
type RouteAdapter interface {
Use(middleware ...gin.HandlerFunc) gin.IRoutes
Group(relativePath string, handlers ...gin.HandlerFunc) *gin.RouterGroup
}
用于适配 Engine 和 RouteGroup
Click to show internal directories.
Click to hide internal directories.