gdbadapter

package module
v0.0.0-...-ee40d63 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

gdb adapter Build Status Coverage Status Godoc

GF ORM adapter for Casbin.

Based on GF ORM, and tested in:

  • MySQL
  • PostgreSQL

基于 vance-liu/gdb-adapter

Installation

go get github.com/flipped-aurora/gdb-adapter

Usage example

db, err = gdb.New("casbin")
if err != nil{
	panic(err)
}
a := NewAdapterByDB(db)
e := casbin.NewEnforcer("examples/rbac_model.conf", a)

Notice

  • you should create the database on your own.

  • Not tested, please do not use in production environment.

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

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter represents the gdb adapter for policy storage. Adapter 代表用于策略存储的gdb适配器。

func NewAdapter

func NewAdapter(driverName string, dataSourceName string) (*Adapter, error)

NewAdapter是Adapter的构造函数。 dbSpecified是可选的bool参数。 默认值为false。 如果dbSpecified == true,则需要确保dataSourceName中的数据库存在。 如果dbSpecified == false,则适配器将自动创建一个名为“ casbin”的数据库。

func NewAdapterByDB

func NewAdapterByDB(db gdb.DB, dbName string) (*Adapter, error)

NewAdapterByDB is the constructor for Adapter.Need to pass in gdb.DB NewAdapterByDB 是Adapter的构造函数,需要传入gdb.DB

func NewAdapterFromOptions

func NewAdapterFromOptions(adapter *Adapter) (*Adapter, error)

NewAdapterFromOptions is the constructor for Adapter with existed connection NewAdapterFromOptions 适配器的构造函数是否具有已存在的连接

func (*Adapter) AddPolicy

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

AddPolicy adds a policy rule to the storage. AddPolicy 向存储添加策略规则。

func (*Adapter) LoadPolicy

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

LoadPolicy loads policy from database. LoadPolicy 从数据库加载策略。

func (*Adapter) RemoveFilteredPolicy

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

RemoveFilteredPolicy removes policy rules that match the filter from the storage. RemoveFilteredPolicy 从存储中删除与筛选器匹配的策略规则。

func (*Adapter) RemovePolicy

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

RemovePolicy removes a policy rule from the storage. RemovePolicy 从存储中删除策略规则。

func (*Adapter) SavePolicy

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

SavePolicy saves policy to database. SavePolicy 将策略保存到数据库。

type CasbinRule

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

Jump to

Keyboard shortcuts

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