auth

package
v0.0.0-...-c0e18de Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ProviderSet 是一个 Wire 的 Provider 集合,用于声明依赖注入的规则。Add commentMore actions 包含 NewAuthz 构造函数,用于生成 Authz 实例。

Functions

func Compare

func Compare(hashedPassword, password string) error

Compare 比较密文和明文是否相同.

func Encrypt

func Encrypt(source string) (string, error)

Encrypt 使用 bcrypt 加密纯文本.

Types

type Authz

type Authz struct {
	*casbin.SyncedEnforcer // 使用 Casbin 的同步授权器
}

Authz 定义了一个授权器,提供授权功能.

func NewAuthz

func NewAuthz(db *gorm.DB, opts ...Option) (*Authz, error)

NewAuthz 创建一个使用 Casbin 完成授权的授权器,通过函数选项模式支持自定义配置.

func (*Authz) Authorize

func (a *Authz) Authorize(sub, obj, act string) (bool, error)

Authorize 用于进行授权.

type Option

type Option func(*authzConfig)

Option 定义了一个函数选项类型,用于自定义 NewAuthz 的行为.

func DefaultOptions

func DefaultOptions() []Option

DefaultOptions 提供默认的授权器选项配置.

func WithAclModel

func WithAclModel(model string) Option

WithAclModel 允许通过选项自定义 ACL 模型.

func WithAutoLoadPolicyTime

func WithAutoLoadPolicyTime(interval time.Duration) Option

WithAutoLoadPolicyTime 允许通过选项自定义自动加载策略的时间间隔.

Jump to

Keyboard shortcuts

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