Model Storage
Casbin models are designed to be loaded rather than saved. The model defines your access control logic and should remain static at runtime, so Casbin does not provide an API for persisting model changes to storage.
You can load a model using any of these three approaches:
从.CONF文件加载模型
Loading from a configuration file is the standard approach. This method makes models easy to understand and share when seeking help from the Casbin community.
Here's an example model file examples/rbac_model.conf:
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
Load this model file:
e := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")