adapter

package module
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

gf-adapter

GF ORM adapter for Casbin.

Tested in:

  • MySQL

Installation

go get github.com/zcyc/gf-adapter/v2
go mod tidy

Usage example

a, _ := NewAdapter(context.Background(), gdb.DefaultGroupName, "", nil)

Notice

you should create the database on your own.

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Columns = Rule{
		PType: "p_type",
		V0:    "v0",
		V1:    "v1",
		V2:    "v2",
		V3:    "v3",
		V4:    "v4",
		V5:    "v5",
	}
)

Functions

This section is empty.

Types

type Adapter

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

func NewAdapter

func NewAdapter(ctx context.Context, dbGroupName, tableName string, db gdb.DB) (adp *Adapter, err error)

NewAdapter Create a casbin adapter

func (*Adapter) AddPolicies

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

AddPolicies adds policy rules to the storage.

func (*Adapter) AddPolicy

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

AddPolicy adds a policy rule to the storage.

func (*Adapter) IsFiltered added in v2.3.0

func (a *Adapter) IsFiltered() bool

IsFiltered returns true if the loaded policy has been filtered.

func (*Adapter) LoadFilteredPolicy added in v2.3.0

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

LoadFilteredPolicy loads only policy rules that match the filter.

func (*Adapter) LoadPolicy

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

LoadPolicy loads all policy rules from the storage.

func (*Adapter) RemoveFilteredPolicy

func (a *Adapter) RemoveFilteredPolicy(sec string, pType string, fieldIndex int, fieldValues ...string) (err error)

RemoveFilteredPolicy removes policy rules that match the filter from the storage.

func (*Adapter) RemovePolicies

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

RemovePolicies removes policy rules from the storage (implements the persist.BatchAdapter interface).

func (*Adapter) RemovePolicy

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

RemovePolicy removes a policy rule from the storage.

func (*Adapter) SavePolicy

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

SavePolicy Saves all policy rules to the storage.

func (*Adapter) UpdateFilteredPolicies added in v2.3.0

func (a *Adapter) UpdateFilteredPolicies(sec string, pType string, newPolicies [][]string, fieldIndex int, fieldValues ...string) ([][]string, error)

UpdateFilteredPolicies deletes old rules and adds new rules.

func (*Adapter) UpdatePolicies

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

UpdatePolicies updates some policy rules to storage, like db, redis.

func (*Adapter) UpdatePolicy

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

UpdatePolicy updates a policy rule from storage.

type Filter added in v2.3.0

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

type Rule added in v2.3.0

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

Jump to

Keyboard shortcuts

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