<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Model存儲 與 policy 不同,model 只能加載,不能保存。 因為我們認為 model 不是動態組件,不應該在運行時進行修改,所以我們沒有實現一個 API 來將 model 保存到存儲中。 但是,好消息是,我們提供了三種等效的方法來靜態或動態地加載模型: ## 從 .CONF 文件中加載 model 當你向 Casbin 團隊尋求幫助時,他們會給你這個 Casbin 最常用的方法,此方法對于初學者來說很容易理解并且便于分享。 `.CONF`文件的內容[examples/rbac\_model.conf](https://github.com/casbin/casbin/blob/master/examples/rbac_model.conf): ~~~ini [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 ~~~ 接著你可以加載模型文件如下: ~~~go e := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv") ~~~ ## 從代碼加載 model 模型可以從代碼中動態初始化,不需要使用`.CONF`。下面是RBAC模型的一個例子: ~~~go // Initialize the model from Go code. m := model.NewModel() m.AddDef("r", "r", "sub, obj, act") m.AddDef("p", "p", "sub, obj, act") m.AddDef("g", "g", "_, _") m.AddDef("e", "e", "some(where (p.eft == allow))") m.AddDef("m", "m", "g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act") // Load the policy rules from the .CSV file adapter. // 使用自己的 adapter 替換。 a := persist.NewFileAdapter("examples/rbac_policy.csv") // 創建一個 enforcer。 e := casbin.NewEnforcer(m, a) ~~~ ## 從字符串加載的 model 或者您可以從多行字符串加載整個模型文本。這種方法的優點是您不需要維護模型文件。 ~~~go // Initialize the model from a string. text := ` [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 ` m := NewModel(text) // Load the policy rules from the .CSV file adapter. // Replace it with your adapter to avoid files. a := persist.NewFileAdapter("examples/rbac_policy.csv") // Create the enforcer. e := casbin.NewEnforcer(m, a) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看