Documentation
¶
Index ¶
- Constants
- func Handle(h HandlerFunc) gin.HandlerFunc
- func LoggerError(comp, typ string, data interface{})
- func Uid(c *gin.Context) int
- type Context
- func (c *Context) Bind(obj interface{}) (err error)
- func (c *Context) JSON(httpStatus int, res Res)
- func (c *Context) JSONE(code int, msg string, data interface{})
- func (c *Context) JSONOK(data ...interface{})
- func (c *Context) JSONPage(data interface{}, pagination Pagination)
- func (c *Context) ShouldBind(obj interface{}) (err error)
- func (c *Context) Uid() int
- func (c *Context) User() *User
- type HandlerFunc
- type Pagination
- type Res
- type ResPage
- type User
Constants ¶
const ( // CodeOK means a successful response CodeOK = 0 // CodeErr means a failure response CodeErr = 1 // DefaultPaginationSize defines pagination size of an item list response DefaultPaginationSize = 20 )
const (
UserContextKey = "moauth/context/user"
)
Variables ¶
This section is empty.
Functions ¶
func Handle ¶
func Handle(h HandlerFunc) gin.HandlerFunc
Handle convert HandlerFunc to gin.HandlerFunc
func LoggerError ¶ added in v0.4.3
func LoggerError(comp, typ string, data interface{})
Types ¶
type Context ¶
Context a wrapper of gin.Context
func (*Context) JSONE ¶
JSONE returns JSON response with failure business code ,msg and data e.x. {"code":<code>, "msg":<msg>, "data":<data>}
func (*Context) JSONOK ¶
func (c *Context) JSONOK(data ...interface{})
JSONOK returns JSON response with successful business code and data e.x. {"code":0, "msg":"成功", "data":<data>}
func (*Context) JSONPage ¶
func (c *Context) JSONPage(data interface{}, pagination Pagination)
JSONPage returns JSON response with pagination e.x. {"code":<code>, "msg":<msg>, "data":<data>, "pagination":<pagination>} <pagination> { "current":1, "pageSize":20, "total": 9 }
func (*Context) ShouldBind ¶
ShouldBind wraps gin context.ShouldBind() with custom validator
type HandlerFunc ¶
type HandlerFunc func(c *Context)
HandlerFunc defines the handler to wrap gin.Context
type Pagination ¶
type Pagination struct { // Current means current page number Current int `json:"current" form:"current"` // PageSize means max item count of a page PageSize int `json:"pageSize" form:"pageSize"` // Total means total page count Total int64 `json:"total" form:"total"` // Sort means sort expression Sort string `json:"sort" form:"sort"` }
func (*Pagination) List ¶
func (p *Pagination) List(db *gorm.DB, list interface{})
func (*Pagination) Valid ¶
func (p *Pagination) Valid() error
type Res ¶
type Res struct { // Code means response business code Code int `json:"code"` // Msg means response extra message Msg string `json:"msg"` // Data means response data payload Data interface{} `json:"data"` }
Res defines HTTP JSON response
type ResPage ¶
type ResPage struct { Res Pagination Pagination `json:"pagination"` }
ResPage defines HTTP JSON response with extra pagination data
type User ¶
type User struct { Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` Nickname string `protobuf:"bytes,2,opt,name=nickname,proto3" json:"nickname,omitempty"` Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"` Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar,omitempty"` Email string `protobuf:"bytes,5,opt,name=email,proto3" json:"email,omitempty"` }