app

package
v0.0.0-...-7ed5fb6 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(appKey string) (string, error)

生成 token

func GetJWTSecret

func GetJWTSecret() []byte

func GetPage

func GetPage(c *gin.Context) int

func GetPageOffset

func GetPageOffset(page, pageSize int) int

计算分页偏移量

func GetPageSize

func GetPageSize(c *gin.Context) int

Types

type Claims

type Claims struct {
	AppKey string `json:"app_key"`
	jwt.StandardClaims
}

jwt token 验证实现

func ParseToken

func ParseToken(token string) (*Claims, error)

解析和验证 token

type Pagination

type Pagination struct {
	Page      int `json:"page"`
	PageSize  int `json:"page_size"`
	TotalRows int `json:"total_rows"`
}

type Response

type Response struct {
	Ctx *gin.Context
}

func NewResponse

func NewResponse(ctx *gin.Context) *Response

func (*Response) Success

func (r *Response) Success(data interface{})

列表返回

func (*Response) ToErrorResponse

func (r *Response) ToErrorResponse(err *error.Error)

func (*Response) ToResponse

func (r *Response) ToResponse(data interface{}, err *error.Error)

type ValidatorError

type ValidatorError struct {
	Key     string
	Message string
}

对应每个 form 表单的字段验证信息

func (*ValidatorError) Error

func (v *ValidatorError) Error() string

type ValidatorErrors

type ValidatorErrors []*ValidatorError

func BindAndValid

func BindAndValid(c *gin.Context, v interface{}) (bool, ValidatorErrors)

对数据绑定并且验证

func (ValidatorErrors) Error

func (v ValidatorErrors) Error() string

func (ValidatorErrors) Errors

func (v ValidatorErrors) Errors() []string

获取所有验证错误信息

Jump to

Keyboard shortcuts

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