upperadapter

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToInterfaceSlice

func ToInterfaceSlice[T interface{}](slice []T) []interface{}

Types

type Adapter

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

Adapter define the sqlx upper-adapter for Casbin. It can load policy lines or save policy lines from sqlx connected database.

func NewAdapter

func NewAdapter(db db.Session, tableName string) (*Adapter, error)

NewAdapter the constructor for Adapter. db should connected to database and controlled by user. If tableName == "", the Adapter will automatically create a table named "casbin_rule".

func NewAdapterContext

func NewAdapterContext(ctx context.Context, db db.Session, tableName string) (*Adapter, error)

NewAdapterContext the constructor for Adapter. db should connected to database and controlled by user. If tableName == "", the Adapter will automatically create a table named "casbin_rule".

func (*Adapter) AddPolicies

func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error

AddPolicies add multiple policy cols to the storage. 实现 persist.BatchAdapter 接口

func (*Adapter) AddPolicy

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

AddPolicy add one policy rule to the storage.

func (*Adapter) IsFiltered

func (a *Adapter) IsFiltered() bool

IsFiltered returns true if the loaded policy cols has been filtered.

func (*Adapter) LoadFilteredPolicy

func (a *Adapter) LoadFilteredPolicy(model model.Model, filter interface{}) error

LoadFilteredPolicy load policy cols that match the filter. filterPtr must be a pointer.

func (*Adapter) LoadPolicy

func (a *Adapter) LoadPolicy(model model.Model) error

LoadPolicy load all policy cols from the storage.

func (*Adapter) RemoveFilteredPolicy

func (a *Adapter) RemoveFilteredPolicy(_ string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy remove policy cols that match the filter from the storage.

func (*Adapter) RemovePolicies

func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) (err error)

RemovePolicies remove policy cols. 实现 persist.BatchAdapter 接口

func (*Adapter) RemovePolicy

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

RemovePolicy remove policy cols from the storage.

func (*Adapter) SavePolicy

func (a *Adapter) SavePolicy(model model.Model) error

SavePolicy save policy cols to the storage.

func (*Adapter) UpdateFilteredPolicies

func (a *Adapter) UpdateFilteredPolicies(sec, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string) (oldPolicies [][]string, err error)

UpdateFilteredPolicies deletes old cols and adds new cols.

func (*Adapter) UpdatePolicies

func (a *Adapter) UpdatePolicies(sec, ptype string, oldRules, newRules [][]string) (err error)

UpdatePolicies updates policy cols to storage.

func (*Adapter) UpdatePolicy

func (a *Adapter) UpdatePolicy(sec, ptype string, oldRule, newRule []string) error

UpdatePolicy update a policy rule from storage. This is part of the Auto-Save feature.

type CasbinRule

type CasbinRule struct {
	PType string `db:"p_type"`
	V0    string `db:"v0"`
	V1    string `db:"v1"`
	V2    string `db:"v2"`
	V3    string `db:"v3"`
	V4    string `db:"v4"`
	V5    string `db:"v5"`
}

CasbinRule defines the casbin rule model. It used for save or load policy lines from sqlx connected database.

type Filter

type Filter struct {
	PType []string
	V0    []string
	V1    []string
	V2    []string
	V3    []string
	V4    []string
	V5    []string
}

Filter defines the filtering cols for a FilteredAdapter's policy. Empty values are ignored, but all others must match the filter.

Jump to

Keyboard shortcuts

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