Documentation
¶
Index ¶
- func ConditionsToGormQuery(db *gorm.DB, conditions []string, combineType CombineType) *gorm.DB
- func TurnOffAutoMigrate(db *gorm.DB)
- type Adapter
- func NewAdapter(driverName string, dataSourceName string, params ...interface{}) (*Adapter, error)
- func NewAdapterByDB(db *gorm.DB) (*Adapter, error)
- func NewAdapterByDBUseTableName(db *gorm.DB, prefix string, tableName string) (*Adapter, error)
- func NewAdapterByDBWithCustomTable(db *gorm.DB, t interface{}, tableName ...string) (*Adapter, error)
- func NewAdapterByMulDb(dbPool DbPool, dbName string, prefix string, tableName string) (*Adapter, error)
- func NewFilteredAdapter(driverName string, dataSourceName string, params ...interface{}) (*Adapter, error)
- func NewFilteredAdapterByDB(db *gorm.DB, prefix string, tableName string) (*Adapter, error)
- func NewTransactionalAdapter(driverName string, dataSourceName string, params ...interface{}) (*Adapter, error)
- func NewTransactionalAdapterByDB(db *gorm.DB) (*Adapter, error)
- func (a *Adapter) AddLogger(l logger.Interface)
- func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error
- func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error
- func (a *Adapter) AddPolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error
- func (a *Adapter) BeginTransaction(ctx context.Context) (persist.TransactionContext, error)
- func (a *Adapter) Close() error
- func (a *Adapter) Copy() *Adapter
- func (a *Adapter) GetDb() *gorm.DB
- func (a *Adapter) IsFiltered() bool
- func (a *Adapter) LoadFilteredPolicy(model model.Model, filter interface{}) error
- func (a *Adapter) LoadPolicy(model model.Model) error
- func (a *Adapter) LoadPolicyCtx(ctx context.Context, model model.Model) error
- func (a *Adapter) Open() error
- func (a *Adapter) Preview(rules *[]CasbinRule, model model.Model) error
- func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
- func (a *Adapter) RemoveFilteredPolicyCtx(ctx context.Context, sec string, ptype string, fieldIndex int, ...) error
- func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) error
- func (a *Adapter) RemovePoliciesCtx(ctx context.Context, sec string, ptype string, rules [][]string) error
- func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error
- func (a *Adapter) RemovePolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error
- func (a *Adapter) SavePolicy(model model.Model) error
- func (a *Adapter) SavePolicyCtx(ctx context.Context, model model.Model) error
- func (a *Adapter) Transaction(e casbin.IEnforcer, fc func(casbin.IEnforcer) error, opts ...*sql.TxOptions) error
- func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [][]string, fieldIndex int, ...) ([][]string, error)
- func (a *Adapter) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error
- func (a *Adapter) UpdatePolicy(sec string, ptype string, oldRule, newPolicy []string) error
- type BatchFilter
- type CasbinRule
- type CombineType
- type DbPool
- type Filter
- type GormTransactionContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConditionsToGormQuery ¶ added in v3.17.0
ConditionsToGormQuery is a function that converts multiple query conditions into a GORM query statement You can use the GetAllowedObjectConditions() API of Casbin to get conditions, and choose the way of combining conditions through combineType.
func TurnOffAutoMigrate ¶ added in v3.7.1
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter represents the Gorm adapter for policy storage.
func NewAdapter ¶
NewAdapter is the constructor for Adapter. Params : databaseName,tableName,dbSpecified
databaseName,{tableName/dbSpecified}
{database/dbSpecified}
databaseName and tableName are user defined. Their default value are "casbin" and "casbin_rule"
dbSpecified is an optional bool parameter. The default value is false. It's up to whether you have specified an existing DB in dataSourceName. If dbSpecified == true, you need to make sure the DB in dataSourceName exists. If dbSpecified == false, the adapter will automatically create a DB named databaseName.
func NewAdapterByDB ¶
NewAdapterByDB creates gorm-adapter by an existing Gorm instance
func NewAdapterByDBUseTableName ¶ added in v3.0.3
NewAdapterByDBUseTableName creates gorm-adapter by an existing Gorm instance and the specified table prefix and table name Example: gormadapter.NewAdapterByDBUseTableName(&db, "cms", "casbin") Automatically generate table name like this "cms_casbin"
func NewAdapterByDBWithCustomTable ¶ added in v3.2.0
func NewAdapterByMulDb ¶ added in v3.3.0
func NewFilteredAdapter ¶ added in v3.0.5
func NewFilteredAdapter(driverName string, dataSourceName string, params ...interface{}) (*Adapter, error)
NewFilteredAdapter is the constructor for FilteredAdapter. Casbin will not automatically call LoadPolicy() for a filtered adapter.
func NewFilteredAdapterByDB ¶ added in v3.13.0
NewFilteredAdapterByDB is the constructor for FilteredAdapter. Casbin will not automatically call LoadPolicy() for a filtered adapter.
func NewTransactionalAdapter ¶ added in v3.37.0
func NewTransactionalAdapter(driverName string, dataSourceName string, params ...interface{}) (*Adapter, error)
NewTransactionalAdapter creates a new adapter that supports the new transaction interface. This is an alias for NewAdapter for clarity when using with TransactionalEnforcer.
func NewTransactionalAdapterByDB ¶ added in v3.37.0
NewTransactionalAdapterByDB creates a new adapter by existing DB that supports the new transaction interface. This is an alias for NewAdapterByDB for clarity when using with TransactionalEnforcer.
func (*Adapter) AddPolicies ¶
AddPolicies adds multiple policy rules to the storage.
func (*Adapter) AddPolicyCtx ¶ added in v3.24.0
AddPolicyCtx adds a policy rule to the storage.
func (*Adapter) BeginTransaction ¶ added in v3.37.0
BeginTransaction implements TransactionalAdapter interface. It starts a new database transaction and returns a TransactionContext.
func (*Adapter) IsFiltered ¶
IsFiltered returns true if the loaded policy has been filtered.
func (*Adapter) LoadFilteredPolicy ¶
LoadFilteredPolicy loads only policy rules that match the filter.
func (*Adapter) LoadPolicy ¶
LoadPolicy loads policy from database.
func (*Adapter) LoadPolicyCtx ¶ added in v3.24.0
LoadPolicyCtx loads policy from database.
func (*Adapter) Preview ¶ added in v3.11.0
func (a *Adapter) Preview(rules *[]CasbinRule, model model.Model) error
Preview Pre-checking to avoid causing partial load success and partial failure deep
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.
func (*Adapter) RemoveFilteredPolicyCtx ¶ added in v3.24.0
func (a *Adapter) RemoveFilteredPolicyCtx(ctx context.Context, sec string, ptype string, fieldIndex int, fieldValues ...string) error
RemoveFilteredPolicyCtx removes policy rules that match the filter from the storage.
func (*Adapter) RemovePolicies ¶
RemovePolicies removes multiple policy rules from the storage.
func (*Adapter) RemovePoliciesCtx ¶ added in v3.24.0
func (a *Adapter) RemovePoliciesCtx(ctx context.Context, sec string, ptype string, rules [][]string) error
RemovePoliciesCtx removes multiple policy rules from the storage.
func (*Adapter) RemovePolicy ¶
RemovePolicy removes a policy rule from the storage.
func (*Adapter) RemovePolicyCtx ¶ added in v3.24.0
func (a *Adapter) RemovePolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error
RemovePolicyCtx removes a policy rule from the storage.
func (*Adapter) SavePolicy ¶
SavePolicy saves policy to database.
func (*Adapter) SavePolicyCtx ¶ added in v3.24.0
SavePolicyCtx saves policy to database.
func (*Adapter) Transaction ¶ added in v3.10.0
func (a *Adapter) Transaction(e casbin.IEnforcer, fc func(casbin.IEnforcer) error, opts ...*sql.TxOptions) error
Transaction perform a set of operations within a transaction.
func (*Adapter) UpdateFilteredPolicies ¶ added in v3.2.9
func (*Adapter) UpdatePolicies ¶ added in v3.2.5
type BatchFilter ¶ added in v3.8.0
type BatchFilter struct {
// contains filtered or unexported fields
}
type CasbinRule ¶
type CasbinRule struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Ptype string `gorm:"size:100"`
V0 string `gorm:"size:100"`
V1 string `gorm:"size:100"`
V2 string `gorm:"size:100"`
V3 string `gorm:"size:100"`
V4 string `gorm:"size:100"`
V5 string `gorm:"size:100"`
}
func (CasbinRule) TableName ¶
func (CasbinRule) TableName() string
type CombineType ¶ added in v3.17.0
type CombineType uint32
CombineType represents different types of condition combining strategies
const ( CombineTypeOr CombineType = iota // Combine conditions with OR operator CombineTypeAnd // Combine conditions with AND operator )
type DbPool ¶ added in v3.3.0
type DbPool struct {
// contains filtered or unexported fields
}
func InitDbResolver ¶ added in v3.3.0
InitDbResolver multiple databases support Example usage: dbPool,err := InitDbResolver([]gorm.Dialector{mysql.Open(dsn),mysql.Open(dsn2)},[]string{"casbin1","casbin2"}) a := initAdapterWithGormInstanceByMulDb(t,dbPool,"casbin1","","casbin_rule1") a = initAdapterWithGormInstanceByMulDb(t,dbPool,"casbin2","","casbin_rule2")/*
type GormTransactionContext ¶ added in v3.37.0
type GormTransactionContext struct {
// contains filtered or unexported fields
}
GormTransactionContext implements persist.TransactionContext interface. It provides transaction control methods and returns a transaction-aware adapter.
func (*GormTransactionContext) Commit ¶ added in v3.37.0
func (gtx *GormTransactionContext) Commit() error
Commit commits the database transaction.
func (*GormTransactionContext) GetAdapter ¶ added in v3.37.0
func (gtx *GormTransactionContext) GetAdapter() persist.Adapter
GetAdapter returns an adapter that operates within this transaction. All policy operations through this adapter will be part of the transaction.
func (*GormTransactionContext) Rollback ¶ added in v3.37.0
func (gtx *GormTransactionContext) Rollback() error
Rollback rolls back the database transaction.