middleware

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(af AuthFunc) gin.HandlerFunc

授权中间件,注册使用中间件后,如果授权未通过(af() return nil, false) 请求会被在此拦截并响应 301,反之, 如果授权通过,会在请求上下文对象 context 中添加一个 user 字段,保存授权的用户信息,授权后可以使用 ctx.Get("user") 经过类型转换后获取到该 User 对象

func CorsHandler

func CorsHandler(accessList []string) gin.HandlerFunc

accessList: 允许访问的白名单

func Permiter

func Permiter(license PermiterFunc) gin.HandlerFunc

鉴权中间件, 注册该中间件后, 如果 license 返回 true 则表示 有权限访问该组(个)接口, 否则响应 403

Types

type AuthFunc

type AuthFunc func(context *gin.Context) (UserBase, bool)

检查授权,如果授权通过,返回授权用户,否则第二个参数返回 false

type PermiterFunc

type PermiterFunc func(context *gin.Context) bool

type UserBase

type UserBase interface {
	GetID() int
}

Jump to

Keyboard shortcuts

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