gorm

package
v1.0.1005 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// 默认适配器
	adapter.Adapter
	// contains filtered or unexported fields
}

*

  • gorm 适配器 *
  • rbac_model.conf 中 matchers 内置可用函数:
  • keyMatch [匹配*号], keyMatch2 [匹配 :file]
  • regexMatch [正则匹配], ipMatch [IP地址或者CIDR匹配] *
  • @create 2021-9-8
  • @author deatil

func New

func New(db *gorm.DB, rule ...*Rules) (*Adapter, error)

自定义模型

func (*Adapter) AddPolicies

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

AddPolicies adds multiple policy rules to the storage.

func (*Adapter) AddPolicy

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

AddPolicy adds a policy rule to the storage.

func (*Adapter) Close

func (this *Adapter) Close() error

关闭

func (*Adapter) IsFiltered

func (this *Adapter) IsFiltered() bool

IsFiltered returns true if the loaded policy has been filtered.

func (*Adapter) LoadFilteredPolicy

func (this *Adapter) LoadFilteredPolicy(model model.Model, filter any) error

LoadFilteredPolicy loads only policy rules that match the filter.

func (*Adapter) LoadPolicy

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

LoadPolicy loads policy from database.

func (*Adapter) RemoveFilteredPolicy

func (this *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

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

func (*Adapter) RemovePolicies

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

RemovePolicies removes multiple policy rules from the storage.

func (*Adapter) RemovePolicy

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

RemovePolicy removes a policy rule from the storage.

func (*Adapter) SavePolicy

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

SavePolicy saves policy to database.

func (*Adapter) UpdatePolicy

func (this *Adapter) UpdatePolicy(sec string, ptype string, oldRule, newPolicy []string) error

UpdatePolicy updates a new policy rule to DB.

func (*Adapter) WithModel

func (this *Adapter) WithModel(model *Rules) *Adapter

默认模型

type Filter

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

过滤

type Rules

type Rules struct {
	ID    string `gorm:"primaryKey;autoIncrement:false;size:36"`
	Ptype string `gorm:"size:250;"`
	V0    string `gorm:"size:250;"`
	V1    string `gorm:"size:250;"`
	V2    string `gorm:"size:250;"`
	V3    string `gorm:"size:250;"`
	V4    string `gorm:"size:250;"`
	V5    string `gorm:"size:250;"`
}

规则模型

func (*Rules) BeforeCreate

func (this *Rules) BeforeCreate(db *gorm.DB) error

Jump to

Keyboard shortcuts

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