casbin

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyCasbin runtime.Key = "casbin"

	DefaultModelPath = "configs/rbac_model.conf"
	DefaultSuperRole = "admin"
	DefaultRuleTable = "casbin_rule"
)

Variables

This section is empty.

Functions

func Bind

func Bind(app *runtime.App, manager *Manager) error

func DeletePolicyRules added in v0.1.4

func DeletePolicyRules(ctx context.Context, db *gorm.DB, filter RuleFilter) error

func DeletePolicyTuples added in v0.1.4

func DeletePolicyTuples(ctx context.Context, db *gorm.DB, rules []Rule) error

func EnsurePolicyTable added in v0.1.4

func EnsurePolicyTable(ctx context.Context, db *gorm.DB) error

func Init

func Init(db *database.Database, cfg Config) error

func InitContext

func InitContext(ctx context.Context, db *database.Database, cfg Config) error

func InsertPolicyRules added in v0.1.4

func InsertPolicyRules(ctx context.Context, db *gorm.DB, rules []Rule) error

func PolicyRuleCountsByV0 added in v0.1.4

func PolicyRuleCountsByV0(ctx context.Context, db *gorm.DB, filter RuleFilter, keyFunc func(Rule) string) (map[string]int64, error)

func Reload

func Reload()

func ReplacePolicyRules added in v0.1.4

func ReplacePolicyRules(ctx context.Context, db *gorm.DB, deleteFilter RuleFilter, rules []Rule) error

Types

type Config

type Config struct {
	ModelPath       string `mapstructure:"model_path" yaml:"model_path"`
	SuperRole       string `mapstructure:"super_role" yaml:"super_role"`
	AutoCreateTable bool   `mapstructure:"auto_create_table" yaml:"auto_create_table"`
	RuleTable       string `mapstructure:"rule_table" yaml:"rule_table"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}
var Default *Manager

func From

func From(app *runtime.App) *Manager

func New

func New(db *database.Database, cfg Config) (*Manager, error)

func NewContext

func NewContext(ctx context.Context, db *database.Database, cfg Config) (*Manager, error)

func (*Manager) Enforce

func (m *Manager) Enforce(sub, obj, act string) (bool, error)

func (*Manager) Enforcer

func (m *Manager) Enforcer() *gocasbin.Enforcer

func (*Manager) Reload

func (m *Manager) Reload()

func (*Manager) ReloadContext

func (m *Manager) ReloadContext(ctx context.Context)

type Rule added in v0.1.4

type Rule struct {
	PType string `gorm:"column:ptype"`
	V0    string `gorm:"column:v0"`
	V1    string `gorm:"column:v1"`
	V2    string `gorm:"column:v2"`
	V3    string `gorm:"column:v3"`
	V4    string `gorm:"column:v4"`
	V5    string `gorm:"column:v5"`
}

func ListPolicyRules added in v0.1.4

func ListPolicyRules(ctx context.Context, db *gorm.DB, filter RuleFilter) ([]Rule, error)

func (Rule) TableName added in v0.1.4

func (Rule) TableName() string

type RuleFilter added in v0.1.4

type RuleFilter struct {
	PType    string
	V0       string
	V0In     []string
	V1       string
	V1Prefix string
	V2       string
	V3       string
	V4       string
	V5       string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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