{"id":36491396,"url":"https://github.com/codyi/grabc","last_synced_at":"2026-01-12T01:56:12.230Z","repository":{"id":57483475,"uuid":"112438540","full_name":"codyi/grabc","owner":"codyi","description":"beego框架的RABC插件，包括路由、权限、角色、授权、菜单管理的功能","archived":false,"fork":false,"pushed_at":"2018-01-22T08:49:38.000Z","size":162,"stargazers_count":80,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-19T01:46:30.048Z","etag":null,"topics":["beego","go","rabc"],"latest_commit_sha":null,"homepage":"http://grabc.liguosong.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-29T06:53:55.000Z","updated_at":"2024-05-21T07:36:11.000Z","dependencies_parsed_at":"2022-08-27T20:02:57.878Z","dependency_job_id":null,"html_url":"https://github.com/codyi/grabc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codyi/grabc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyi%2Fgrabc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyi%2Fgrabc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyi%2Fgrabc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyi%2Fgrabc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codyi","download_url":"https://codeload.github.com/codyi/grabc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codyi%2Fgrabc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"ssl_error","status_checked_at":"2026-01-12T00:36:15.229Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["beego","go","rabc"],"created_at":"2026-01-12T01:56:12.161Z","updated_at":"2026-01-12T01:56:12.224Z","avatar_url":"https://github.com/codyi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## GRABC \n[![GitHub forks](https://img.shields.io/github/forks/codyi/grabc.svg?style=social\u0026label=Forks)](https://github.com/codyi/grabc/network)\n[![GitHub stars](https://img.shields.io/github/stars/codyi/grabc.svg?style=social\u0026label=Starss)](https://github.com/codyi/grabc/stargazers)\n[![GitHub last commit](https://img.shields.io/github/last-commit/codyi/grabc.svg)](https://github.com/codyi/grabc)\n[![Go Report Card](https://goreportcard.com/badge/github.com/codyi/grabc)](https://goreportcard.com/report/github.com/codyi/grabc)  \n\nGRABC 是一个beego权限管理插件，插件分为路由、权限、角色。将路由分配给权限，权限授给角色，角色授给用户~~\nGRABC 目前依赖的前端是adminlte和boostrap\n更详细的文档见：grabc.liguosong.com\n示例地址：http://grabc.demo.liguosong.com/site/login\n### 安装\n    go get github.com/codyi/grabc\n\n### 配置    \n第一步：在你项目中的数据库中导入rabc.sql，生成对应数据表\n\n第二步：在项目中引入grabc库（可以在项目中的main.go或router.go中引入）\n\n\u003cpre\u003e\nimport \"github.com/codyi/grabc\"\n\u003c/pre\u003e\n\n引入之后，在引入的router.go或main.go中添加如下配置\n\u003cpre\u003e\nfunc init() {\n\tvar c []beego.ControllerInterface\n\tc = append(c, \u0026controllers.SiteController{}, \u0026controllers.UserController{})\n\tbeego.Router(\"/\", \u0026controllers.SiteController{})\n\tfor _, v := range c {\n\t\t//将路由注册到beego\n\t\tbeego.AutoRouter(v)\n\t\t//将路由注册到grabc\n\t\tgrabc.RegisterController(v)\n\t}\n\t//注册用户系统模型到grabc\n\tgrabc.RegisterUserModel(\u0026models.User{})\n\t//增加忽律权限检查的页面\n\tgrabc.AppendIgnoreRoute(\"site\", \"login\")\n\n\t//设置grabc页面视图路径\n\t//如果使用默认的，不要设置或置空\n\t//如果需要对grabc插件进行二次开发，则需要设置这个目录，否则不需要管\n\t//注意：设置grabc的模板必须在beego.Run()之前设置，如果视图目录在当前项目中，可以使用相对目录，否则需要绝对路径\n\t// grabc.SetViewPath(\"views\")\n\t//设置grabc的layout\n\tgrabc.SetLayout(\"layout/main.html\", \"views\")\n\n\t//注册获取当前登录用户ID的函数\n\tgrabc.RegisterUserIdFunc(func(c *beego.Controller) int {\n\t\tsessionUId := c.GetSession(\"login_user_id\")\n\n\t\tif sessionUId != nil {\n\t\t\tuser := models.User{}\n\t\t\tuser.FindById(sessionUId.(int))\n\t\t\treturn user.Id\n\t\t}\n\n\t\treturn 0\n\t})\n}\n\u003c/pre\u003e\n\n添加好上面的配置之后，剩下就是在controller中增加权限判了，个人建议做一个BaseController，然后每个controller都继承这个base，然后在BaseController中的Prepare方法中增加grabc的权限检查~~\n\u003cpre\u003e\n//注册当前请求的beego.Controller\ngrabc.SetBeegoController(\u0026this.Controller)\n//检查权限\nif !grabc.CheckAccess(this.controllerName, this.actionName) {\n\tthis.redirect(this.URLFor(\"SiteController.NoPermission\"))\n}\n\u003c/pre\u003e\n\n到此grabc的功能都加完了，是不是很简单~~~\n\n注意：增加完权限判断之后，会发现很多页面都不能访问了，那么就在忽律权限中增加如下配置\n\u003cpre\u003e\ngrabc.AppendIgnoreRoute(\"\\*\", \"\\*\")\n\u003c/pre\u003e\n以上配置将会忽律所有的权限检查，这时候需要去/route/index中增加路由，然后添加权限，角色和用户分配，都配置好之后，就可以将grabc.AppendIgnoreRoute(\"\\*\", \"\\*\")代码删掉，然后重启项目~~权限起作用了\n\n### 接口说明    \nIUserModel接口\n\u003cpre\u003e\n//用于定义用户model\ntype IUserModel interface {\n\t//用户列表返回可用用户的id和姓名\n\t//参数：pageIndex 分页的页数\n\t//参数：pageCount 每页显示的用户数量\n\t//返回值：userList [用户ID]用户姓名，用户列表展示\n\t//返回值：totalNum 全部的用户数目，用于计算分页的数量\n\t//返回值：err\n\tUserList(pageIndex, pageCount int) (userList map[int]string, totalNum int, err error)\n\t//根据用户ID获取用户姓名\n\tFindNameById(id int) string \n}\n\u003c/pre\u003e\n\n### 注意\ngrabc对注册的控制器会进行反射，然后获取每个controller的名称和controller内的公共方法，由于每个controller都继承了beego.Controller，在获取controller下的方法名称时，会将beego.Controller继承的方法也会获取到，所以目前还不能区分出方法名到底是beego和用户自己定义的，所以grabc将beego继承的方法都进行了忽律，如果在route扫描中，没有找到自定义的方法，可以在controller中增加如下方法，进行方法返回~~\n\u003cpre\u003e\nfunc (this *SiteController) RABCMethods() []string {\n\treturn []string{\"Get\", \"Post\"}\n}\n\u003c/pre\u003e\n\ngrabc的详细例子：github.com/codyi/grabc_example\n\n![Image text](http://www.liguosong.com/grabc_1.jpeg)\n![Image text](http://www.liguosong.com/grabc_2.jpeg)\n![Image text](http://www.liguosong.com/grabc_3.jpeg)\n![Image text](http://www.liguosong.com/grabc_4.jpeg)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodyi%2Fgrabc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodyi%2Fgrabc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodyi%2Fgrabc/lists"}