middleware

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LocaleFS embed.FS

LocaleFS 加载国际化文件

Functions

func Cors

func Cors() func(http.Handler) http.Handler

Cors 跨域中间件

func GetOperation

func GetOperation(ctx context.Context) string

GetOperation is get operation from context

func GetSourceType

func GetSourceType(ctx context.Context) vobj.SourceType

GetSourceType get source type

func GetTeamID added in v1.1.0

func GetTeamID(ctx context.Context) uint32

GetTeamID get team id

func GetTeamMemberID added in v1.1.0

func GetTeamMemberID(ctx context.Context) uint32

GetTeamMemberID get team member id

func GetUserID added in v1.1.0

func GetUserID(ctx context.Context) uint32

GetUserID get user id

func GetUserRole

func GetUserRole(ctx context.Context) vobj.Role

GetUserRole get user role

func I18N

func I18N() middleware.Middleware

I18N 国际化中间件

func IsExpire

func IsExpire(jwtClaims *JwtClaims) bool

IsExpire 是否过期

func JwtLoginMiddleware

func JwtLoginMiddleware(check CheckTokenFun) middleware.Middleware

JwtLoginMiddleware jwt login middleware

func JwtServer

func JwtServer() middleware.Middleware

JwtServer jwt server

func Logging

func Logging(logger log.Logger) middleware.Middleware

Logging is an server logging middleware.

func NewWhiteListMatcher

func NewWhiteListMatcher(list []string) selector.MatchFunc

NewWhiteListMatcher new white list matcher

func Rbac

Rbac 权限校验中间件

func SetExpire

func SetExpire(e time.Duration)

SetExpire set expire

func SetIssuer

func SetIssuer(iss string)

SetIssuer set issuer

func SetSignKey

func SetSignKey(key string)

SetSignKey set sign key

func SourceType

func SourceType() middleware.Middleware

SourceType 获取请求头中的Source-Type sourceType System Team

func Validate

func Validate(opts ...protovalidate.ValidatorOption) middleware.Middleware

Validate 验证请求参数

func WithTeamIDContextKey added in v1.1.0

func WithTeamIDContextKey(ctx context.Context, id uint32) context.Context

WithTeamIDContextKey with team id context key

func WithTeamMemberIDContextKey added in v1.1.0

func WithTeamMemberIDContextKey(ctx context.Context, id uint32) context.Context

WithTeamMemberIDContextKey with team member id context key

func WithUserIDContextKey added in v1.1.0

func WithUserIDContextKey(ctx context.Context, id uint32) context.Context

WithUserIDContextKey with user id context key

func WithUserRoleContextKey

func WithUserRoleContextKey(ctx context.Context, role vobj.Role) context.Context

WithUserRoleContextKey with user role context key

Types

type CheckRbacFun

type CheckRbacFun func(ctx context.Context, operation string) (*authorizationapi.CheckPermissionReply, error)

CheckRbacFun 权限校验函数

type CheckTokenFun

type CheckTokenFun func(ctx context.Context) (*authorization.CheckTokenReply, error)

CheckTokenFun check token fun

type JwtBaseInfo

type JwtBaseInfo struct {
	UserID   uint32 `json:"user"`
	TeamID   uint32 `json:"team"`
	MemberID uint32 `json:"member"`
}

JwtBaseInfo jwt base info

func (*JwtBaseInfo) GetMember

func (l *JwtBaseInfo) GetMember() uint32

GetMember 获取成员id

func (*JwtBaseInfo) GetTeam

func (l *JwtBaseInfo) GetTeam() uint32

GetTeam 获取团队id

func (*JwtBaseInfo) GetUser

func (l *JwtBaseInfo) GetUser() uint32

GetUser 获取用户id

func (*JwtBaseInfo) SetMember

func (l *JwtBaseInfo) SetMember(memberID uint32) *JwtBaseInfo

SetMember 设置成员信息

func (*JwtBaseInfo) SetTeamInfo

func (l *JwtBaseInfo) SetTeamInfo(teamID uint32) *JwtBaseInfo

SetTeamInfo 设置团队信息

func (*JwtBaseInfo) SetUserInfo

func (l *JwtBaseInfo) SetUserInfo(userID uint32) *JwtBaseInfo

SetUserInfo 设置用户信息

type JwtClaims

type JwtClaims struct {
	*JwtBaseInfo
	*jwtv5.RegisteredClaims
}

JwtClaims jwt claims

func NewJwtClaims

func NewJwtClaims(base *JwtBaseInfo) *JwtClaims

NewJwtClaims new jwt claims

func ParseJwtClaims

func ParseJwtClaims(ctx context.Context) (*JwtClaims, bool)

ParseJwtClaims parse jwt claims

func (*JwtClaims) GetToken

func (l *JwtClaims) GetToken() (string, error)

GetToken get token

func (*JwtClaims) IsLogout

func (l *JwtClaims) IsLogout(ctx context.Context, cache cache.ICacher) bool

IsLogout 是否已经登出

func (*JwtClaims) Logout

func (l *JwtClaims) Logout(ctx context.Context, cache cache.ICacher) error

Logout 缓存token hash

type Selector

type Selector struct {
	// contains filtered or unexported fields
}

Selector is middleware selector

func Client

func Client(ms ...middle.Middleware) *Selector

Client selector middleware

func Server

func Server(ms ...middle.Middleware) *Selector

Server selector middleware

func (*Selector) Build

func (b *Selector) Build() middle.Middleware

Build is Builder's Build, for example: Server().Path(m1,m2).Build()

func (*Selector) Match

func (b *Selector) Match(fn selector.MatchFunc) *Selector

Match is with Builder's match

func (*Selector) Path

func (b *Selector) Path(path ...string) *Selector

Path is with Builder's path

func (*Selector) Prefix

func (b *Selector) Prefix(prefix ...string) *Selector

Prefix is with Builder's prefix

func (*Selector) Regex

func (b *Selector) Regex(regex ...string) *Selector

Regex is with Builder's regex

type ValidateHandler

type ValidateHandler func(ctx context.Context, req interface{}) error

func ValidateParams

func ValidateParams(opts ...protovalidate.ValidatorOption) ValidateHandler

ValidateParams 验证请求参数

Jump to

Keyboard shortcuts

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