core

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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{})

func Uid

func Uid(c *gin.Context) int

Uid get uid from gin.Context

Types

type Context

type Context struct {
	*gin.Context
}

Context a wrapper of gin.Context

func (*Context) Bind

func (c *Context) Bind(obj interface{}) (err error)

Bind wraps gin context.Bind() with custom validator

func (*Context) JSON

func (c *Context) JSON(httpStatus int, res Res)

JSON returns JSON response e.x. {"code":<code>, "msg":<msg>, "data":<data>}

func (*Context) JSONE

func (c *Context) JSONE(code int, msg string, data interface{})

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

func (c *Context) ShouldBind(obj interface{}) (err error)

ShouldBind wraps gin context.ShouldBind() with custom validator

func (*Context) Uid

func (c *Context) Uid() int

Uid gets uid from context

func (*Context) User

func (c *Context) User() *User

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"`
}

func ContextUser

func ContextUser(c *gin.Context) *User

ContextUser get user from gin.Context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL