Documentation ¶
Index ¶
- func Cors() gin.HandlerFunc
- type Context
- func (c *Context) Bad(code int, msg string) ICustomResp
- func (c *Context) BadCode(err errorx.ErrorCode) ICustomResp
- func (c *Context) BadError(err error) ICustomResp
- func (c *Context) Bind(v any) error
- func (c *Context) BindForm(v any) error
- func (c *Context) BindHeader(v any) error
- func (c *Context) BindJson(v any) error
- func (c *Context) BindJsonpb(v proto.Message) error
- func (c *Context) BindQuery(v any) error
- func (c *Context) BindUri(v any) error
- func (c *Context) Biz(code int, msg string, data any) ICustomResp
- func (c *Context) BizBad(code int, msg string) ICustomResp
- func (c *Context) BizBadCode(err errorx.ErrorCode) ICustomResp
- func (c *Context) BizBadError(err error) ICustomResp
- func (c *Context) BizData(data any) ICustomResp
- func (c *Context) Context() context.Context
- func (c *Context) Data(data any) ICustomResp
- func (c *Context) Forbidden() ICustomResp
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) GetReqHeader(key string) string
- func (c *Context) GetRespHeader(key string) string
- func (c *Context) Set(key string, value any)
- func (c *Context) SetReqHeader(key string, value string)
- func (c *Context) SetRespHeader(key string, value string)
- func (c *Context) UnAuth() ICustomResp
- type ICustomResp
- type IRoute
- type RouteContext
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cors ¶
func Cors() gin.HandlerFunc
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Bad ¶
func (c *Context) Bad(code int, msg string) ICustomResp
Bad http状态码为400的错误返回,可以指定code和msg
http status: 400
example:
{ "code": 1001, "msg": "用户名或密码错误" }
func (*Context) BadCode ¶
func (c *Context) BadCode(err errorx.ErrorCode) ICustomResp
BadCode http状态码为400的错误返回,自定义code
http status: 400
example:
{ "code": 1001, "msg": "用户名或密码错误" }
func (*Context) BadError ¶
func (c *Context) BadError(err error) ICustomResp
BadError http状态码为400的错误返回,code=400
http status: 400
example:
{ "code": 400, "msg": "用户名或密码错误" }
func (*Context) BindHeader ¶
func (*Context) BindJsonpb ¶
BindJsonpb 绑定数据到protobuf struct
func (*Context) Biz ¶
func (c *Context) Biz(code int, msg string, data any) ICustomResp
Biz 业务数据,可以指定code和msg
http status: 200
example:
{ "code": 0, "msg": "success", "data": { "id": 1, "name": "张三" } }
func (*Context) BizBad ¶
func (c *Context) BizBad(code int, msg string) ICustomResp
BizBad 业务错误,可以指定code和msg
http status: 200
example:
{ "code": 1001, "msg": "用户名或密码错误" }
func (*Context) BizBadCode ¶
func (c *Context) BizBadCode(err errorx.ErrorCode) ICustomResp
BizBadCode 业务错误,自定义错误码
http status: 200
example:
{ "code": 1001, "msg": "用户名或密码错误" }
func (*Context) BizBadError ¶
func (c *Context) BizBadError(err error) ICustomResp
BizBadError 业务错误,code=400
http status: 200
example:
{ "code": 400, "msg": "用户名或密码错误" }
func (*Context) BizData ¶
func (c *Context) BizData(data any) ICustomResp
BizData 业务数据
http status: 200
example:
{ "code": 0, "msg": "success", "data": { "id": 1, "name": "张三" } }
func (*Context) Data ¶
func (c *Context) Data(data any) ICustomResp
Data http状态码为200的数据返回
http status: 200
example:
{ "id": 1, "name": "张三" }
func (*Context) Forbidden ¶
func (c *Context) Forbidden() ICustomResp
Forbidden 禁止访问
http status: 403
example:
{ "code": 403, "msg": "禁止访问" }
func (*Context) GetReqHeader ¶
GetReqHeader get header
func (*Context) GetRespHeader ¶
GetRespHeader get header
func (*Context) SetReqHeader ¶
SetReqHeader set header
func (*Context) SetRespHeader ¶
SetRespHeader set header
func (*Context) UnAuth ¶
func (c *Context) UnAuth() ICustomResp
type ICustomResp ¶
type IRoute ¶
type IRoute interface {
Routes(ctx *RouteContext)
}
type RouteContext ¶
func (*RouteContext) Handle ¶
func (r *RouteContext) Handle(fn func(ctx *Context) any) gin.HandlerFunc
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ...ServerOption) (*Server, error)
NewServer 创建一个新的Server,默认debug模式
type ServerOption ¶
type ServerOption func(*Server)
ServerOption Server Option type
func WithAuthMiddleware ¶
func WithAuthMiddleware(authMiddleware gin.HandlerFunc) ServerOption
WithAuthMiddleware 设置认证中间件