Documentation ¶
Index ¶
- Constants
- func ErrorJSON(w http.ResponseWriter, msg string, code int)
- func GetBody(r *http.Request) string
- func InitializationToken(rds redis.Conn, tokenParamsList map[string]*TokenParams, ...)
- func InitializeValidator()
- func ReadJSON(r *http.Request, data interface{}) error
- func SuccessJSON(w http.ResponseWriter, data interface{})
- type Claims
- type ControllerFunc
- type FormatJSON
- type Handle
- type IndexData
- type Router
- func (c *Router) InitializationToken(tokenParamsList map[string]*TokenParams, adminRolesRouter map[int64][]string) *Router
- func (c *Router) ListenAndServe(addr string) error
- func (c *Router) ServeFiles(filePath string) *Router
- func (c *Router) SetAccessLogsFunc(fun func(handle *Handle, r *http.Request, claims *Claims)) *Router
- func (c *Router) SetRouteHandle(routeHandle []*Handle) *Router
- func (c *Router) StatusUnauthorized(writer http.ResponseWriter)
- type Token
- func (c *Token) AuthRouter(rds redis.Conn, adminId int64, router string) bool
- func (c *Token) DelTokenValue(rds redis.Conn, adminId, userId int64)
- func (c *Token) Generate(rds redis.Conn, tokenKey string, adminId, userId int64) string
- func (c *Token) GetContextClaims(r *http.Request) *Claims
- func (c *Token) GetHeaderTokenAndTokenKey(r *http.Request) (string, string)
- func (c *Token) GetTokenAdminRolesRouter(rds redis.Conn, adminId int64) []string
- func (c *Token) GetTokenParams(rds redis.Conn, tokenKey string) *TokenParams
- func (c *Token) GetTokenValue(rds redis.Conn, adminId, userId int64) string
- func (c *Token) GetTokenValueKey(adminId, userId int64) string
- func (c *Token) SetTokenAdminRolesRouter(rds redis.Conn, adminId int64, rolesRouter []string)
- func (c *Token) SetTokenParams(rds redis.Conn, tokenKey string, tokenParams *TokenParams)
- func (c *Token) SetTokenValue(rds redis.Conn, adminId, userId int64, tokenStr string)
- func (c *Token) Verify(rds redis.Conn, r *http.Request) *Claims
- type TokenParams
- type Validator
Constants ¶
const ( TokenParamsRedisName = "_tokenParams" // Token参数缓存名称 TokenValuesRedisName = "_tokenValues" // Token值缓存名称 TokenAdminRolesRouterName = "_adminRolesRouter" // 管理角色路由缓存名称 ClaimsKey contextKey = 1 // claims类型 )
Variables ¶
This section is empty.
Functions ¶
func InitializationToken ¶
func InitializationToken(rds redis.Conn, tokenParamsList map[string]*TokenParams, adminRolesRouter map[int64][]string)
InitializationToken 初始化Token
Types ¶
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 (*Router) InitializationToken ¶
func (c *Router) InitializationToken(tokenParamsList map[string]*TokenParams, adminRolesRouter map[int64][]string) *Router
InitializationToken 初始化Token
func (*Router) ListenAndServe ¶
ListenAndServe 监听服务
func (*Router) SetAccessLogsFunc ¶
func (c *Router) SetAccessLogsFunc(fun func(handle *Handle, r *http.Request, claims *Claims)) *Router
SetAccessLogsFunc 设置访问日志函数
func (*Router) SetRouteHandle ¶
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 ¶
AuthRouter 验证路由
func (*Token) DelTokenValue ¶ added in v1.10.4
DelTokenValue 删除Token值
func (*Token) GetContextClaims ¶
GetContextClaims 获取当前Claims
func (*Token) GetHeaderTokenAndTokenKey ¶
GetHeaderTokenAndTokenKey 获取头信息Token参数
func (*Token) GetTokenAdminRolesRouter ¶
GetTokenAdminRolesRouter 获取管理角色路由列表
func (*Token) GetTokenParams ¶
func (c *Token) GetTokenParams(rds redis.Conn, tokenKey string) *TokenParams
GetTokenParams 获取Token参数
func (*Token) GetTokenValue ¶
GetTokenValue 获取Token值
func (*Token) GetTokenValueKey ¶
GetTokenValueKey 获取Token值key
func (*Token) SetTokenAdminRolesRouter ¶
SetTokenAdminRolesRouter 设置管理角色路由列表
func (*Token) SetTokenParams ¶
func (c *Token) SetTokenParams(rds redis.Conn, tokenKey string, tokenParams *TokenParams)
SetTokenParams 设置Token参数
func (*Token) SetTokenValue ¶
SetTokenValue 设置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 ¶
AddTranslation 添加翻译文本
func (*Validator) RegisterTagNameFunc ¶
func (c *Validator) RegisterTagNameFunc()
RegisterTagNameFunc 注册Tag名称方法