router

package
v1.11.11 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenParamsRedisName                 = "_tokenParams"      //	Token参数缓存名称
	TokenValuesRedisName                 = "_tokenValues"      //	Token值缓存名称
	TokenAdminRolesRouterName            = "_adminRolesRouter" //	管理角色路由缓存名称
	ClaimsKey                 contextKey = 1                   //	claims类型
)

Variables

This section is empty.

Functions

func ErrorJSON

func ErrorJSON(w http.ResponseWriter, msg string, code int)

ErrorJSON 返回错误数据

func GetBody added in v1.0.5

func GetBody(r *http.Request) string

GetBody 获取body数据

func InitializationToken

func InitializationToken(rds redis.Conn, tokenParamsList map[string]*TokenParams, adminRolesRouter map[int64][]string)

InitializationToken 初始化Token

func InitializeValidator

func InitializeValidator()

InitializeValidator 初始化验证器

func ReadJSON added in v1.0.9

func ReadJSON(r *http.Request, data interface{}) error

ReadJSON 读取 Json Body

func SuccessJSON

func SuccessJSON(w http.ResponseWriter, data interface{})

SuccessJSON 返回成功数据

Types

type Claims

type Claims struct {
	UserId             int64 //	用户ID
	AdminId            int64 //	管理员ID
	jwt.StandardClaims       //	jwt基础参数
}

Claims Token对象

type ControllerFunc

type ControllerFunc func(w http.ResponseWriter, r *http.Request, p httprouter.Params)

ControllerFunc 控制器方法名

type FormatJSON

type FormatJSON struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

FormatJSON JSON格式数据

type Handle

type Handle struct {
	Name       string         //	名称
	Module     string         //	模块
	Method     string         // 	类型
	Route      string         // 	路由
	Controller ControllerFunc //	控制器
	RouteAuth  bool           //	路由验证
	TokenAuth  bool           //	Token验证
}

func NewHandle

func NewHandle(module, name, method, route string, controllerFunc ControllerFunc, routeAuth, tokenAuth bool) *Handle

NewHandle 创建路由

func NewHomeHandle added in v1.10.9

func NewHomeHandle(module, name, method, route string, controllerFunc ControllerFunc, tokenAuth bool) *Handle

NewHomeHandle 前台路由

type IndexData added in v1.10.1

type IndexData struct {
	Items interface{} `json:"items"`
	Count int64       `json:"count"`
}

IndexData 列表数据

type Router

type Router struct {
	RedisManager *redis.Pool //	缓存池

	AccessLogsFunc func(handle *Handle, r *http.Request, claims *Claims) //	访问日志
	// contains filtered or unexported fields
}

func NewRoute

func NewRoute(redisManager *redis.Pool) *Router

NewRoute 创建路由

func (*Router) InitializationToken

func (c *Router) InitializationToken(tokenParamsList map[string]*TokenParams, adminRolesRouter map[int64][]string) *Router

InitializationToken 初始化Token

func (*Router) ListenAndServe

func (c *Router) ListenAndServe(addr string) error

ListenAndServe 监听服务

func (*Router) ServeFiles

func (c *Router) ServeFiles(filePath string) *Router

ServeFiles 开启静态资源

func (*Router) SetAccessLogsFunc

func (c *Router) SetAccessLogsFunc(fun func(handle *Handle, r *http.Request, claims *Claims)) *Router

SetAccessLogsFunc 设置访问日志函数

func (*Router) SetRouteHandle

func (c *Router) SetRouteHandle(routeHandle []*Handle) *Router

SetRouteHandle 设置路由函数

func (*Router) StatusUnauthorized

func (c *Router) StatusUnauthorized(writer http.ResponseWriter)

StatusUnauthorized 返回没有权限

type Token

type Token struct {
}
var TokenManager *Token

TokenManager Token管理

func (*Token) AuthRouter

func (c *Token) AuthRouter(rds redis.Conn, adminId int64, router string) bool

AuthRouter 验证路由

func (*Token) DelTokenValue added in v1.10.4

func (c *Token) DelTokenValue(rds redis.Conn, adminId, userId int64)

DelTokenValue 删除Token值

func (*Token) Generate

func (c *Token) Generate(rds redis.Conn, tokenKey string, adminId, userId int64) string

Generate 生成Token

func (*Token) GetContextClaims

func (c *Token) GetContextClaims(r *http.Request) *Claims

GetContextClaims 获取当前Claims

func (*Token) GetHeaderTokenAndTokenKey

func (c *Token) GetHeaderTokenAndTokenKey(r *http.Request) (string, string)

GetHeaderTokenAndTokenKey 获取头信息Token参数

func (*Token) GetTokenAdminRolesRouter

func (c *Token) GetTokenAdminRolesRouter(rds redis.Conn, adminId int64) []string

GetTokenAdminRolesRouter 获取管理角色路由列表

func (*Token) GetTokenParams

func (c *Token) GetTokenParams(rds redis.Conn, tokenKey string) *TokenParams

GetTokenParams 获取Token参数

func (*Token) GetTokenValue

func (c *Token) GetTokenValue(rds redis.Conn, adminId, userId int64) string

GetTokenValue 获取Token值

func (*Token) GetTokenValueKey

func (c *Token) GetTokenValueKey(adminId, userId int64) string

GetTokenValueKey 获取Token值key

func (*Token) SetTokenAdminRolesRouter

func (c *Token) SetTokenAdminRolesRouter(rds redis.Conn, adminId int64, rolesRouter []string)

SetTokenAdminRolesRouter 设置管理角色路由列表

func (*Token) SetTokenParams

func (c *Token) SetTokenParams(rds redis.Conn, tokenKey string, tokenParams *TokenParams)

SetTokenParams 设置Token参数

func (*Token) SetTokenValue

func (c *Token) SetTokenValue(rds redis.Conn, adminId, userId int64, tokenStr string)

SetTokenValue 设置Token值

func (*Token) Verify

func (c *Token) Verify(rds redis.Conn, r *http.Request) *Claims

Verify 验证Token

type TokenParams

type TokenParams struct {
	Key       string        `json:"key"`       //	密钥
	Only      bool          `json:"only"`      //	是否唯一
	Expire    time.Duration `json:"expire"`    //	过期时间
	Whitelist string        `json:"whitelist"` //	白名单
	Blacklist string        `json:"blacklist"` //	黑名单
}

TokenParams Token 参数

type Validator

type Validator struct {
	Validate *validator.Validate
	Trans    ut.Translator
}

Validator 验证器

var ValidatorManager *Validator

ValidatorManager 验证器管理

func (*Validator) AddTranslation

func (c *Validator) AddTranslation(tag string, errMessage string)

AddTranslation 添加翻译文本

func (*Validator) RegisterTagNameFunc

func (c *Validator) RegisterTagNameFunc()

RegisterTagNameFunc 注册Tag名称方法

func (*Validator) Struct

func (c *Validator) Struct(s any) error

Struct 验证结构体

Jump to

Keyboard shortcuts

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