enforcer

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultModelText 默认 casbin 模型文本
	DefaultModelText = `` /* 289-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ModelText     string        `json:",optional"`      // casbin 模型文本,为空则使用 DefaultModelText
	RetryDuration time.Duration `json:",default=500ms"` // 加载决策规则重试间隔
	RetryMaxTimes int           `json:",default=5"`     // 加载决策规则重试最大次数
}

Config 决策规则执行器配置

type Enforcer

type Enforcer struct {
	*casbin.SyncedEnforcer
	// contains filtered or unexported fields
}

Enforcer 决策规则执行器

func MustNewEnforcer

func MustNewEnforcer(c Config, a persist.Adapter, w persist.Watcher) *Enforcer

MustNewEnforcer 新建决策规则执行器

func NewEnforcer

func NewEnforcer(c Config, a persist.Adapter, w persist.Watcher) (*Enforcer, error)

NewEnforcer 新建决策规则执行器

func (*Enforcer) Reload

func (e *Enforcer) Reload(retryDuration time.Duration, retryMaxTimes int)

Reload 重新加载决策规则

func (*Enforcer) Update

func (e *Enforcer) Update()

Update 更新决策规则信息

type MockAdapter

type MockAdapter struct{}

MockAdapter 模拟决策规则适配器

func (*MockAdapter) AddPolicy

func (a *MockAdapter) AddPolicy(sec, ptype string, rule []string) error

AddPolicy 添加决策规则

func (*MockAdapter) LoadPolicy

func (a *MockAdapter) LoadPolicy(m model.Model) error

LoadPolicy 加载决策规则

func (*MockAdapter) RemoveFilteredPolicy

func (a *MockAdapter) RemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy 移除筛选后的决策规则

func (*MockAdapter) RemovePolicy

func (a *MockAdapter) RemovePolicy(sec, ptype string, rule []string) error

RemovePolicy 移除决策规则

func (*MockAdapter) SavePolicy

func (a *MockAdapter) SavePolicy(m model.Model) error

SavePolicy 保存决策规则

type MockWatcher

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

MockWatcher 模拟决策规则观察器

func (*MockWatcher) Close

func (w *MockWatcher) Close()

Close 关闭模拟决策规则观察器

func (*MockWatcher) SetUpdateCallback

func (w *MockWatcher) SetUpdateCallback(callback func(string)) error

SetUpdateCallback 设置更新回调函数

func (*MockWatcher) Update

func (w *MockWatcher) Update() error

Update 调用更新回调函数

Jump to

Keyboard shortcuts

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