{"id":13425399,"url":"https://github.com/zpatrick/rbac","last_synced_at":"2026-01-17T15:36:23.940Z","repository":{"id":57480199,"uuid":"143220850","full_name":"zpatrick/rbac","owner":"zpatrick","description":"Minimalistic RBAC package for Go applications","archived":false,"fork":false,"pushed_at":"2018-08-29T19:03:47.000Z","size":52,"stargazers_count":115,"open_issues_count":0,"forks_count":24,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-13T16:07:12.734Z","etag":null,"topics":["go","golang","rbac","uac"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zpatrick.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":"2018-08-02T00:11:04.000Z","updated_at":"2025-04-13T06:56:44.000Z","dependencies_parsed_at":"2022-09-26T17:41:38.038Z","dependency_job_id":null,"html_url":"https://github.com/zpatrick/rbac","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zpatrick/rbac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zpatrick","download_url":"https://codeload.github.com/zpatrick/rbac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frbac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28511695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: 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":["go","golang","rbac","uac"],"created_at":"2024-07-31T00:01:11.593Z","updated_at":"2026-01-17T15:36:23.932Z","avatar_url":"https://github.com/zpatrick.png","language":"Go","funding_links":[],"categories":["Authentication and OAuth","身份验证和OAuth","认证和OAuth授权","Go","Uncategorized"],"sub_categories":["Contents"],"readme":"# RBAC\n\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/zpatrick/rbac/blob/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zpatrick/rbac)](https://goreportcard.com/report/github.com/zpatrick/rbac)\n[![Go Doc](https://godoc.org/github.com/zpatrick/rbac?status.svg)](https://godoc.org/github.com/zpatrick/rbac)\n\n## Overview\nRBAC is a package that makes it easy to implement Role Based Access Control (RBAC) models in Go applications. \n\n## Download\nTo download this package, run:\n```\ngo get github.com/zpatrick/rbac\n```\n\n## Getting Started\nThis section will go over some of the basic concepts and an example of how to use `rbac` in an application.\nFor more advanced usage, please see the [examples](/examples) directory. \n\n\n* **Action**: An action is a string that represents some desired operation. \nActions are typically expressed as a verb or a verb-object combination, but it is ultimately up to the user how actions are expressed. \nSome examples are: `\"Upvote\"`, `\"ReadArticle\"`, or `\"EditComment\"`. \n* **Target**: A target is a string that represents what the action is trying to operate on. \nTargets are typically expressed as an object's unique identifier, but it is ultimately up to the user how targets are expressed. \nAn example is passing an `articleID` as the target for a `\"ReadArticle\"` action. \nNot all actions require a target. \n* **Matcher**: A [matcher](https://godoc.org/github.com/zpatrick/rbac#Matcher) is a function that returns a bool representing whether or not the target matches some pre-defined pattern.\nThis repo comes with some builtin matchers: \n[GlobMatch](https://godoc.org/github.com/zpatrick/rbac#GlobMatch), \n[RegexMatch](https://godoc.org/github.com/zpatrick/rbac#RegexMatch), \nand [StringMatch](https://godoc.org/github.com/zpatrick/rbac#StringMatch). \nPlease see the [complex blog](/examples/blog_complex) example to see how one can implement custom matchers for their applications. \n* **Permission**: A [permission](https://godoc.org/github.com/zpatrick/rbac#Permission) is a function that takes an action and a target, and returns true if and only if the action is allowed on the target. \nA permission should always allow (as opposed to deny) action(s) to be made on target(s), since nothing is allowed by default. \n* **Role**: A [role](https://godoc.org/github.com/zpatrick/rbac#Role) is essentially a grouping of permissions. \nThe [`role.Can`](https://godoc.org/github.com/zpatrick/rbac#Role.Can) function should be used to determine whether or not a role can do an action on a target. \nA role is only allowed to do something if it has at least one permission that allows it. \n\n## Usage\n```go\npackage main\n\nimport (\n        \"fmt\"\n\n        \"github.com/zpatrick/rbac\"\n)\n\nfunc main() {\n        roles := []rbac.Role{\n                {\n                        RoleID: \"Adult\",\n                        Permissions: []rbac.Permission{\n                                rbac.NewGlobPermission(\"watch\", \"*\"),\n                        },\n                },\n                {\n                        RoleID: \"Teenager\",\n                        Permissions: []rbac.Permission{\n                                rbac.NewGlobPermission(\"watch\", \"pg-13\"),\n                                rbac.NewGlobPermission(\"watch\", \"g\"),\n                        },\n                },\n                {\n                        RoleID: \"Child\",\n                        Permissions: []rbac.Permission{\n                                rbac.NewGlobPermission(\"watch\", \"g\"),\n                        },\n                },\n        }\n\n        for _, role := range roles {\n                fmt.Println(\"Role:\", role.RoleID)\n                for _, rating := range []string{\"g\", \"pg-13\", \"r\"} {\n                        canWatch, _ := role.Can(\"watch\", rating)\n                        fmt.Printf(\"Can watch %s? %t\\n\", rating, canWatch)\n                }\n        }\n}\n\n```\n\nOutput:\n```console\nRole: Adult\nCan watch g? true\nCan watch pg-13? true\nCan watch r? true\nRole: Teenager\nCan watch g? true\nCan watch pg-13? true\nCan watch r? false\nRole: Child\nCan watch g? true\nCan watch pg-13? false\nCan watch r? false\n```\n\n## License\nThis work is published under the MIT license.\n\nPlease see the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpatrick%2Frbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzpatrick%2Frbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpatrick%2Frbac/lists"}