app

package
v0.0.0-...-8406b6b Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package app JWT权限处理,例如生成、校验token

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(appKey, appSecret string) (string, error)

GenerateToken 生成 JWT Token ,JWT的核心函数

func GetJWTSecret

func GetJWTSecret() []byte

GetJWTSecret 获取该项目的 JWT Secret,目前我们是直接使用配置所配置的 Secret

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"`
	AppSecret string `json:"app_secret"`
	// 这是jwt库里预定义的,也就是JWT的规范,可以点进去看源码
	jwt.StandardClaims
}

Claims JMT 数据结构,用于计算token

func ParseToken

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

ParseToken 解析和校验 Token,与GenerateToken相对 其函数流程主要是解析传入的 Token,然后根据 Claims 的相关属性要求进行校验

type Pager

type Pager 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) ToErrorResponse

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

func (*Response) ToResponse

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

func (*Response) ToResponseList

func (r *Response) ToResponseList(list interface{}, totalRows int)

type ValidError

type ValidError struct {
	Key     string
	Message string
}

ValidError 自定义错误类型

func (*ValidError) Error

func (v *ValidError) Error() string

Error 实现接口才被识别为自定义错误

type ValidErrors

type ValidErrors []*ValidError

ValidErrors 自定义数组错误类型

func BindAndValidBody

func BindAndValidBody(c *gin.Context, v interface{}) (bool, ValidErrors)

func BindAndValidHeader

func BindAndValidHeader(c *gin.Context, v interface{}) (bool, ValidErrors)

func (ValidErrors) Error

func (v ValidErrors) Error() string

Error 实现接口才被识别为自定义错误

func (ValidErrors) Errors

func (v ValidErrors) Errors() []string

Errors 实现接口才被识别为自定义错误,错误可以是一个列表,包含多个错误

Jump to

Keyboard shortcuts

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