forked from bullteam/zeus-admin
/
adapter.go
38 lines (33 loc) · 1.24 KB
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package adapter
import (
"github.com/casbin/casbin/model"
"github.com/CMLiang/zeus-admin/pkg/api/domain/perm/adapter/mysql"
)
type Adapter interface {
LoadPolicy(model model.Model) error
SavePolicy(model model.Model) error
AddPolicy(sec string, ptype string, rule []string) error
RemovePolicy(sec string, ptype string, rule []string) error
RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
}
// NewMysqlAdapter : delegate of adapter
func NewMysqlAdapter() *mysqlAdapter {
ad := &mysqlAdapter{
a: mysql.NewGormAdapter(),
}
return ad
}
type mysqlAdapter struct {
a Adapter
}
func (ca *mysqlAdapter) LoadPolicy(model model.Model) error { return ca.a.LoadPolicy(model) }
func (ca *mysqlAdapter) SavePolicy(model model.Model) error { return ca.a.SavePolicy(model) }
func (ca *mysqlAdapter) AddPolicy(sec string, ptype string, rule []string) error {
return ca.a.AddPolicy(sec, ptype, rule)
}
func (ca *mysqlAdapter) RemovePolicy(sec string, ptype string, rule []string) error {
return ca.a.RemovePolicy(sec, ptype, rule)
}
func (ca *mysqlAdapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
return ca.a.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...)
}