{"id":19298250,"url":"https://github.com/casbin/casbin-raft","last_synced_at":"2026-03-03T22:33:07.923Z","repository":{"id":55941266,"uuid":"277861018","full_name":"casbin/casbin-raft","owner":"casbin","description":"Etcd Raft Dispatcher for Casbin","archived":false,"fork":false,"pushed_at":"2020-12-04T10:40:50.000Z","size":61,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-13T00:27:58.215Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/casbin/casbin","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-07T15:57:32.000Z","updated_at":"2024-08-30T16:25:39.000Z","dependencies_parsed_at":"2022-08-15T10:00:30.651Z","dependency_job_id":null,"html_url":"https://github.com/casbin/casbin-raft","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/casbin/casbin-raft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fcasbin-raft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fcasbin-raft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fcasbin-raft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fcasbin-raft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casbin","download_url":"https://codeload.github.com/casbin/casbin-raft/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fcasbin-raft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30064365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:07:23.542Z","updated_at":"2026-03-03T22:33:07.901Z","avatar_url":"https://github.com/casbin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# casbin-raft\n\ncasbin-raft is the `Dispatcher` for Casbin. Provide a way to synchronize incremental changes of policy based on etcd/raft. With this library, Casbin can ensure the consistency of multiple Casbin instances in distributed situations.\n\n## Installation\n\n```\n    go get -u github.com/casbin/casbin-raft\n```\nOnly casbin v3 supports the use of dispatcher, so you need to use the code of the beta branch\n\n```\n    go get -u github.com/casbin/casbin/v3@beta\n```\n\n## Simple Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/casbin/casbin/v3\"\n\tcasbinraft \"github.com/casbin/casbin-raft\"\n)\n\nfunc main() {\n    // Must guarantee that the initial state of all instances is the same, \n    e, _ := casbin.NewSyncedEnforcer(\"examples/basic_model.conf\", \"examples/basic_policy.csv\")\n\n    // Need to provide the ID and URL of all nodes in the cluster. \n    peers := make(map[uint64]string)\n    peers[1] = \"127.0.0.1:8001\"\n    peers[2] = \"127.0.0.1:8002\"\n    d := casbinraft.NewDispathcer(1, peers)\n\n    e.SetDispathcer(d)\n    e.EnableautoNotifyDispatcher(true)\n\n    go d.Start()\n\n    // Then you can continue to use the enforcer normally, and when the policy changes, dispathcer will automatically synchronize all clusters\n    e.AddPolicy(\"alice\", \"data2\", \"read\")\n}\n```\n\n### Dynamic Membership\n\ncasbin-raft supports dynamically adding/removing nodes while runtime, for the new node, you need set the param `join` to true.\n```go\n    // peers should also contain all nodes info, although this is not needed by raft, it will be used for tranport between nodes\n    peers := make(map[uint64]string)\n    peers[1] = \"http://127.0.0.1:8001\"\n    peers[2] = \"http://127.0.0.1:8002\"\n    peers[3] = \"http://127.0.0.1:8003\"\n    peers[4] = \"http://127.0.0.1:8004\"\n    e, err := casbin.NewEnforcer(\"examples/basic_model.conf\", \"examples/basic_policy.csv\")\n    if err != nil {\n        t.Fatal(err)\n    }\n\n    d := casbinraft.NewDispatcher(4, peers, true)\n    _ = e.SetDispatcher(d)\n    e.EnableautoNotifyDispatcher(true)\n    \n    go d.Start()\n```\n\nfor the existing cluster, you can call `AddMember` on any node\n```\n    d.AddMember(4, \"http://127.0.0.1:8004\")\n```\n\nIf you need to remove the node, you can call `RemoveMember` on any node\n```\n    d.RemoveMember(3)\n```\n\n## Getting Help\n\n- [Casbin](https://github.com/casbin/casbin)\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Fcasbin-raft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasbin%2Fcasbin-raft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Fcasbin-raft/lists"}