├── .gitattributes ├── .gitignore ├── Makefile ├── README.MD ├── api ├── common.go ├── dept │ ├── dept.go │ └── v1 │ │ └── dept.go ├── permission │ ├── permission.go │ └── v1 │ │ └── permission.go ├── public │ ├── public.go │ └── v1 │ │ ├── login.go │ │ └── public.go ├── role │ ├── role.go │ └── v1 │ │ ├── permission.go │ │ └── role.go └── user │ ├── user.go │ └── v1 │ └── user.go ├── go.mod ├── go.sum ├── hack ├── config.yaml ├── hack-cli.mk └── hack.mk ├── internal ├── cmd │ └── cmd.go ├── consts │ └── consts.go ├── controller │ ├── dept │ │ ├── dept.go │ │ ├── dept_new.go │ │ ├── dept_v1_add.go │ │ ├── dept_v1_del.go │ │ ├── dept_v1_get_lst.go │ │ └── dept_v1_upt.go │ ├── permission │ │ ├── permission.go │ │ ├── permission_new.go │ │ ├── permission_v1_add.go │ │ ├── permission_v1_del.go │ │ ├── permission_v1_get_lst.go │ │ ├── permission_v1_get_route_lst.go │ │ ├── permission_v1_upt.go │ │ └── permission_v1_upt_show_link.go │ ├── public │ │ ├── public.go │ │ ├── public_new.go │ │ ├── public_v1_login.go │ │ ├── public_v1_logout.go │ │ ├── public_v1_ping.go │ │ └── public_v1_refresh_token.go │ ├── role │ │ ├── role.go │ │ ├── role_new.go │ │ ├── role_v1_add.go │ │ ├── role_v1_del.go │ │ ├── role_v1_get_lst.go │ │ ├── role_v1_get_page_lst.go │ │ ├── role_v1_upt.go │ │ └── role_v1_upt_permission.go │ └── user │ │ ├── user.go │ │ ├── user_new.go │ │ ├── user_v1_add.go │ │ ├── user_v1_del.go │ │ ├── user_v1_get_page_lst.go │ │ ├── user_v1_upt.go │ │ ├── user_v1_upt_enabled.go │ │ └── user_v1_upt_password.go ├── dao │ ├── .gitkeep │ ├── dept.go │ ├── internal │ │ ├── dept.go │ │ ├── permission.go │ │ ├── role.go │ │ └── user.go │ ├── permission.go │ ├── role.go │ └── user.go ├── logic │ ├── .gitkeep │ ├── context │ │ ├── casbin.go │ │ └── context.go │ ├── dept │ │ └── dept.go │ ├── logic.go │ ├── middleware │ │ └── middleware.go │ ├── permission │ │ ├── permission.go │ │ └── route.go │ ├── role │ │ └── role.go │ └── user │ │ └── user.go ├── model │ ├── .gitkeep │ ├── context.go │ ├── do │ │ ├── .gitkeep │ │ ├── dept.go │ │ ├── permission.go │ │ ├── role.go │ │ └── user.go │ ├── entity │ │ ├── .gitkeep │ │ ├── comb │ │ │ ├── permission.go │ │ │ ├── role.go │ │ │ └── user.go │ │ ├── dept.go │ │ ├── permission.go │ │ ├── role.go │ │ └── user.go │ └── mid │ │ ├── dept.go │ │ ├── permission.go │ │ ├── role.go │ │ └── user.go ├── packed │ └── packed.go └── service │ ├── .gitkeep │ ├── auth.go │ ├── context.go │ ├── dept.go │ ├── middleware.go │ ├── permission.go │ ├── role.go │ └── user.go ├── main.go ├── manifest ├── config │ └── config.yaml ├── db │ └── zze_admin_go.sql ├── deploy │ └── kustomize │ │ ├── base │ │ ├── deployment.yaml │ │ ├── kustomization.yaml │ │ └── service.yaml │ │ └── overlays │ │ └── develop │ │ ├── configmap.yaml │ │ ├── deployment.yaml │ │ └── kustomization.yaml ├── docker │ ├── Dockerfile │ └── docker.sh └── protobuf │ └── .keep-if-necessary ├── resource ├── i18n │ └── .gitkeep ├── imgs │ ├── dept-manage.png │ ├── permission-manage.png │ ├── role-manage.png │ └── user-manage.png ├── public │ ├── html │ │ └── .gitkeep │ ├── plugin │ │ └── .gitkeep │ └── resource │ │ ├── css │ │ └── .gitkeep │ │ ├── image │ │ └── .gitkeep │ │ └── js │ │ └── .gitkeep └── template │ └── .gitkeep ├── tests └── 1_test.go └── utility ├── .gitkeep └── util ├── encrypt.go └── generic.go /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-language=GO -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .hgignore.swp 3 | .project 4 | .orig 5 | .swp 6 | .idea/ 7 | .settings/ 8 | .vscode/ 9 | bin/ 10 | **/.DS_Store 11 | gf 12 | main 13 | main.exe 14 | output/ 15 | manifest/output/ 16 | temp/ 17 | temp.yaml 18 | bin 19 | **/config/config-prod.yaml 20 | dist -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR = $(shell pwd) 2 | NAMESPACE = "default" 3 | DEPLOY_NAME = "zze-admin-go" 4 | DOCKER_NAME = "zze-admin-go" 5 | 6 | include ./hack/hack.mk -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # zze Admin go 2 | 3 | ## 功能 4 | 5 | 本项目主要用来作为新项目启动时的模板,如果你想要使用 Golang 来新开发一个后台管理系统,那么选我就对了。 6 | 7 | - 已实现后台管理系统最基础的用户管理、角色管理、权限管理,基于它来开发可以让你可以更聚焦业务的实现。 8 | - 选用了相对成熟、稳定、功能齐全的的框架,后端基于 **[GoFrame](https://goframe.org/pages/viewpage.action?pageId=1114119)** 9 | ,前端基于 **[PureAdmin](https://yiming_chang.gitee.io/pure-admin-doc/pages/introduction/)**; 10 | - 支持一套权限管理逻辑控制前后端路由、按钮级别权限; 11 | 12 | ## 预览地址 13 | 14 | [点我预览](http://admin.zze.xyz) 15 | > 数据库每小时自动重置,可随意测试。 16 | 17 | - 管理员:`admin`,密码:`devops.zze`; 18 | - 测试账号:`test`,密码:`devops.zze`; 19 | 20 | 21 | 22 | 效果图: 23 | 24 | ![用户管理](https://raw.githubusercontent.com/zze326/zze-admin-go/main/resource/imgs/user-manage.png) 25 | ![角色管理](https://raw.githubusercontent.com/zze326/zze-admin-go/main/resource/imgs/role-manage.png) 26 | ![权限管理](https://raw.githubusercontent.com/zze326/zze-admin-go/main/resource/imgs/permission-manage.png) 27 | ![部门管理](https://raw.githubusercontent.com/zze326/zze-admin-go/main/resource/imgs/dept-manage.png) 28 | 29 | ## 技术栈 30 | 31 | - 语言:Golang、Typescript; 32 | - 后端:GoFrame、Casbin; 33 | - 前端:Vue3、Vite、Element-Plus、TypeScript、Pinia 等; 34 | 35 | ## 项目运行 36 | 1、在 MySQL 中执行 `manifest/db/zze_admin_go.sql` 创建好数据库以及初始化数据; 37 | 38 | 2、然后修改 `manifest/config/config.yaml` 中的数据库连接地址(`database.default.link`),格式如下: 39 | ```sql 40 | mysql:<用户名>:<密码>@tcp(<数据库地址>)/<库名>?loc=Local&parseTime=true 41 | -- 例:mysql:zze:zze.admin@tcp(127.0.0.1:3306)/zze_admin_go?loc=Local&parseTime=true 42 | ``` 43 | 3、直接运行项目根目录的 `main.go` 就可以跑起来啦~ 44 | ## 前端项目 45 | 本仓库是后端项目,对应前端项目地址为:。 -------------------------------------------------------------------------------- /api/common.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/encoding/gjson" 5 | ) 6 | 7 | type PageLstReq struct { 8 | Page int `p:"page" v:"page @integer|min:1#页码必填" dc:"页码"` // 页码 9 | PageSize int `p:"pageSize" v:"pageSize @integer|min:1#每页数量必填" dc:"每页数量"` // 每页数量 10 | Search string `p:"search" dc:"模糊搜索内容"` // 搜索内容 11 | Wheres *gjson.Json `p:"wheres" dc:"搜索条件"` 12 | } 13 | 14 | func (r *PageLstReq) Offset() int { 15 | return (r.Page - 1) * r.PageSize 16 | } 17 | 18 | func (r *PageLstReq) Limit() int { 19 | return r.PageSize 20 | } 21 | 22 | func (r *PageLstReq) SearchStr() string { 23 | return "%" + r.Search + "%" 24 | } 25 | 26 | type PageLstRes[T any] struct { 27 | Total int `json:"total" dc:"总数"` // 总数 28 | List []T `json:"list" dc:"列表"` // 列表 29 | } 30 | -------------------------------------------------------------------------------- /api/dept/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package dept 6 | 7 | import ( 8 | "context" 9 | 10 | "devops-super/api/dept/v1" 11 | ) 12 | 13 | type IDeptV1 interface { 14 | Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) 15 | GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) 16 | Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) 17 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 18 | } 19 | -------------------------------------------------------------------------------- /api/dept/v1/dept.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "devops-super/internal/model/entity" 5 | "devops-super/internal/model/mid" 6 | "github.com/gogf/gf/v2/frame/g" 7 | ) 8 | 9 | type AddReq struct { 10 | g.Meta `path:"/dept" method:"post" tags:"部门" summary:"新增部门"` 11 | *mid.Dept 12 | } 13 | 14 | type AddRes struct{} 15 | 16 | type GetLstReq struct { 17 | g.Meta `path:"/dept/list" method:"get" tags:"部门" summary:"获取部门列表"` 18 | Search string `p:"search"` 19 | } 20 | 21 | type GetLstRes struct { 22 | List []*entity.Dept `json:"list"` 23 | } 24 | 25 | type UptReq struct { 26 | g.Meta `path:"/dept/{id}" method:"put" tags:"部门" summary:"更新部门"` 27 | Id int ` v:"min:1#id必须" path:"id"` 28 | *mid.Dept 29 | } 30 | 31 | type UptRes struct{} 32 | 33 | type DelReq struct { 34 | g.Meta `path:"/dept/{id}" method:"delete" tags:"部门" summary:"删除部门"` 35 | Id int `v:"min:1#id必须" path:"id" ` 36 | } 37 | 38 | type DelRes struct{} 39 | -------------------------------------------------------------------------------- /api/permission/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package permission 6 | 7 | import ( 8 | "context" 9 | 10 | "devops-super/api/permission/v1" 11 | ) 12 | 13 | type IPermissionV1 interface { 14 | Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) 15 | GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) 16 | Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) 17 | UptShowLink(ctx context.Context, req *v1.UptShowLinkReq) (res *v1.UptShowLinkRes, err error) 18 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 19 | GetRouteLst(ctx context.Context, req *v1.GetRouteLstReq) (res *v1.GetRouteLstRes, err error) 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /api/permission/v1/permission.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "devops-super/internal/model/entity" 5 | "devops-super/internal/model/mid" 6 | "github.com/gogf/gf/v2/frame/g" 7 | ) 8 | 9 | type AddReq struct { 10 | g.Meta `path:"/permission" method:"post" tags:"权限" summary:"创建权限"` 11 | *mid.Permission 12 | } 13 | 14 | type AddRes struct{} 15 | 16 | type GetLstReq struct { 17 | g.Meta `path:"/permission/list" method:"get" tags:"权限" summary:"获取权限列表"` 18 | Search string `p:"search"` 19 | } 20 | 21 | type GetLstRes struct { 22 | List []*entity.Permission `json:"list"` 23 | } 24 | 25 | type UptReq struct { 26 | g.Meta `path:"/permission/{id}" method:"put" tags:"权限" summary:"更新权限"` 27 | Id int ` v:"min:1#id必须" path:"id"` 28 | *mid.Permission 29 | } 30 | 31 | type UptRes struct{} 32 | 33 | type UptShowLinkReq struct { 34 | g.Meta `path:"/permission/{id}/show-link" method:"patch" tags:"权限" summary:"更新是否显示在菜单"` 35 | Id int `v:"min:1#id必须" path:"id" ` 36 | Enabled bool `v:"required" json:"enabled"` 37 | } 38 | 39 | type UptShowLinkRes struct{} 40 | 41 | type DelReq struct { 42 | g.Meta `path:"/permission/{id}" method:"delete" tags:"权限" summary:"删除权限"` 43 | Id int `v:"min:1#id必须" path:"id" ` 44 | } 45 | 46 | type DelRes struct{} 47 | 48 | type GetRouteLstReq struct { 49 | g.Meta `path:"/permission/route-list" method:"get" tags:"权限" summary:"获取前端路由列表"` 50 | } 51 | 52 | type GetRouteLstRes struct { 53 | List []*mid.Route `json:"list"` 54 | } 55 | -------------------------------------------------------------------------------- /api/public/public.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package public 6 | 7 | import ( 8 | "context" 9 | 10 | "devops-super/api/public/v1" 11 | ) 12 | 13 | type IPublicV1 interface { 14 | Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) 15 | RefreshToken(ctx context.Context, req *v1.RefreshTokenReq) (res *v1.RefreshTokenRes, err error) 16 | Logout(ctx context.Context, req *v1.LogoutReq) (res *v1.LogoutRes, err error) 17 | Ping(ctx context.Context, req *v1.PingReq) (res *v1.PingRes, err error) 18 | } 19 | -------------------------------------------------------------------------------- /api/public/v1/login.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/gogf/gf/v2/frame/g" 4 | 5 | type LoginReq struct { 6 | g.Meta `path:"/login" tags:"用户" method:"post" summary:"登录"` 7 | Username string `v:"required#请输入用户名" json:"username" dc:"用户名"` 8 | Password string `v:"required#请输入密码" json:"password" dc:"密码"` 9 | } 10 | 11 | type LoginRes struct { 12 | Username string `json:"username"` 13 | RealName string `json:"realName"` 14 | Token string `json:"token"` 15 | Expires int64 `json:"expires"` 16 | RefreshAfter int64 `json:"refreshAfter"` 17 | Roles []string `json:"roles"` 18 | } 19 | 20 | type RefreshTokenReq struct { 21 | g.Meta `path:"/refresh-token" method:"post" tags:"用户" summary:"刷新 Token"` 22 | } 23 | 24 | type RefreshTokenRes struct { 25 | Username string `json:"username"` 26 | RealName string `json:"realName"` 27 | Token string `json:"token"` 28 | Expire int64 `json:"expire"` 29 | RefreshAfter int64 `json:"refreshAfter"` 30 | Roles []string `json:"roles"` 31 | } 32 | 33 | type LogoutReq struct { 34 | g.Meta `path:"/logout" method:"post" tags:"用户" summary:"用户登出"` 35 | } 36 | 37 | type LogoutRes struct{} 38 | -------------------------------------------------------------------------------- /api/public/v1/public.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/gogf/gf/v2/frame/g" 4 | 5 | type PingReq struct { 6 | g.Meta `path:"/ping" method:"get" tags:"健康检查" summary:"ping"` 7 | } 8 | 9 | type PingRes struct{} 10 | -------------------------------------------------------------------------------- /api/role/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package role 6 | 7 | import ( 8 | "context" 9 | 10 | "devops-super/api/role/v1" 11 | ) 12 | 13 | type IRoleV1 interface { 14 | UptPermission(ctx context.Context, req *v1.UptPermissionReq) (res *v1.UptPermissionRes, err error) 15 | GetPageLst(ctx context.Context, req *v1.GetPageLstReq) (res *v1.GetPageLstRes, err error) 16 | Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) 17 | Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) 18 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 19 | GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /api/role/v1/permission.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/encoding/gjson" 5 | "github.com/gogf/gf/v2/frame/g" 6 | ) 7 | 8 | type UptPermissionReq struct { 9 | g.Meta `method:"patch" path:"/role/{id}/permission" summary:"更新角色关联的权限" tags:"角色"` 10 | Id int `v:"min:1#id必须" path:"id"` 11 | PermissionIds *gjson.Json `json:"permissionIds"` 12 | } 13 | 14 | type UptPermissionRes struct{} 15 | -------------------------------------------------------------------------------- /api/role/v1/role.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "devops-super/api" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/model/mid" 7 | "github.com/gogf/gf/v2/frame/g" 8 | ) 9 | 10 | type GetPageLstReq struct { 11 | g.Meta `method:"get" path:"/role/page-list" summary:"分页获取角色列表" tags:"角色"` 12 | *api.PageLstReq 13 | } 14 | 15 | type GetPageLstRes struct { 16 | *api.PageLstRes[*entity.Role] 17 | } 18 | 19 | type AddReq struct { 20 | g.Meta `method:"post" path:"/role" summary:"添加角色" tags:"角色"` 21 | *mid.Role 22 | } 23 | 24 | type AddRes struct{} 25 | 26 | type UptReq struct { 27 | g.Meta `method:"put" path:"/role/{id}" summary:"更新角色" tags:"角色"` 28 | Id int ` v:"min:1#id必须" path:"id"` 29 | *mid.Role 30 | } 31 | 32 | type UptRes struct{} 33 | 34 | type DelReq struct { 35 | g.Meta `method:"delete" path:"/role/{id}" summary:"删除角色" tags:"角色"` 36 | Id int ` v:"min:1#id必须" path:"id"` 37 | } 38 | 39 | type DelRes struct{} 40 | 41 | type GetLstReq struct { 42 | g.Meta `method:"get" path:"/role/list" summary:"获取所有角色列表" tags:"角色"` 43 | *api.PageLstReq 44 | } 45 | 46 | type GetLstRes struct { 47 | List []*entity.Role `json:"list"` 48 | } 49 | -------------------------------------------------------------------------------- /api/user/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package user 6 | 7 | import ( 8 | "context" 9 | 10 | "devops-super/api/user/v1" 11 | ) 12 | 13 | type IUserV1 interface { 14 | GetPageLst(ctx context.Context, req *v1.GetPageLstReq) (res *v1.GetPageLstRes, err error) 15 | Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) 16 | Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) 17 | UptPassword(ctx context.Context, req *v1.UptPasswordReq) (res *v1.UptPasswordRes, err error) 18 | UptEnabled(ctx context.Context, req *v1.UptEnabledReq) (res *v1.UptEnabledRes, err error) 19 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /api/user/v1/user.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "devops-super/api" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/model/mid" 7 | "github.com/gogf/gf/v2/frame/g" 8 | ) 9 | 10 | type GetPageLstReq struct { 11 | g.Meta `method:"get" path:"/user/page-list" summary:"分页获取用户列表" tags:"用户"` 12 | *api.PageLstReq 13 | } 14 | 15 | type GetPageLstRes struct { 16 | *api.PageLstRes[*entity.User] 17 | } 18 | 19 | type AddReq struct { 20 | g.Meta `method:"post" path:"/user" summary:"新增用户" tags:"用户"` 21 | *mid.User 22 | } 23 | 24 | type AddRes struct{} 25 | 26 | type UptReq struct { 27 | g.Meta `method:"put" path:"/user/{id}" summary:"更新用户" tags:"用户"` 28 | Id int ` v:"min:1#id必须" path:"id"` 29 | *mid.User 30 | } 31 | 32 | type UptRes struct{} 33 | 34 | type UptPasswordReq struct { 35 | g.Meta `method:"patch" path:"/user/{id}/password" summary:"更新用户密码" tags:"用户"` 36 | Id int ` v:"min:1#id必须" path:"id"` 37 | Password string `v:"required|length:6,30#请输入密码|密码长度为:{min}到:{max}位"` 38 | } 39 | 40 | type UptPasswordRes struct{} 41 | 42 | type UptEnabledReq struct { 43 | g.Meta `method:"patch" path:"/user/{id}/enabled" summary:"更新用户密码" tags:"用户"` 44 | Id int `v:"min:1#id必须" path:"id"` 45 | Enabled bool `v:"required" json:"enabled"` 46 | } 47 | 48 | type UptEnabledRes struct{} 49 | 50 | type DelReq struct { 51 | g.Meta `method:"delete" path:"/user/{id}" summary:"删除用户" tags:"用户"` 52 | Id int ` v:"min:1#id必须" path:"id"` 53 | } 54 | 55 | type DelRes struct{} 56 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module devops-super 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/casbin/casbin/v2 v2.77.2 7 | github.com/gogf/gf-jwt/v2 v2.1.0 8 | github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4 9 | github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.4 10 | github.com/gogf/gf/v2 v2.5.4 11 | golang.org/x/crypto v0.11.0 12 | ) 13 | 14 | require ( 15 | github.com/BurntSushi/toml v1.2.0 // indirect 16 | github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/clbanning/mxj/v2 v2.7.0 // indirect 19 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 20 | github.com/fatih/color v1.15.0 // indirect 21 | github.com/fsnotify/fsnotify v1.6.0 // indirect 22 | github.com/go-logr/logr v1.2.4 // indirect 23 | github.com/go-logr/stdr v1.2.2 // indirect 24 | github.com/go-sql-driver/mysql v1.7.1 // indirect 25 | github.com/golang-jwt/jwt/v4 v4.3.0 // indirect 26 | github.com/gorilla/websocket v1.5.0 // indirect 27 | github.com/grokify/html-strip-tags-go v0.0.1 // indirect 28 | github.com/magiconair/properties v1.8.6 // indirect 29 | github.com/mattn/go-colorable v0.1.13 // indirect 30 | github.com/mattn/go-isatty v0.0.19 // indirect 31 | github.com/mattn/go-runewidth v0.0.15 // indirect 32 | github.com/olekukonko/tablewriter v0.0.5 // indirect 33 | github.com/redis/go-redis/v9 v9.0.5 // indirect 34 | github.com/rivo/uniseg v0.4.4 // indirect 35 | github.com/tidwall/gjson v1.14.4 // indirect 36 | github.com/tidwall/match v1.1.1 // indirect 37 | github.com/tidwall/pretty v1.2.0 // indirect 38 | go.opentelemetry.io/otel v1.14.0 // indirect 39 | go.opentelemetry.io/otel/sdk v1.14.0 // indirect 40 | go.opentelemetry.io/otel/trace v1.14.0 // indirect 41 | golang.org/x/net v0.12.0 // indirect 42 | golang.org/x/sys v0.10.0 // indirect 43 | golang.org/x/text v0.11.0 // indirect 44 | gopkg.in/yaml.v3 v3.0.1 // indirect 45 | ) 46 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 2 | github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= 3 | github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 4 | github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= 5 | github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= 6 | github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= 7 | github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= 8 | github.com/casbin/casbin/v2 v2.77.2 h1:yQinn/w9x8AswiwqwtrXz93VU48R1aYTXdHEx4RI3jM= 9 | github.com/casbin/casbin/v2 v2.77.2/go.mod h1:mzGx0hYW9/ksOSpw3wNjk3NRAroq5VMFYUQ6G43iGPk= 10 | github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 11 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 12 | github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 13 | github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= 14 | github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= 15 | github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= 16 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 17 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 18 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 19 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= 20 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 21 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 22 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 23 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 24 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 25 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 26 | github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= 27 | github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= 28 | github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= 29 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 30 | github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= 31 | github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 32 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 33 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 34 | github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= 35 | github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 36 | github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= 37 | github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= 38 | github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= 39 | github.com/gogf/gf-jwt/v2 v2.1.0 h1:79/KH6vo3IAtHTvRubE8/NXKDF6/UisItLVpdsTTIjE= 40 | github.com/gogf/gf-jwt/v2 v2.1.0/go.mod h1:AGEJOkG64G8ZYOi50ObYgJ+D7L3W4GcTW65m6VVGbmI= 41 | github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4 h1:xAmYQZEDBDoce/q5s7UTibYHHW0DSTApfmXVC/i0/zI= 42 | github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4/go.mod h1:lEgzJw5PLBOEJ4gZHgs1GwsbjyBLBttN2sN63rYRNhk= 43 | github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.4 h1:t4Ls/E022VMk5hc3a4IgWO3xGNEQRXicCTOrFymZdDg= 44 | github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.4/go.mod h1:1P7id3OWFb3lkp1zBKdGqRoVXgYAjATzky++tGh2vxc= 45 | github.com/gogf/gf/v2 v2.0.0-rc3/go.mod h1:apktt6TleWtCIwpz63vBqUnw8MX8gWKoZyxgDpXFtgM= 46 | github.com/gogf/gf/v2 v2.5.4 h1:UBCSw8mInkHmEqL0E1LYc6QhSpaNFY/wHcFrTI/rzTk= 47 | github.com/gogf/gf/v2 v2.5.4/go.mod h1:7yf5qp0BznfsYx7Sw49m3mQvBsHpwAjJk3Q9ZnKoUEc= 48 | github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= 49 | github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= 50 | github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= 51 | github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= 52 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 53 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 54 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 55 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 56 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 57 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 58 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 59 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 60 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 61 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 62 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 63 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 64 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 65 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 66 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 67 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 68 | github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= 69 | github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 70 | github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= 71 | github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= 72 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 73 | github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= 74 | github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= 75 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 76 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 77 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 78 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 79 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 80 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 81 | github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= 82 | github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 83 | github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 84 | github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= 85 | github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 86 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= 87 | github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= 88 | github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= 89 | github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= 90 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 91 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= 92 | github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= 93 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 94 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= 95 | github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= 96 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 97 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 98 | github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o= 99 | github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= 100 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 101 | github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= 102 | github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 103 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 104 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 105 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 106 | github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= 107 | github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= 108 | github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 109 | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= 110 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 111 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 112 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 113 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 114 | github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 115 | go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg= 116 | go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= 117 | go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= 118 | go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM= 119 | go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= 120 | go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= 121 | go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs= 122 | go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= 123 | go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= 124 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 125 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 126 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 127 | golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= 128 | golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= 129 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 130 | golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 131 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 132 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 133 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 134 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 135 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 136 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 137 | golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= 138 | golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 139 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 140 | golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= 141 | golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= 142 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 143 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 144 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 145 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 146 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 147 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 148 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 149 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 150 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 151 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 152 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 153 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 154 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 155 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 156 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 157 | golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 158 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 159 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 160 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 161 | golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 162 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 163 | golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 164 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 165 | golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= 166 | golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 167 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 168 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 169 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 170 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 171 | golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= 172 | golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= 173 | golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 174 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 175 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 176 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 177 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 178 | golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= 179 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 180 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 181 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 182 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 183 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 184 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 185 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 186 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 187 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 188 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 189 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 190 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 191 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 192 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 193 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 194 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 195 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 196 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 197 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 198 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 199 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 200 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 201 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 202 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 203 | -------------------------------------------------------------------------------- /hack/config.yaml: -------------------------------------------------------------------------------- 1 | 2 | # CLI tool, only in development environment. 3 | # https://goframe.org/pages/viewpage.action?pageId=3673173 4 | gfcli: 5 | docker: 6 | build: "-a amd64 -s linux -p temp -ew" 7 | tagPrefixes: 8 | - zze326/ 9 | gen: 10 | dao: 11 | - link: "mysql:zze:devops.zze@tcp(192.168.2.231:3306)/zze_admin_go?loc=Local&parseTime=true" 12 | group: default 13 | tables: "user, permission, role, dept" 14 | withTime: false 15 | gJsonSupport: true 16 | overwriteDao: true 17 | descriptionTag: true 18 | # jsonCase: Snake 19 | clear: true -------------------------------------------------------------------------------- /hack/hack-cli.mk: -------------------------------------------------------------------------------- 1 | 2 | # Install/Update to the latest CLI tool. 3 | .PHONY: cli 4 | cli: 5 | @set -e; \ 6 | wget -O gf https://github.com/gogf/gf/releases/latest/download/gf_$(shell go env GOOS)_$(shell go env GOARCH) && \ 7 | chmod +x gf && \ 8 | ./gf install -y && \ 9 | rm ./gf 10 | 11 | 12 | # Check and install CLI tool. 13 | .PHONY: cli.install 14 | cli.install: 15 | @set -e; \ 16 | gf -v > /dev/null 2>&1 || if [[ "$?" -ne "0" ]]; then \ 17 | echo "GoFame CLI is not installed, start proceeding auto installation..."; \ 18 | make cli; \ 19 | fi; -------------------------------------------------------------------------------- /hack/hack.mk: -------------------------------------------------------------------------------- 1 | include ./hack/hack-cli.mk 2 | DATE := $(shell date '+%Y%m%d%H%M') 3 | 4 | # Update GoFrame and its CLI to latest stable version. 5 | .PHONY: up 6 | up: cli.install 7 | @gf up -a 8 | 9 | # Build binary using configuration from hack/config.yaml. 10 | .PHONY: build 11 | build: cli.install 12 | @gf build -ew 13 | 14 | # Parse api and generate controller/sdk. 15 | .PHONY: ctrl 16 | ctrl: cli.install 17 | @gf gen ctrl 18 | 19 | # Generate Go files for DAO/DO/Entity. 20 | .PHONY: dao 21 | dao: cli.install 22 | @gf gen dao 23 | 24 | # Parse current project go files and generate enums go file. 25 | .PHONY: enums 26 | enums: cli.install 27 | @gf gen enums 28 | 29 | # Generate Go files for Service. 30 | .PHONY: service 31 | service: cli.install 32 | @gf gen service 33 | 34 | 35 | # Build docker image. 36 | .PHONY: image 37 | image: cli.install 38 | # $(eval _TAG = $(shell git describe --dirty --always --tags --abbrev=8 --match 'v*' | sed 's/-/./2' | sed 's/-/./2')) 39 | $(eval _TAG = $(DATE)) 40 | #ifneq (, $(shell git status --porcelain 2>/dev/null)) 41 | # $(eval _TAG = $(_TAG).dirty) 42 | #endif 43 | $(eval _TAG = $(if ${TAG}, ${TAG}, $(_TAG))) 44 | $(eval _PUSH = $(if ${PUSH}, ${PUSH}, )) 45 | @gf docker ${_PUSH} -tn $(DOCKER_NAME):${_TAG}; 46 | 47 | 48 | # Build docker image and automatically push to docker repo. 49 | .PHONY: image.push 50 | image.push: 51 | @make image PUSH=-p; 52 | 53 | 54 | # Deploy image and yaml to current kubectl environment. 55 | .PHONY: deploy 56 | deploy: 57 | $(eval _TAG = $(if ${TAG}, ${TAG}, develop)) 58 | 59 | @set -e; \ 60 | mkdir -p $(ROOT_DIR)/temp/kustomize;\ 61 | cd $(ROOT_DIR)/manifest/deploy/kustomize/overlays/${_ENV};\ 62 | kustomize build > $(ROOT_DIR)/temp/kustomize.yaml;\ 63 | kubectl apply -f $(ROOT_DIR)/temp/kustomize.yaml; \ 64 | if [ $(DEPLOY_NAME) != "" ]; then \ 65 | kubectl patch -n $(NAMESPACE) deployment/$(DEPLOY_NAME) -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"; \ 66 | fi; 67 | 68 | 69 | # Parsing protobuf files and generating go files. 70 | .PHONY: pb 71 | pb: cli.install 72 | @gf gen pb 73 | 74 | # Generate protobuf files for database tables. 75 | .PHONY: pbentity 76 | pbentity: cli.install 77 | @gf gen pbentity -------------------------------------------------------------------------------- /internal/cmd/cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/controller/dept" 6 | "devops-super/internal/controller/permission" 7 | "devops-super/internal/controller/public" 8 | "devops-super/internal/controller/role" 9 | "devops-super/internal/controller/user" 10 | "devops-super/internal/service" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | "github.com/gogf/gf/v2/net/ghttp" 14 | "github.com/gogf/gf/v2/os/gcmd" 15 | ) 16 | 17 | var ( 18 | Main = gcmd.Command{ 19 | Name: "main", 20 | Usage: "main", 21 | Brief: "start http server", 22 | Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { 23 | s := g.Server() 24 | s.Group("/", func(group *ghttp.RouterGroup) { 25 | group.Middleware(ghttp.MiddlewareCORS) 26 | group.Middleware(ghttp.MiddlewareHandlerResponse) 27 | group.Bind( 28 | public.NewV1(), 29 | ) 30 | 31 | // 权限控制路由 32 | group.Group("/", func(group *ghttp.RouterGroup) { 33 | group.Middleware(service.Middleware().Auth) 34 | group.Bind( 35 | user.NewV1(), 36 | permission.NewV1(), 37 | role.NewV1(), 38 | dept.NewV1(), 39 | ) 40 | }) 41 | }) 42 | 43 | // 初始化 44 | if err = service.Context().Init(ctx); err != nil { 45 | g.Log().Fatal(ctx, err) 46 | } 47 | s.Run() 48 | return nil 49 | }, 50 | } 51 | ) 52 | -------------------------------------------------------------------------------- /internal/consts/consts.go: -------------------------------------------------------------------------------- 1 | package consts 2 | 3 | // 权限类型 4 | const ( 5 | PERMISSION_TYPE_DIR = 1 // 目录 6 | PERMISSION_TYPE_MENU = 2 // 菜单 7 | PERMISSION_TYPE_ABLE = 3 // 功能 8 | ) 9 | 10 | // 系统必须权限名称 11 | const PERMISSION_SYSTEM_REQUIRED_NAME = "system-required" 12 | -------------------------------------------------------------------------------- /internal/controller/dept/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dept 6 | -------------------------------------------------------------------------------- /internal/controller/dept/dept_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package dept 6 | 7 | import ( 8 | "devops-super/api/dept" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() dept.IDeptV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/dept/dept_v1_add.go: -------------------------------------------------------------------------------- 1 | package dept 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/dept/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) { 13 | in := new(entity.Dept) 14 | if err = gconv.Struct(req, in); err != nil { 15 | return 16 | } 17 | 18 | err = service.Dept().Add(ctx, in) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/dept/dept_v1_del.go: -------------------------------------------------------------------------------- 1 | package dept 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/dept/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = service.Role().Del(ctx, &do.Role{Id: req.Id}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/dept/dept_v1_get_lst.go: -------------------------------------------------------------------------------- 1 | package dept 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/dept/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) { 11 | res = new(v1.GetLstRes) 12 | res.List, err = service.Dept().GetLst(ctx, req.Search) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/dept/dept_v1_upt.go: -------------------------------------------------------------------------------- 1 | package dept 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/dept/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) { 13 | in := new(do.Dept) 14 | if err = gconv.Struct(req, in); err != nil { 15 | return 16 | } 17 | err = service.Dept().Upt(ctx, in) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/permission/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package permission 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package permission 6 | 7 | import ( 8 | "devops-super/api/permission" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() permission.IPermissionV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_add.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/permission/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) { 13 | ePermission := new(entity.Permission) 14 | if err = gconv.Struct(req, ePermission); err != nil { 15 | return 16 | } 17 | err = service.Permission().Add(ctx, ePermission) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_del.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/permission/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = service.Permission().Del(ctx, &do.Permission{Id: req.Id}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_get_lst.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/permission/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) { 11 | res = new(v1.GetLstRes) 12 | res.List, err = service.Permission().GetLst(ctx, req.Search) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_get_route_lst.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/permission/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetRouteLst(ctx context.Context, req *v1.GetRouteLstReq) (res *v1.GetRouteLstRes, err error) { 11 | res = new(v1.GetRouteLstRes) 12 | res.List, err = service.Permission().GetRouteLst(ctx) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_upt.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/permission/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) { 13 | uptDo := new(do.Permission) 14 | if err = gconv.Struct(req, uptDo); err != nil { 15 | return 16 | } 17 | err = service.Permission().Upt(ctx, uptDo) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/permission/permission_v1_upt_show_link.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/permission/v1" 9 | ) 10 | 11 | func (c *ControllerV1) UptShowLink(ctx context.Context, req *v1.UptShowLinkReq) (res *v1.UptShowLinkRes, err error) { 12 | err = service.Permission().Upt(ctx, &do.Permission{Id: req.Id, ShowLink: req.Enabled}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/public/public.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package public 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/public/public_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package public 6 | 7 | import ( 8 | "devops-super/api/public" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() public.IPublicV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/public/public_v1_login.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "time" 8 | 9 | "devops-super/api/public/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) { 13 | token, expires := service.Auth().LoginHandler(ctx) 14 | refreshAfter := time.Now().Add(expires.Sub(time.Now()) / 2).UnixMilli() 15 | eUser, err := service.User().GetComb(ctx, &do.User{Username: req.Username}) 16 | if err != nil { 17 | return nil, err 18 | } 19 | res = &v1.LoginRes{ 20 | Username: eUser.Username, 21 | RealName: eUser.RealName, 22 | Token: token, 23 | Expires: expires.UnixMilli(), 24 | RefreshAfter: refreshAfter, 25 | Roles: eUser.RoleCodes(), 26 | } 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /internal/controller/public/public_v1_logout.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/public/v1" 8 | ) 9 | 10 | func (c *ControllerV1) Logout(ctx context.Context, _ *v1.LogoutReq) (res *v1.LogoutRes, err error) { 11 | service.Auth().LogoutHandler(ctx) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/public/public_v1_ping.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import ( 4 | "context" 5 | 6 | "devops-super/api/public/v1" 7 | ) 8 | 9 | func (c *ControllerV1) Ping(ctx context.Context, req *v1.PingReq) (res *v1.PingRes, err error) { 10 | return 11 | } 12 | -------------------------------------------------------------------------------- /internal/controller/public/public_v1_refresh_token.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "time" 8 | 9 | "devops-super/api/public/v1" 10 | ) 11 | 12 | func (c *ControllerV1) RefreshToken(ctx context.Context, req *v1.RefreshTokenReq) (res *v1.RefreshTokenRes, err error) { 13 | token, expire := service.Auth().RefreshHandler(ctx) 14 | refreshAfter := time.Now().Add(expire.Sub(time.Now()) / 2).UnixMilli() 15 | eUser, err := service.User().GetComb(ctx, &do.User{Id: service.Auth().GetIdentity(ctx)}) 16 | if err != nil { 17 | return nil, err 18 | } 19 | res = &v1.RefreshTokenRes{ 20 | Username: eUser.Username, 21 | RealName: eUser.RealName, 22 | Token: token, 23 | Expire: expire.UnixMilli(), 24 | RefreshAfter: refreshAfter, 25 | Roles: eUser.RoleCodes(), 26 | } 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /internal/controller/role/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package role 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/role/role_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package role 6 | 7 | import ( 8 | "devops-super/api/role" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() role.IRoleV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_add.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/role/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) { 13 | in := new(entity.Role) 14 | if err = gconv.Struct(req, in); err != nil { 15 | return 16 | } 17 | 18 | err = service.Role().Add(ctx, in) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_del.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/role/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = service.Role().Del(ctx, &do.Role{Id: req.Id}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_get_lst.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/role/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetLst(ctx context.Context, req *v1.GetLstReq) (res *v1.GetLstRes, err error) { 11 | res = new(v1.GetLstRes) 12 | res.List, err = service.Role().GetLst(ctx) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_get_page_lst.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/role/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetPageLst(ctx context.Context, req *v1.GetPageLstReq) (res *v1.GetPageLstRes, err error) { 11 | res = new(v1.GetPageLstRes) 12 | res.PageLstRes, err = service.Role().GetPageLst(ctx, req.PageLstReq) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_upt.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/role/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) { 13 | in := new(do.Role) 14 | if err = gconv.Struct(req, in); err != nil { 15 | return 16 | } 17 | err = service.Role().Upt(ctx, in) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/role/role_v1_upt_permission.go: -------------------------------------------------------------------------------- 1 | package role 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/role/v1" 9 | ) 10 | 11 | func (c *ControllerV1) UptPermission(ctx context.Context, req *v1.UptPermissionReq) (res *v1.UptPermissionRes, err error) { 12 | err = service.Role().Upt(ctx, &do.Role{Id: req.Id, Permission: req.PermissionIds}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/user/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package user 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/user/user_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package user 6 | 7 | import ( 8 | "devops-super/api/user" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() user.IUserV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_add.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/entity" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/user/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) { 13 | eUser := new(entity.User) 14 | if err = gconv.Struct(req, eUser); err != nil { 15 | return 16 | } 17 | 18 | eUser.Password = "devops.zze" 19 | err = service.User().Add(ctx, eUser) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_del.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/api/user/v1" 6 | "devops-super/internal/model/do" 7 | "devops-super/internal/service" 8 | ) 9 | 10 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 11 | err = service.User().Del(ctx, &do.User{Id: req.Id}) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_get_page_lst.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/service" 6 | 7 | "devops-super/api/user/v1" 8 | ) 9 | 10 | func (c *ControllerV1) GetPageLst(ctx context.Context, req *v1.GetPageLstReq) (res *v1.GetPageLstRes, err error) { 11 | res = new(v1.GetPageLstRes) 12 | res.PageLstRes, err = service.User().GetPageLst(ctx, req.PageLstReq) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_upt.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | "github.com/gogf/gf/v2/util/gconv" 8 | 9 | "devops-super/api/user/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Upt(ctx context.Context, req *v1.UptReq) (res *v1.UptRes, err error) { 13 | uptDo := new(do.User) 14 | if err = gconv.Struct(req, uptDo); err != nil { 15 | return 16 | } 17 | err = service.User().Upt(ctx, uptDo) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_upt_enabled.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model/do" 6 | "devops-super/internal/service" 7 | 8 | "devops-super/api/user/v1" 9 | ) 10 | 11 | func (c *ControllerV1) UptEnabled(ctx context.Context, req *v1.UptEnabledReq) (res *v1.UptEnabledRes, err error) { 12 | err = service.User().Upt(ctx, &do.User{Id: req.Id, Enabled: req.Enabled}) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/user/user_v1_upt_password.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/api/user/v1" 6 | "devops-super/internal/model/do" 7 | "devops-super/internal/service" 8 | ) 9 | 10 | func (c *ControllerV1) UptPassword(ctx context.Context, req *v1.UptPasswordReq) (res *v1.UptPasswordRes, err error) { 11 | err = service.User().Upt(ctx, &do.User{Id: req.Id, Password: req.Password}) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/dao/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/dao/.gitkeep -------------------------------------------------------------------------------- /internal/dao/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "devops-super/internal/dao/internal" 9 | ) 10 | 11 | // internalDeptDao is internal type for wrapping internal DAO implements. 12 | type internalDeptDao = *internal.DeptDao 13 | 14 | // deptDao is the data access object for table dept. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type deptDao struct { 17 | internalDeptDao 18 | } 19 | 20 | var ( 21 | // Dept is globally public accessible object for table dept operations. 22 | Dept = deptDao{ 23 | internal.NewDeptDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/internal/dept.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // DeptDao is the data access object for table dept. 15 | type DeptDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns DeptColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // DeptColumns defines and stores column names for table dept. 22 | type DeptColumns struct { 23 | Id string // 24 | Name string // 部门名称 25 | Rank string // 排序 26 | ParentId string // 上级部门 id 27 | UpdatedAt string // 更新时间 28 | } 29 | 30 | // deptColumns holds the columns for table dept. 31 | var deptColumns = DeptColumns{ 32 | Id: "id", 33 | Name: "name", 34 | Rank: "rank", 35 | ParentId: "parent_id", 36 | UpdatedAt: "updated_at", 37 | } 38 | 39 | // NewDeptDao creates and returns a new DAO object for table data access. 40 | func NewDeptDao() *DeptDao { 41 | return &DeptDao{ 42 | group: "default", 43 | table: "dept", 44 | columns: deptColumns, 45 | } 46 | } 47 | 48 | // DB retrieves and returns the underlying raw database management object of current DAO. 49 | func (dao *DeptDao) DB() gdb.DB { 50 | return g.DB(dao.group) 51 | } 52 | 53 | // Table returns the table name of current dao. 54 | func (dao *DeptDao) Table() string { 55 | return dao.table 56 | } 57 | 58 | // Columns returns all column names of current dao. 59 | func (dao *DeptDao) Columns() DeptColumns { 60 | return dao.columns 61 | } 62 | 63 | // Group returns the configuration group name of database of current dao. 64 | func (dao *DeptDao) Group() string { 65 | return dao.group 66 | } 67 | 68 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 69 | func (dao *DeptDao) Ctx(ctx context.Context) *gdb.Model { 70 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 71 | } 72 | 73 | // Transaction wraps the transaction logic using function f. 74 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 75 | // It commits the transaction and returns nil if function f returns nil. 76 | // 77 | // Note that, you should not Commit or Rollback the transaction in function f 78 | // as it is automatically handled by this function. 79 | func (dao *DeptDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 80 | return dao.Ctx(ctx).Transaction(ctx, f) 81 | } 82 | -------------------------------------------------------------------------------- /internal/dao/internal/permission.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // PermissionDao is the data access object for table permission. 15 | type PermissionDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns PermissionColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // PermissionColumns defines and stores column names for table permission. 22 | type PermissionColumns struct { 23 | Id string // 24 | Title string // 标题 25 | Name string // 路由名称 26 | Type string // 类型:1-目录,2-菜单,3-功能 27 | FRoute string // 前端路由路径 28 | BRoutes string // 后端路由路径 29 | Redirect string // 重定向路径 30 | Icon string // 图标 31 | Rank string // 排序 32 | ShowLink string // 是否在菜单中展示 33 | ShowParent string // 是否展示父级菜单 34 | KeepAlive string // 页面缓存 35 | ParentId string // 父级权限 id 36 | } 37 | 38 | // permissionColumns holds the columns for table permission. 39 | var permissionColumns = PermissionColumns{ 40 | Id: "id", 41 | Title: "title", 42 | Name: "name", 43 | Type: "type", 44 | FRoute: "f_route", 45 | BRoutes: "b_routes", 46 | Redirect: "redirect", 47 | Icon: "icon", 48 | Rank: "rank", 49 | ShowLink: "show_link", 50 | ShowParent: "show_parent", 51 | KeepAlive: "keep_alive", 52 | ParentId: "parent_id", 53 | } 54 | 55 | // NewPermissionDao creates and returns a new DAO object for table data access. 56 | func NewPermissionDao() *PermissionDao { 57 | return &PermissionDao{ 58 | group: "default", 59 | table: "permission", 60 | columns: permissionColumns, 61 | } 62 | } 63 | 64 | // DB retrieves and returns the underlying raw database management object of current DAO. 65 | func (dao *PermissionDao) DB() gdb.DB { 66 | return g.DB(dao.group) 67 | } 68 | 69 | // Table returns the table name of current dao. 70 | func (dao *PermissionDao) Table() string { 71 | return dao.table 72 | } 73 | 74 | // Columns returns all column names of current dao. 75 | func (dao *PermissionDao) Columns() PermissionColumns { 76 | return dao.columns 77 | } 78 | 79 | // Group returns the configuration group name of database of current dao. 80 | func (dao *PermissionDao) Group() string { 81 | return dao.group 82 | } 83 | 84 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 85 | func (dao *PermissionDao) Ctx(ctx context.Context) *gdb.Model { 86 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 87 | } 88 | 89 | // Transaction wraps the transaction logic using function f. 90 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 91 | // It commits the transaction and returns nil if function f returns nil. 92 | // 93 | // Note that, you should not Commit or Rollback the transaction in function f 94 | // as it is automatically handled by this function. 95 | func (dao *PermissionDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 96 | return dao.Ctx(ctx).Transaction(ctx, f) 97 | } 98 | -------------------------------------------------------------------------------- /internal/dao/internal/role.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // RoleDao is the data access object for table role. 15 | type RoleDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns RoleColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // RoleColumns defines and stores column names for table role. 22 | type RoleColumns struct { 23 | Id string // 24 | Name string // 角色名称 25 | Code string // 角色代码 26 | Permission string // 关联权限 27 | UpdatedAt string // 更新时间 28 | } 29 | 30 | // roleColumns holds the columns for table role. 31 | var roleColumns = RoleColumns{ 32 | Id: "id", 33 | Name: "name", 34 | Code: "code", 35 | Permission: "permission", 36 | UpdatedAt: "updated_at", 37 | } 38 | 39 | // NewRoleDao creates and returns a new DAO object for table data access. 40 | func NewRoleDao() *RoleDao { 41 | return &RoleDao{ 42 | group: "default", 43 | table: "role", 44 | columns: roleColumns, 45 | } 46 | } 47 | 48 | // DB retrieves and returns the underlying raw database management object of current DAO. 49 | func (dao *RoleDao) DB() gdb.DB { 50 | return g.DB(dao.group) 51 | } 52 | 53 | // Table returns the table name of current dao. 54 | func (dao *RoleDao) Table() string { 55 | return dao.table 56 | } 57 | 58 | // Columns returns all column names of current dao. 59 | func (dao *RoleDao) Columns() RoleColumns { 60 | return dao.columns 61 | } 62 | 63 | // Group returns the configuration group name of database of current dao. 64 | func (dao *RoleDao) Group() string { 65 | return dao.group 66 | } 67 | 68 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 69 | func (dao *RoleDao) Ctx(ctx context.Context) *gdb.Model { 70 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 71 | } 72 | 73 | // Transaction wraps the transaction logic using function f. 74 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 75 | // It commits the transaction and returns nil if function f returns nil. 76 | // 77 | // Note that, you should not Commit or Rollback the transaction in function f 78 | // as it is automatically handled by this function. 79 | func (dao *RoleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 80 | return dao.Ctx(ctx).Transaction(ctx, f) 81 | } 82 | -------------------------------------------------------------------------------- /internal/dao/internal/user.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // UserDao is the data access object for table user. 15 | type UserDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns UserColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // UserColumns defines and stores column names for table user. 22 | type UserColumns struct { 23 | Id string // 24 | Username string // 用户名 25 | Password string // 密码 26 | Phone string // 手机号码 27 | Email string // 邮箱 28 | RealName string // 真实姓名 29 | Enabled string // 是否启用状态 30 | RoleIds string // 角色 id 31 | DeptId string // 所属部门 id 32 | UpdatedAt string // 更新时间 33 | } 34 | 35 | // userColumns holds the columns for table user. 36 | var userColumns = UserColumns{ 37 | Id: "id", 38 | Username: "username", 39 | Password: "password", 40 | Phone: "phone", 41 | Email: "email", 42 | RealName: "real_name", 43 | Enabled: "enabled", 44 | RoleIds: "role_ids", 45 | DeptId: "dept_id", 46 | UpdatedAt: "updated_at", 47 | } 48 | 49 | // NewUserDao creates and returns a new DAO object for table data access. 50 | func NewUserDao() *UserDao { 51 | return &UserDao{ 52 | group: "default", 53 | table: "user", 54 | columns: userColumns, 55 | } 56 | } 57 | 58 | // DB retrieves and returns the underlying raw database management object of current DAO. 59 | func (dao *UserDao) DB() gdb.DB { 60 | return g.DB(dao.group) 61 | } 62 | 63 | // Table returns the table name of current dao. 64 | func (dao *UserDao) Table() string { 65 | return dao.table 66 | } 67 | 68 | // Columns returns all column names of current dao. 69 | func (dao *UserDao) Columns() UserColumns { 70 | return dao.columns 71 | } 72 | 73 | // Group returns the configuration group name of database of current dao. 74 | func (dao *UserDao) Group() string { 75 | return dao.group 76 | } 77 | 78 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 79 | func (dao *UserDao) Ctx(ctx context.Context) *gdb.Model { 80 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 81 | } 82 | 83 | // Transaction wraps the transaction logic using function f. 84 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 85 | // It commits the transaction and returns nil if function f returns nil. 86 | // 87 | // Note that, you should not Commit or Rollback the transaction in function f 88 | // as it is automatically handled by this function. 89 | func (dao *UserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 90 | return dao.Ctx(ctx).Transaction(ctx, f) 91 | } 92 | -------------------------------------------------------------------------------- /internal/dao/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "devops-super/internal/dao/internal" 9 | ) 10 | 11 | // internalPermissionDao is internal type for wrapping internal DAO implements. 12 | type internalPermissionDao = *internal.PermissionDao 13 | 14 | // permissionDao is the data access object for table permission. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type permissionDao struct { 17 | internalPermissionDao 18 | } 19 | 20 | var ( 21 | // Permission is globally public accessible object for table permission operations. 22 | Permission = permissionDao{ 23 | internal.NewPermissionDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "devops-super/internal/dao/internal" 9 | ) 10 | 11 | // internalRoleDao is internal type for wrapping internal DAO implements. 12 | type internalRoleDao = *internal.RoleDao 13 | 14 | // roleDao is the data access object for table role. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type roleDao struct { 17 | internalRoleDao 18 | } 19 | 20 | var ( 21 | // Role is globally public accessible object for table role operations. 22 | Role = roleDao{ 23 | internal.NewRoleDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "devops-super/internal/dao/internal" 9 | ) 10 | 11 | // internalUserDao is internal type for wrapping internal DAO implements. 12 | type internalUserDao = *internal.UserDao 13 | 14 | // userDao is the data access object for table user. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type userDao struct { 17 | internalUserDao 18 | } 19 | 20 | var ( 21 | // User is globally public accessible object for table user operations. 22 | User = userDao{ 23 | internal.NewUserDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/logic/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/logic/.gitkeep -------------------------------------------------------------------------------- /internal/logic/context/casbin.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/consts" 6 | "devops-super/internal/model/entity/comb" 7 | "devops-super/internal/service" 8 | "github.com/casbin/casbin/v2" 9 | "github.com/casbin/casbin/v2/model" 10 | "github.com/gogf/gf/v2/frame/g" 11 | "strings" 12 | ) 13 | 14 | func (*sContext) initCasbin(ctx context.Context) (*casbin.Enforcer, error) { 15 | g.Log().Debug(ctx, "init casbin enforcer start.") 16 | enforcer, err := casbin.NewEnforcer(newCasbinModel()) 17 | if err != nil { 18 | return nil, err 19 | } 20 | roleList, err := service.Role().GetCombList(ctx) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | type recursiveHandlePermissionsFunc func(roleCode string, permissions []*comb.Permission) error 26 | var recursiveHandlePermissions recursiveHandlePermissionsFunc 27 | 28 | recursiveHandlePermissions = func(roleCode string, permissions []*comb.Permission) error { 29 | for _, permission := range permissions { 30 | if permission.Type == consts.PERMISSION_TYPE_ABLE { 31 | for _, backendRouteInfo := range permission.BRoutes.Array() { 32 | routeInfoArr := strings.SplitN(backendRouteInfo.(string), ":", 2) 33 | method := strings.ToUpper(routeInfoArr[0]) 34 | routePath := routeInfoArr[1] 35 | if enforcer.HasPolicy(roleCode, routePath, method) { 36 | continue 37 | } 38 | if _, err := enforcer.AddPolicy(roleCode, routePath, method); err != nil { 39 | return err 40 | } 41 | g.Log().Debugf(ctx, "casbin policy added: %s, %s, %s", roleCode, routePath, method) 42 | } 43 | } else { 44 | if len(permission.Children) > 0 { 45 | if err = recursiveHandlePermissions(roleCode, permission.Children); err != nil { 46 | return err 47 | } 48 | } 49 | } 50 | } 51 | return nil 52 | } 53 | 54 | for _, role := range roleList { 55 | if err := recursiveHandlePermissions(role.Code, role.Permissions); err != nil { 56 | return nil, err 57 | } 58 | } 59 | 60 | userList, err := service.User().GetCombLst(ctx) 61 | if err != nil { 62 | return nil, err 63 | } 64 | 65 | for _, user := range userList { 66 | var roleCodes []string 67 | for _, role := range user.Roles { 68 | roleCodes = append(roleCodes, role.Code) 69 | } 70 | if _, err := enforcer.AddRolesForUser(user.Username, roleCodes); err != nil { 71 | return nil, err 72 | } 73 | g.Log().Debugf(ctx, "casbin roles added: %s, %v", user.Username, roleCodes) 74 | } 75 | g.Log().Debug(ctx, "init casbin enforcer successful.") 76 | return enforcer, nil 77 | } 78 | 79 | func newCasbinModel() model.Model { 80 | m := model.NewModel() 81 | m.AddDef("r", "r", "sub, obj, act") 82 | m.AddDef("p", "p", "sub, obj, act") 83 | m.AddDef("g", "g", "_, _") 84 | m.AddDef("e", "e", "some(where (p.eft == allow))") 85 | m.AddDef("m", "m", `g(r.sub, p.sub) && keyMatch2(r.obj, p.obj) && regexMatch(r.act, p.act) || g(r.sub, "admin")`) 86 | return m 87 | } 88 | -------------------------------------------------------------------------------- /internal/logic/context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/model" 6 | "devops-super/internal/service" 7 | ) 8 | 9 | type sContext struct { 10 | svcCtx *model.ServiceContext 11 | ctx context.Context 12 | } 13 | 14 | func init() { 15 | service.RegisterContext(New()) 16 | } 17 | 18 | func New() *sContext { 19 | return &sContext{} 20 | } 21 | 22 | func (s *sContext) Init(ctx context.Context) error { 23 | s.ctx = ctx 24 | return s.initServiceContext() 25 | } 26 | 27 | func (s *sContext) initServiceContext() (err error) { 28 | s.svcCtx = new(model.ServiceContext) 29 | // 初始化 casbin 30 | err = s.RefreshCasbin(s.ctx) 31 | if err != nil { 32 | return 33 | } 34 | return 35 | } 36 | 37 | func (s *sContext) RefreshCasbin(ctx context.Context) error { 38 | enforcer, err := s.initCasbin(ctx) 39 | if err != nil { 40 | return err 41 | } 42 | s.svcCtx.CasbinEnforcer = enforcer 43 | return nil 44 | } 45 | 46 | func (s *sContext) Ctx() *model.ServiceContext { 47 | return s.svcCtx 48 | } 49 | -------------------------------------------------------------------------------- /internal/logic/dept/dept.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/dao" 6 | "devops-super/internal/model/do" 7 | "devops-super/internal/model/entity" 8 | "devops-super/internal/service" 9 | "devops-super/utility/util" 10 | "github.com/gogf/gf/v2/errors/gerror" 11 | "github.com/gogf/gf/v2/util/gutil" 12 | ) 13 | 14 | type sDept struct{} 15 | 16 | var ( 17 | cols = dao.Dept.Columns() 18 | ) 19 | 20 | func init() { 21 | service.RegisterDept(New()) 22 | } 23 | 24 | func New() *sDept { 25 | return &sDept{} 26 | } 27 | 28 | func (s *sDept) Add(ctx context.Context, in *entity.Dept) (err error) { 29 | r, err := s.Get(ctx, &do.Dept{Name: in.Name}) 30 | if err != nil { 31 | return err 32 | } 33 | if r != nil { 34 | return gerror.Newf("已存在名称为 %s 部门", in.Name) 35 | } 36 | _, err = dao.Dept.Ctx(ctx).Insert(in) 37 | return 38 | } 39 | 40 | func (*sDept) Get(ctx context.Context, in *do.Dept) (out *entity.Dept, err error) { 41 | err = dao.Dept.Ctx(ctx).Where(in).OmitNilWhere().Limit(1).Scan(&out) 42 | return 43 | } 44 | 45 | func (*sDept) GetLst(ctx context.Context, search string) (out []*entity.Dept, err error) { 46 | m := dao.Dept.Ctx(ctx).Order(dao.Dept.Columns().Rank).Safe(true) 47 | if !gutil.IsEmpty(search) { 48 | m = m.WhereOr(m.Builder().WhereOrLike(cols.Name, util.SqlLikeStr(search))) 49 | } 50 | err = m.Scan(&out) 51 | return 52 | } 53 | 54 | func (*sDept) Upt(ctx context.Context, in *do.Dept) (err error) { 55 | if !gutil.IsEmpty(in.Name) { 56 | r, err := dao.Dept.Ctx(ctx).WhereNot(cols.Id, in.Id).Where(cols.Name, in.Name).One() 57 | if err != nil { 58 | return err 59 | } 60 | 61 | if r != nil { 62 | return gerror.Newf("已存在名称为 %s 部门", in.Name) 63 | } 64 | } 65 | _, err = dao.Dept.Ctx(ctx).WherePri(in.Id).OmitNilData().Data(in).Update() 66 | return 67 | } 68 | 69 | func (*sDept) Del(ctx context.Context, in *do.Dept) (err error) { 70 | _, err = dao.Dept.Ctx(ctx).Where(in).OmitNilWhere().Delete() 71 | return 72 | } 73 | -------------------------------------------------------------------------------- /internal/logic/logic.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package logic 6 | 7 | import ( 8 | _ "devops-super/internal/logic/context" 9 | _ "devops-super/internal/logic/dept" 10 | _ "devops-super/internal/logic/middleware" 11 | _ "devops-super/internal/logic/permission" 12 | _ "devops-super/internal/logic/role" 13 | _ "devops-super/internal/logic/user" 14 | ) 15 | -------------------------------------------------------------------------------- /internal/logic/middleware/middleware.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "devops-super/internal/service" 5 | "github.com/gogf/gf/v2/errors/gerror" 6 | "github.com/gogf/gf/v2/frame/g" 7 | "github.com/gogf/gf/v2/net/ghttp" 8 | "github.com/gogf/gf/v2/text/gstr" 9 | "net/http" 10 | ) 11 | 12 | type sMiddleware struct{} 13 | 14 | func init() { 15 | service.RegisterMiddleware(New()) 16 | } 17 | 18 | func New() *sMiddleware { 19 | return &sMiddleware{} 20 | } 21 | 22 | func (*sMiddleware) Auth(r *ghttp.Request) { 23 | service.Auth().MiddlewareFunc()(r) 24 | var ( 25 | requestPath = r.Request.URL.Path 26 | method = r.Request.Method 27 | refreshPermissionPathPrefixes = []string{"/permission", "/role", "/user"} 28 | ) 29 | 30 | pass, err := service.Context().Ctx().CasbinEnforcer.Enforce(service.CurrentUser(r.GetCtx()).Username, requestPath, method) 31 | if err != nil { 32 | r.Response.WriteJson(g.Map{ 33 | "code": http.StatusForbidden, 34 | "message": err, 35 | }) 36 | r.ExitAll() 37 | } 38 | 39 | if !pass { 40 | r.Response.WriteJson(g.Map{ 41 | "code": http.StatusForbidden, 42 | "message": "没有接口权限", 43 | }) 44 | r.ExitAll() 45 | } 46 | 47 | r.Middleware.Next() 48 | 49 | if method != "GET" { 50 | for _, prefix := range refreshPermissionPathPrefixes { 51 | if gstr.HasPrefix(requestPath, prefix) { 52 | if err := service.Context().RefreshCasbin(r.GetCtx()); err != nil { 53 | r.Response.WriteJson(g.Map{ 54 | "code": http.StatusInternalServerError, 55 | "message": gerror.Newf("刷新权限失败: %v", err), 56 | }) 57 | r.ExitAll() 58 | } 59 | break 60 | } 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /internal/logic/permission/permission.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/consts" 6 | "devops-super/internal/dao" 7 | "devops-super/internal/model/do" 8 | "devops-super/internal/model/entity" 9 | "devops-super/internal/service" 10 | "devops-super/utility/util" 11 | "github.com/gogf/gf/v2/errors/gerror" 12 | "github.com/gogf/gf/v2/util/gutil" 13 | ) 14 | 15 | type sPermission struct{} 16 | 17 | var ( 18 | cols = dao.Permission.Columns() 19 | ) 20 | 21 | func init() { 22 | service.RegisterPermission(New()) 23 | } 24 | 25 | func New() *sPermission { 26 | return &sPermission{} 27 | } 28 | 29 | func (s *sPermission) Add(ctx context.Context, in *entity.Permission) (err error) { 30 | r, err := s.Get(ctx, &do.Permission{Name: in.Name}) 31 | if err != nil { 32 | return err 33 | } 34 | if r != nil { 35 | return gerror.Newf("已存在名称为 %s 权限", in.Name) 36 | } 37 | if (in.Type == consts.PERMISSION_TYPE_DIR || in.Type == consts.PERMISSION_TYPE_MENU) && !gutil.IsEmpty(in.FRoute) { 38 | r, err = s.Get(ctx, &do.Permission{FRoute: in.FRoute}) 39 | if err != nil { 40 | return err 41 | } 42 | if r != nil { 43 | return gerror.Newf("已存在前端路由为 %s 权限", in.FRoute) 44 | } 45 | } 46 | _, err = dao.Permission.Ctx(ctx).Insert(in) 47 | return 48 | } 49 | 50 | func (*sPermission) Get(ctx context.Context, in *do.Permission) (out *entity.Permission, err error) { 51 | err = dao.Permission.Ctx(ctx).Where(in).OmitNilWhere().Limit(1).Scan(&out) 52 | return 53 | } 54 | 55 | func (*sPermission) GetLst(ctx context.Context, search string) (out []*entity.Permission, err error) { 56 | m := dao.Permission.Ctx(ctx).Order(dao.Permission.Columns().Rank).Safe(true) 57 | if !gutil.IsEmpty(search) { 58 | m = m.WhereOr(m.Builder().WhereOrLike(cols.Name, util.SqlLikeStr(search)).WhereOrLike(cols.Title, util.SqlLikeStr(search))) 59 | } 60 | err = m.Scan(&out) 61 | return 62 | } 63 | 64 | func (*sPermission) Upt(ctx context.Context, in *do.Permission) (err error) { 65 | if !gutil.IsEmpty(in.Name) { 66 | r, err := dao.Permission.Ctx(ctx).WhereNot(cols.Id, in.Id).Where(cols.Name, in.Name).One() 67 | if err != nil { 68 | return err 69 | } 70 | 71 | if r != nil { 72 | return gerror.Newf("已存在名称为 %s 权限", in.Name) 73 | } 74 | } 75 | if (in.Type == consts.PERMISSION_TYPE_DIR || in.Type == consts.PERMISSION_TYPE_MENU) && !gutil.IsEmpty(in.FRoute) { 76 | r, err := dao.Permission.Ctx(ctx).WhereNot(cols.Id, in.Id).Where(cols.FRoute, in.FRoute).One() 77 | if err != nil { 78 | return err 79 | } 80 | if r != nil { 81 | return gerror.Newf("已存在前端路由为 %s 权限", in.FRoute) 82 | } 83 | } 84 | 85 | _, err = dao.Permission.Ctx(ctx).WherePri(in.Id).OmitNilData().Data(in).Update() 86 | return 87 | } 88 | 89 | func (*sPermission) Del(ctx context.Context, in *do.Permission) (err error) { 90 | _, err = dao.Permission.Ctx(ctx).Where(in).OmitNilWhere().Delete() 91 | return 92 | } 93 | 94 | func (s *sPermission) SystemRequired(ctx context.Context) (ePermission *entity.Permission, err error) { 95 | requiredPermission, err := s.Get(ctx, &do.Permission{Name: consts.PERMISSION_SYSTEM_REQUIRED_NAME}) 96 | if err != nil { 97 | return nil, err 98 | } 99 | if requiredPermission != nil && requiredPermission.Id > 0 { 100 | return requiredPermission, nil 101 | } 102 | return nil, gerror.New("系统必需权限缺失") 103 | } 104 | -------------------------------------------------------------------------------- /internal/logic/permission/route.go: -------------------------------------------------------------------------------- 1 | package permission 2 | 3 | import ( 4 | "context" 5 | "devops-super/internal/consts" 6 | "devops-super/internal/dao" 7 | "devops-super/internal/model/do" 8 | "devops-super/internal/model/entity" 9 | "devops-super/internal/model/entity/comb" 10 | "devops-super/internal/model/mid" 11 | "devops-super/internal/service" 12 | "github.com/gogf/gf/v2/container/gset" 13 | "github.com/gogf/gf/v2/util/gconv" 14 | "sort" 15 | ) 16 | 17 | func (*sPermission) GetRouteLst(ctx context.Context) (out []*mid.Route, err error) { 18 | cUser, err := service.User().GetComb(ctx, &do.User{Id: service.CurrentUser(ctx).UserId}) 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | var permissionIdSet = gset.New() 24 | for _, role := range cUser.Roles { 25 | if role.Permission.IsNil() { 26 | continue 27 | } 28 | for _, pId := range role.Permission.Array() { 29 | permissionIdSet.Add(pId) 30 | } 31 | } 32 | 33 | var cPermissions []*comb.Permission 34 | if err = dao.Permission.Ctx(ctx).Order(cols.Rank).WithAll().WhereIn(cols.Id, permissionIdSet.Slice()).Scan(&cPermissions); err != nil { 35 | return 36 | } 37 | 38 | var ePermissionMap = make(map[int]*entity.Permission, len(cPermissions)) 39 | for _, permission := range cPermissions { 40 | ePermissionMap[permission.Id] = permission.Permission 41 | } 42 | 43 | type ( 44 | handleManyFunc = func(children []*comb.Permission) error 45 | handleOneFunc = func(cPermission *comb.Permission) error 46 | handleParentFunc = func(parentId int) (*mid.Route, error) 47 | ) 48 | 49 | var ( 50 | finalRoutes mid.FrontendRouteList 51 | routeMap = make(map[int]*mid.Route) 52 | getOne = func(id int) *entity.Permission { 53 | return ePermissionMap[id] 54 | } 55 | permissionToRoute = func(ePermission *entity.Permission) (route *mid.Route) { 56 | _ = gconv.Struct(ePermission, &route) 57 | return 58 | } 59 | handleMany handleManyFunc 60 | handleOne handleOneFunc 61 | handleParent handleParentFunc 62 | ) 63 | 64 | handleParent = func(parentId int) (*mid.Route, error) { 65 | var ( 66 | parent *mid.Route 67 | ok bool 68 | ) 69 | parent, ok = routeMap[parentId] 70 | if !ok { 71 | ePermission := new(entity.Permission) 72 | if permissionIdSet.Contains(parentId) { 73 | ePermission = getOne(parentId) 74 | } else { 75 | if err := dao.Permission.Ctx(ctx).WherePri(parentId).Scan(ePermission); err != nil { 76 | return nil, err 77 | } 78 | parent = permissionToRoute(ePermission) 79 | routeMap[parentId] = parent 80 | finalRoutes = append(finalRoutes, parent) 81 | } 82 | if parent.ParentId > 0 { 83 | if _, err := handleParent(parent.ParentId); err != nil { 84 | return nil, err 85 | } 86 | } 87 | } 88 | 89 | return parent, nil 90 | } 91 | 92 | handleMany = func(children []*comb.Permission) error { 93 | for _, child := range children { 94 | if err := handleOne(child); err != nil { 95 | return err 96 | } 97 | } 98 | return nil 99 | } 100 | 101 | handleOne = func(cPermission *comb.Permission) error { 102 | switch cPermission.Type { 103 | case consts.PERMISSION_TYPE_DIR, consts.PERMISSION_TYPE_MENU: 104 | route := permissionToRoute(cPermission.Permission) 105 | if cPermission.Type == consts.PERMISSION_TYPE_DIR { 106 | if err := handleMany(cPermission.Children); err != nil { 107 | return err 108 | } 109 | } else { 110 | route.Auths = cPermission.AuthCodes() 111 | } 112 | 113 | if _, ok := routeMap[route.Id]; !ok { 114 | routeMap[route.Id] = route 115 | finalRoutes = append(finalRoutes, route) 116 | } 117 | } 118 | 119 | if parentId := cPermission.ParentId; parentId > 0 { 120 | parent, err := handleParent(parentId) 121 | if err != nil { 122 | return err 123 | } 124 | 125 | if cPermission.Type == consts.PERMISSION_TYPE_ABLE { 126 | parent.Auths = append(parent.Auths, cPermission.Name) 127 | } 128 | } 129 | return nil 130 | } 131 | 132 | if err = handleMany(cPermissions); err != nil { 133 | return 134 | } 135 | sort.Sort(finalRoutes) 136 | return finalRoutes, nil 137 | } 138 | -------------------------------------------------------------------------------- /internal/logic/role/role.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/api" 6 | "devops-super/internal/dao" 7 | "devops-super/internal/model/do" 8 | "devops-super/internal/model/entity" 9 | "devops-super/internal/model/entity/comb" 10 | "devops-super/internal/service" 11 | "github.com/gogf/gf/v2/encoding/gjson" 12 | "github.com/gogf/gf/v2/errors/gerror" 13 | "github.com/gogf/gf/v2/util/gutil" 14 | ) 15 | 16 | type sRole struct{} 17 | 18 | var cols = dao.Role.Columns() 19 | 20 | func init() { 21 | service.RegisterRole(New()) 22 | } 23 | 24 | func New() *sRole { 25 | return &sRole{} 26 | } 27 | 28 | func (*sRole) Add(ctx context.Context, in *entity.Role) (err error) { 29 | r, err := dao.Role.Ctx(ctx).Where(cols.Code, in.Code).One() 30 | if err != nil { 31 | return err 32 | } 33 | if r != nil { 34 | return gerror.New("已存在该代码的权限") 35 | } 36 | _, err = dao.Role.Ctx(ctx).Insert(in) 37 | return 38 | } 39 | 40 | func (*sRole) Upt(ctx context.Context, in *do.Role) (err error) { 41 | if !gutil.IsEmpty(in.Code) { 42 | r, err := dao.Role.Ctx(ctx).WhereNot(cols.Id, in.Id).Where(cols.Code, in.Code).One() 43 | if err != nil { 44 | return err 45 | } 46 | if r != nil { 47 | return gerror.New("已存在该代码的权限") 48 | } 49 | } 50 | _, err = dao.Role.Ctx(ctx).WherePri(in.Id).OmitNilData().Data(in).Update() 51 | return 52 | } 53 | 54 | func (*sRole) GetPageLst(ctx context.Context, in *api.PageLstReq) (out *api.PageLstRes[*entity.Role], err error) { 55 | out = &api.PageLstRes[*entity.Role]{} 56 | m := dao.Role.Ctx(ctx).Safe(true) 57 | if !gutil.IsEmpty(in.Search) { 58 | m = m.WhereOr(m.Builder().WhereOrLike(cols.Name, in.SearchStr()).WhereOrLike(cols.Code, in.SearchStr())) 59 | } 60 | 61 | err = m.Offset(in.Offset()).Limit(in.Limit()). 62 | ScanAndCount(&out.List, &out.Total, false) 63 | 64 | permission, err := service.Permission().SystemRequired(ctx) 65 | if err != nil { 66 | return nil, err 67 | } 68 | for _, u := range out.List { 69 | u.Permission = gjson.New(append(u.Permission.Array(), permission.Id)) 70 | } 71 | return 72 | } 73 | 74 | func (*sRole) GetLst(ctx context.Context) (out []*entity.Role, err error) { 75 | err = dao.Role.Ctx(ctx).OrderDesc(cols.Id).FieldsEx(cols.Permission).Scan(&out) 76 | return 77 | } 78 | 79 | func (*sRole) GetCombList(ctx context.Context) (out []*comb.Role, err error) { 80 | if err = dao.Role.Ctx(ctx).Scan(&out); err != nil { 81 | return 82 | } 83 | 84 | permission, err := service.Permission().SystemRequired(ctx) 85 | if err != nil { 86 | return nil, err 87 | } 88 | 89 | for _, role := range out { 90 | role.Permission = gjson.New(append(role.Permission.Array(), permission.Id)) 91 | if err = dao.Permission.Ctx(ctx).WithAll().WhereIn(dao.Permission.Columns().Id, role.Permission.Array()).Scan(&role.Permissions); err != nil { 92 | return 93 | } 94 | } 95 | return 96 | } 97 | 98 | func (*sRole) Get(ctx context.Context, in *do.Role) (out *entity.Role, err error) { 99 | err = dao.Role.Ctx(ctx).Where(in).OmitNilWhere().Limit(1).Scan(&out) 100 | permission, err := service.Permission().SystemRequired(ctx) 101 | if err != nil { 102 | return nil, err 103 | } 104 | out.Permission = gjson.New(append(out.Permission.Array(), permission.Id)) 105 | return 106 | } 107 | 108 | func (*sRole) Del(ctx context.Context, in *do.Role) (err error) { 109 | _, err = dao.Role.Ctx(ctx).Where(in).OmitNilWhere().Delete() 110 | return 111 | } 112 | -------------------------------------------------------------------------------- /internal/logic/user/user.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "devops-super/api" 6 | "devops-super/internal/dao" 7 | "devops-super/internal/model/do" 8 | "devops-super/internal/model/entity" 9 | "devops-super/internal/model/entity/comb" 10 | "devops-super/internal/service" 11 | "devops-super/utility/util" 12 | "github.com/gogf/gf/v2/util/gutil" 13 | ) 14 | 15 | type sUser struct{} 16 | 17 | var cols = dao.User.Columns() 18 | 19 | func init() { 20 | service.RegisterUser(New()) 21 | } 22 | 23 | func New() *sUser { 24 | return &sUser{} 25 | } 26 | 27 | func (*sUser) Add(ctx context.Context, in *entity.User) (err error) { 28 | in.Password, err = util.EncryptPassword(in.Password) 29 | if err != nil { 30 | return 31 | } 32 | _, err = dao.User.Ctx(ctx).Insert(in) 33 | return 34 | } 35 | 36 | func (*sUser) Upt(ctx context.Context, in *do.User) (err error) { 37 | if !gutil.IsEmpty(in.Password) { 38 | in.Password, err = util.EncryptPassword(in.Password.(string)) 39 | if err != nil { 40 | return 41 | } 42 | } 43 | _, err = dao.User.Ctx(ctx).WherePri(in.Id).OmitNilData().Data(in).Update() 44 | return 45 | } 46 | 47 | func (*sUser) GetPageLst(ctx context.Context, in *api.PageLstReq) (out *api.PageLstRes[*entity.User], err error) { 48 | out = &api.PageLstRes[*entity.User]{} 49 | m := dao.User.Ctx(ctx).Safe(true) 50 | if !gutil.IsEmpty(in.Search) { 51 | m = m.WhereOr(m.Builder().WhereOrLike(cols.Username, in.SearchStr()).WhereOrLike(cols.RealName, in.SearchStr())) 52 | } 53 | 54 | if enabled := in.Wheres.Get("enabled"); !enabled.IsNil() { 55 | m = m.Where(cols.Enabled, enabled.Bool()) 56 | } 57 | 58 | if deptId := in.Wheres.Get("deptId"); !deptId.IsNil() { 59 | m = m.Where(cols.DeptId, deptId.Int()) 60 | } 61 | 62 | err = m.Offset(in.Offset()).Limit(in.Limit()).FieldsEx(cols.Password). 63 | ScanAndCount(&out.List, &out.Total, false) 64 | return 65 | } 66 | 67 | func (*sUser) Get(ctx context.Context, userDo *do.User) (out *entity.User, err error) { 68 | err = dao.User.Ctx(ctx).Where(userDo).OmitNilWhere().Limit(1).Scan(&out) 69 | return 70 | } 71 | 72 | func (*sUser) GetComb(ctx context.Context, userDo *do.User) (out *comb.User, err error) { 73 | if err = dao.User.Ctx(ctx).Where(userDo).OmitNilWhere().Limit(1).Scan(&out); err != nil { 74 | return 75 | } 76 | if err = dao.Role.Ctx(ctx).WhereIn(dao.Role.Columns().Id, out.RoleIds.Array()).Scan(&out.Roles); err != nil { 77 | return 78 | } 79 | return 80 | } 81 | 82 | func (*sUser) GetCombLst(ctx context.Context) (out []*comb.User, err error) { 83 | if err = dao.User.Ctx(ctx).Where(cols.Enabled, true).Scan(&out); err != nil { 84 | return 85 | } 86 | 87 | for _, user := range out { 88 | if err = dao.Role.Ctx(ctx).WhereIn(dao.Role.Columns().Id, user.RoleIds.Array()).Scan(&user.Roles); err != nil { 89 | return 90 | } 91 | } 92 | return 93 | } 94 | 95 | func (*sUser) Del(ctx context.Context, in *do.User) (err error) { 96 | _, err = dao.User.Ctx(ctx).Where(in).OmitNilWhere().Delete() 97 | return 98 | } 99 | -------------------------------------------------------------------------------- /internal/model/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/model/.gitkeep -------------------------------------------------------------------------------- /internal/model/context.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/casbin/casbin/v2" 4 | 5 | type ServiceContext struct { 6 | CasbinEnforcer *casbin.Enforcer 7 | } 8 | 9 | type RequestUser struct { 10 | UserId int `json:"userId"` 11 | RealName string `json:"realName"` 12 | Username string `json:"username"` 13 | } 14 | -------------------------------------------------------------------------------- /internal/model/do/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/model/do/.gitkeep -------------------------------------------------------------------------------- /internal/model/do/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Dept is the golang structure of table dept for DAO operations like Where/Data. 13 | type Dept struct { 14 | g.Meta `orm:"table:dept, do:true"` 15 | Id interface{} // 16 | Name interface{} // 部门名称 17 | Rank interface{} // 排序 18 | ParentId interface{} // 上级部门 id 19 | UpdatedAt *gtime.Time // 更新时间 20 | } 21 | -------------------------------------------------------------------------------- /internal/model/do/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | "github.com/gogf/gf/v2/frame/g" 10 | ) 11 | 12 | // Permission is the golang structure of table permission for DAO operations like Where/Data. 13 | type Permission struct { 14 | g.Meta `orm:"table:permission, do:true"` 15 | Id interface{} // 16 | Title interface{} // 标题 17 | Name interface{} // 路由名称 18 | Type interface{} // 类型:1-目录,2-菜单,3-功能 19 | FRoute interface{} // 前端路由路径 20 | BRoutes *gjson.Json // 后端路由路径 21 | Redirect interface{} // 重定向路径 22 | Icon interface{} // 图标 23 | Rank interface{} // 排序 24 | ShowLink interface{} // 是否在菜单中展示 25 | ShowParent interface{} // 是否展示父级菜单 26 | KeepAlive interface{} // 页面缓存 27 | ParentId interface{} // 父级权限 id 28 | } 29 | -------------------------------------------------------------------------------- /internal/model/do/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | "github.com/gogf/gf/v2/frame/g" 10 | "github.com/gogf/gf/v2/os/gtime" 11 | ) 12 | 13 | // Role is the golang structure of table role for DAO operations like Where/Data. 14 | type Role struct { 15 | g.Meta `orm:"table:role, do:true"` 16 | Id interface{} // 17 | Name interface{} // 角色名称 18 | Code interface{} // 角色代码 19 | Permission *gjson.Json // 关联权限 20 | UpdatedAt *gtime.Time // 更新时间 21 | } 22 | -------------------------------------------------------------------------------- /internal/model/do/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | "github.com/gogf/gf/v2/frame/g" 10 | "github.com/gogf/gf/v2/os/gtime" 11 | ) 12 | 13 | // User is the golang structure of table user for DAO operations like Where/Data. 14 | type User struct { 15 | g.Meta `orm:"table:user, do:true"` 16 | Id interface{} // 17 | Username interface{} // 用户名 18 | Password interface{} // 密码 19 | Phone interface{} // 手机号码 20 | Email interface{} // 邮箱 21 | RealName interface{} // 真实姓名 22 | Enabled interface{} // 是否启用状态 23 | RoleIds *gjson.Json // 角色 id 24 | DeptId interface{} // 所属部门 id 25 | UpdatedAt *gtime.Time // 更新时间 26 | } 27 | -------------------------------------------------------------------------------- /internal/model/entity/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/model/entity/.gitkeep -------------------------------------------------------------------------------- /internal/model/entity/comb/permission.go: -------------------------------------------------------------------------------- 1 | package comb 2 | 3 | import ( 4 | "devops-super/internal/consts" 5 | "devops-super/internal/model/entity" 6 | ) 7 | 8 | type Permission struct { 9 | *entity.Permission 10 | //Parent *Permission `orm:"with:id=parent_id" json:"parent"` 11 | Children []*Permission `orm:"with:parent_id=id" json:"children"` 12 | } 13 | 14 | func (s *Permission) AuthCodes() (codes []string) { 15 | for _, child := range s.Children { 16 | if child.Type == consts.PERMISSION_TYPE_ABLE { 17 | codes = append(codes, child.Name) 18 | } 19 | } 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /internal/model/entity/comb/role.go: -------------------------------------------------------------------------------- 1 | package comb 2 | 3 | import "devops-super/internal/model/entity" 4 | 5 | type Role struct { 6 | *entity.Role 7 | Permissions []*Permission 8 | } 9 | -------------------------------------------------------------------------------- /internal/model/entity/comb/user.go: -------------------------------------------------------------------------------- 1 | package comb 2 | 3 | import "devops-super/internal/model/entity" 4 | 5 | type User struct { 6 | *entity.User 7 | Roles []*entity.Role 8 | } 9 | 10 | func (u *User) RoleCodes() []string { 11 | codes := make([]string, 0) 12 | for _, role := range u.Roles { 13 | codes = append(codes, role.Code) 14 | } 15 | return codes 16 | } 17 | -------------------------------------------------------------------------------- /internal/model/entity/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/os/gtime" 9 | ) 10 | 11 | // Dept is the golang structure for table dept. 12 | type Dept struct { 13 | Id int `json:"id" description:""` // 14 | Name string `json:"name" description:"部门名称"` // 部门名称 15 | Rank int `json:"rank" description:"排序"` // 排序 16 | ParentId int `json:"parentId" description:"上级部门 id"` // 上级部门 id 17 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` // 更新时间 18 | } 19 | -------------------------------------------------------------------------------- /internal/model/entity/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | ) 10 | 11 | // Permission is the golang structure for table permission. 12 | type Permission struct { 13 | Id int `json:"id" description:""` // 14 | Title string `json:"title" description:"标题"` // 标题 15 | Name string `json:"name" description:"路由名称"` // 路由名称 16 | Type int `json:"type" description:"类型:1-目录,2-菜单,3-功能"` // 类型:1-目录,2-菜单,3-功能 17 | FRoute string `json:"fRoute" description:"前端路由路径"` // 前端路由路径 18 | BRoutes *gjson.Json `json:"bRoutes" description:"后端路由路径"` // 后端路由路径 19 | Redirect string `json:"redirect" description:"重定向路径"` // 重定向路径 20 | Icon string `json:"icon" description:"图标"` // 图标 21 | Rank int `json:"rank" description:"排序"` // 排序 22 | ShowLink bool `json:"showLink" description:"是否在菜单中展示"` // 是否在菜单中展示 23 | ShowParent bool `json:"showParent" description:"是否展示父级菜单"` // 是否展示父级菜单 24 | KeepAlive bool `json:"keepAlive" description:"页面缓存"` // 页面缓存 25 | ParentId int `json:"parentId" description:"父级权限 id"` // 父级权限 id 26 | } 27 | -------------------------------------------------------------------------------- /internal/model/entity/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Role is the golang structure for table role. 13 | type Role struct { 14 | Id int `json:"id" description:""` // 15 | Name string `json:"name" description:"角色名称"` // 角色名称 16 | Code string `json:"code" description:"角色代码"` // 角色代码 17 | Permission *gjson.Json `json:"permission" description:"关联权限"` // 关联权限 18 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` // 更新时间 19 | } 20 | -------------------------------------------------------------------------------- /internal/model/entity/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/encoding/gjson" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // User is the golang structure for table user. 13 | type User struct { 14 | Id uint `json:"id" description:""` // 15 | Username string `json:"username" description:"用户名"` // 用户名 16 | Password string `json:"password" description:"密码"` // 密码 17 | Phone string `json:"phone" description:"手机号码"` // 手机号码 18 | Email string `json:"email" description:"邮箱"` // 邮箱 19 | RealName string `json:"realName" description:"真实姓名"` // 真实姓名 20 | Enabled bool `json:"enabled" description:"是否启用状态"` // 是否启用状态 21 | RoleIds *gjson.Json `json:"roleIds" description:"角色 id"` // 角色 id 22 | DeptId int `json:"deptId" description:"所属部门 id"` // 所属部门 id 23 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` // 更新时间 24 | } 25 | -------------------------------------------------------------------------------- /internal/model/mid/dept.go: -------------------------------------------------------------------------------- 1 | package mid 2 | 3 | type Dept struct { 4 | Name string `v:"required" json:"name"` 5 | Rank int `v:"required" json:"rank"` 6 | ParentId int `json:"parentId"` 7 | } 8 | -------------------------------------------------------------------------------- /internal/model/mid/permission.go: -------------------------------------------------------------------------------- 1 | package mid 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/encoding/gjson" 5 | ) 6 | 7 | type Permission struct { 8 | Title string `v:"required" json:"title"` 9 | Name string `v:"required" json:"name"` 10 | Type int `v:"required" json:"type"` 11 | FRoute string `json:"fRoute"` 12 | BRoutes *gjson.Json `json:"bRoutes"` 13 | Redirect string `json:"redirect"` 14 | Icon string `json:"icon"` 15 | Rank int `json:"rank"` 16 | ShowLink bool `v:"required" json:"showLink"` 17 | ShowParent bool `v:"required" json:"showParent"` 18 | KeepAlive bool `v:"required" json:"keepAlive"` 19 | ParentId int `json:"parentId"` 20 | } 21 | 22 | type Route struct { 23 | Id int `json:"id"` 24 | Name string `json:"name"` 25 | Title string `json:"title"` 26 | FRoute string `json:"fRoute"` 27 | Redirect string `json:"redirect"` 28 | Icon string `json:"icon,omitempty"` 29 | ParentId int `json:"parentId"` 30 | Rank int `json:"rank"` 31 | ShowLink bool `json:"showLink"` 32 | ShowParent bool `json:"showParent"` 33 | Auths []string `json:"auths,omitempty"` 34 | KeepAlive bool `json:"keepAlive"` 35 | } 36 | 37 | type FrontendRouteList []*Route 38 | 39 | func (s FrontendRouteList) Len() int { return len(s) } 40 | 41 | func (s FrontendRouteList) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 42 | 43 | func (s FrontendRouteList) Less(i, j int) bool { return s[i].Rank < s[j].Rank } 44 | -------------------------------------------------------------------------------- /internal/model/mid/role.go: -------------------------------------------------------------------------------- 1 | package mid 2 | 3 | type Role struct { 4 | Name string `v:"required|max-length:30" json:"name"` 5 | Code string `v:"required|max-length:30" json:"code"` 6 | } 7 | -------------------------------------------------------------------------------- /internal/model/mid/user.go: -------------------------------------------------------------------------------- 1 | package mid 2 | 3 | import "github.com/gogf/gf/v2/encoding/gjson" 4 | 5 | type User struct { 6 | Username string `v:"required|length:4,30" json:"username"` 7 | Phone string `json:"phone"` 8 | Email string `json:"email"` 9 | RealName string `v:"required" json:"realName"` 10 | RoleIds *gjson.Json `json:"roleIds"` 11 | DeptId int `v:"required" json:"deptId"` 12 | } 13 | -------------------------------------------------------------------------------- /internal/packed/packed.go: -------------------------------------------------------------------------------- 1 | package packed 2 | -------------------------------------------------------------------------------- /internal/service/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/internal/service/.gitkeep -------------------------------------------------------------------------------- /internal/service/auth.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | v1 "devops-super/api/public/v1" 6 | "devops-super/internal/model" 7 | "devops-super/internal/model/do" 8 | "devops-super/internal/model/entity" 9 | "devops-super/utility/util" 10 | "time" 11 | 12 | "github.com/gogf/gf/v2/encoding/gjson" 13 | 14 | jwt "github.com/gogf/gf-jwt/v2" 15 | "github.com/gogf/gf/v2/errors/gerror" 16 | "github.com/gogf/gf/v2/frame/g" 17 | ) 18 | 19 | var authService *jwt.GfJWTMiddleware 20 | 21 | func Auth() *jwt.GfJWTMiddleware { 22 | return authService 23 | } 24 | 25 | func CurrentUser(ctx context.Context) (u *model.RequestUser) { 26 | _ = gjson.New(authService.GetPayload(ctx)).Scan(&u) 27 | return 28 | } 29 | 30 | func init() { 31 | ctx := context.Background() 32 | auth := jwt.New(&jwt.GfJWTMiddleware{ 33 | Realm: "devops-super", 34 | Key: g.Cfg().MustGet(context.Background(), "jwt.secret").Bytes(), 35 | Timeout: g.Cfg().MustGet(ctx, "jwt.expire").Duration(), 36 | MaxRefresh: g.Cfg().MustGet(ctx, "jwt.expire").Duration(), 37 | IdentityKey: "userId", 38 | TokenLookup: "header: Authorization, query: token, cookie: jwt", 39 | TokenHeadName: "Bearer", 40 | TimeFunc: time.Now, 41 | Authenticator: Authenticator, 42 | Unauthorized: Unauthorized, 43 | PayloadFunc: PayloadFunc, 44 | IdentityHandler: IdentityHandler, 45 | }) 46 | authService = auth 47 | } 48 | 49 | // PayloadFunc is a callback function that will be called during login. 50 | // Using this function it is possible to add additional payload data to the webtoken. 51 | // The data is then made available during requests via c.Get("JWT_PAYLOAD"). 52 | // Note that the payload is not encrypted. 53 | // The attributes mentioned on jwt.io can't be used as keys for the map. 54 | // Optional, by default no additional data will be set. 55 | func PayloadFunc(data any) jwt.MapClaims { 56 | userInfo := data.(*entity.User) 57 | claims := make(jwt.MapClaims) 58 | claims["userId"] = userInfo.Id 59 | claims["username"] = userInfo.Username 60 | claims["realName"] = userInfo.RealName 61 | return claims 62 | } 63 | 64 | // IdentityHandler get the identity from JWT and set the identity for every request 65 | // Using this function, by r.GetParam("id") get identity 66 | func IdentityHandler(ctx context.Context) interface{} { 67 | claims := jwt.ExtractClaims(ctx) 68 | return claims[authService.IdentityKey] 69 | } 70 | 71 | // Unauthorized is used to define customized Unauthorized callback function. 72 | func Unauthorized(ctx context.Context, code int, message string) { 73 | r := g.RequestFromCtx(ctx) 74 | g.Log().Debug(ctx, message) 75 | r.Response.WriteJson(g.Map{ 76 | "code": code, 77 | "message": message, 78 | }) 79 | r.ExitAll() 80 | } 81 | 82 | // Authenticator is used to validate login parameters. 83 | // It must return user data as user identifier, it will be stored in Claim Array. 84 | // if your identityKey is 'id', your user data must have 'id' 85 | // Check error (e) to determine the appropriate error message. 86 | func Authenticator(ctx context.Context) (interface{}, error) { 87 | var ( 88 | r = g.RequestFromCtx(ctx) 89 | req *v1.LoginReq 90 | ) 91 | if err := r.Parse(&req); err != nil { 92 | return nil, err 93 | } 94 | 95 | eUser, err := User().Get(ctx, &do.User{Username: req.Username}) 96 | if err != nil { 97 | return nil, err 98 | } 99 | 100 | if eUser == nil { 101 | return nil, gerror.New("用户不存在") 102 | } 103 | 104 | if !util.ComparePassword(eUser.Password, req.Password) { 105 | return nil, gerror.New("密码错误") 106 | } 107 | 108 | if !eUser.Enabled { 109 | return nil, gerror.New("该用户处于禁用状态") 110 | } 111 | 112 | return eUser, nil 113 | } 114 | -------------------------------------------------------------------------------- /internal/service/context.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "context" 10 | model0 "devops-super/internal/model" 11 | ) 12 | 13 | type ( 14 | IContext interface { 15 | Init(ctx context.Context) error 16 | RefreshCasbin(ctx context.Context) error 17 | Ctx() *model0.ServiceContext 18 | } 19 | ) 20 | 21 | var ( 22 | localContext IContext 23 | ) 24 | 25 | func Context() IContext { 26 | if localContext == nil { 27 | panic("implement not found for interface IContext, forgot register?") 28 | } 29 | return localContext 30 | } 31 | 32 | func RegisterContext(i IContext) { 33 | localContext = i 34 | } 35 | -------------------------------------------------------------------------------- /internal/service/dept.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "context" 10 | "devops-super/internal/model/do" 11 | "devops-super/internal/model/entity" 12 | ) 13 | 14 | type ( 15 | IDept interface { 16 | Add(ctx context.Context, in *entity.Dept) (err error) 17 | Get(ctx context.Context, in *do.Dept) (out *entity.Dept, err error) 18 | GetLst(ctx context.Context, search string) (out []*entity.Dept, err error) 19 | Upt(ctx context.Context, in *do.Dept) (err error) 20 | Del(ctx context.Context, in *do.Dept) (err error) 21 | } 22 | ) 23 | 24 | var ( 25 | localDept IDept 26 | ) 27 | 28 | func Dept() IDept { 29 | if localDept == nil { 30 | panic("implement not found for interface IDept, forgot register?") 31 | } 32 | return localDept 33 | } 34 | 35 | func RegisterDept(i IDept) { 36 | localDept = i 37 | } 38 | -------------------------------------------------------------------------------- /internal/service/middleware.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "github.com/gogf/gf/v2/net/ghttp" 10 | ) 11 | 12 | type ( 13 | IMiddleware interface { 14 | Auth(r *ghttp.Request) 15 | } 16 | ) 17 | 18 | var ( 19 | localMiddleware IMiddleware 20 | ) 21 | 22 | func Middleware() IMiddleware { 23 | if localMiddleware == nil { 24 | panic("implement not found for interface IMiddleware, forgot register?") 25 | } 26 | return localMiddleware 27 | } 28 | 29 | func RegisterMiddleware(i IMiddleware) { 30 | localMiddleware = i 31 | } 32 | -------------------------------------------------------------------------------- /internal/service/permission.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "context" 10 | "devops-super/internal/model/do" 11 | "devops-super/internal/model/entity" 12 | "devops-super/internal/model/mid" 13 | ) 14 | 15 | type ( 16 | IPermission interface { 17 | Add(ctx context.Context, in *entity.Permission) (err error) 18 | Get(ctx context.Context, in *do.Permission) (out *entity.Permission, err error) 19 | GetLst(ctx context.Context, search string) (out []*entity.Permission, err error) 20 | Upt(ctx context.Context, in *do.Permission) (err error) 21 | Del(ctx context.Context, in *do.Permission) (err error) 22 | SystemRequired(ctx context.Context) (ePermission *entity.Permission, err error) 23 | GetRouteLst(ctx context.Context) (out []*mid.Route, err error) 24 | } 25 | ) 26 | 27 | var ( 28 | localPermission IPermission 29 | ) 30 | 31 | func Permission() IPermission { 32 | if localPermission == nil { 33 | panic("implement not found for interface IPermission, forgot register?") 34 | } 35 | return localPermission 36 | } 37 | 38 | func RegisterPermission(i IPermission) { 39 | localPermission = i 40 | } 41 | -------------------------------------------------------------------------------- /internal/service/role.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "context" 10 | "devops-super/api" 11 | "devops-super/internal/model/do" 12 | "devops-super/internal/model/entity" 13 | "devops-super/internal/model/entity/comb" 14 | ) 15 | 16 | type ( 17 | IRole interface { 18 | Add(ctx context.Context, in *entity.Role) (err error) 19 | Upt(ctx context.Context, in *do.Role) (err error) 20 | GetPageLst(ctx context.Context, in *api.PageLstReq) (out *api.PageLstRes[*entity.Role], err error) 21 | GetLst(ctx context.Context) (out []*entity.Role, err error) 22 | GetCombList(ctx context.Context) (out []*comb.Role, err error) 23 | Get(ctx context.Context, in *do.Role) (out *entity.Role, err error) 24 | Del(ctx context.Context, in *do.Role) (err error) 25 | } 26 | ) 27 | 28 | var ( 29 | localRole IRole 30 | ) 31 | 32 | func Role() IRole { 33 | if localRole == nil { 34 | panic("implement not found for interface IRole, forgot register?") 35 | } 36 | return localRole 37 | } 38 | 39 | func RegisterRole(i IRole) { 40 | localRole = i 41 | } 42 | -------------------------------------------------------------------------------- /internal/service/user.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | import ( 9 | "context" 10 | "devops-super/api" 11 | "devops-super/internal/model/do" 12 | "devops-super/internal/model/entity" 13 | "devops-super/internal/model/entity/comb" 14 | ) 15 | 16 | type ( 17 | IUser interface { 18 | Add(ctx context.Context, in *entity.User) (err error) 19 | Upt(ctx context.Context, in *do.User) (err error) 20 | GetPageLst(ctx context.Context, in *api.PageLstReq) (out *api.PageLstRes[*entity.User], err error) 21 | Get(ctx context.Context, userDo *do.User) (out *entity.User, err error) 22 | GetComb(ctx context.Context, userDo *do.User) (out *comb.User, err error) 23 | GetCombLst(ctx context.Context) (out []*comb.User, err error) 24 | Del(ctx context.Context, in *do.User) (err error) 25 | } 26 | ) 27 | 28 | var ( 29 | localUser IUser 30 | ) 31 | 32 | func User() IUser { 33 | if localUser == nil { 34 | panic("implement not found for interface IUser, forgot register?") 35 | } 36 | return localUser 37 | } 38 | 39 | func RegisterUser(i IUser) { 40 | localUser = i 41 | } 42 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "devops-super/internal/logic" 5 | _ "devops-super/internal/packed" 6 | _ "github.com/gogf/gf/contrib/drivers/mysql/v2" 7 | _ "github.com/gogf/gf/contrib/nosql/redis/v2" 8 | 9 | "github.com/gogf/gf/v2/os/gctx" 10 | 11 | "devops-super/internal/cmd" 12 | ) 13 | 14 | func main() { 15 | cmd.Main.Run(gctx.GetInitCtx()) 16 | } 17 | -------------------------------------------------------------------------------- /manifest/config/config.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | address: ":8000" 3 | openapiPath: "/api.json" 4 | swaggerPath: "/swagger" 5 | accessLogEnabled: true 6 | serverRoot: /Users/zze/Work/code/github/zze-admin-go/resource/dist 7 | indexFiles: [ "index.html", "main.html" ] 8 | 9 | 10 | logger: 11 | level: "all" 12 | stdout: true 13 | 14 | database: 15 | logger: 16 | level: "all" 17 | stdout: "true" 18 | default: 19 | type: mysql 20 | link: "mysql:zze:zze.admin@tcp(127.0.0.1:3306)/zze_admin_go?loc=Local&parseTime=true" 21 | charset: utf8mb4 22 | maxIdle: "10" 23 | maxOpen: "300" 24 | debug: true 25 | 26 | jwt: 27 | secret: vIIEngfamGZasdkseadgF9fe 28 | expire: 8h 29 | -------------------------------------------------------------------------------- /manifest/db/zze_admin_go.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE `zze_admin_go` default charset utf8mb4; 2 | USE `zze_admin_go`; 3 | 4 | SET NAMES utf8mb4; 5 | SET FOREIGN_KEY_CHECKS = 0; 6 | 7 | -- ---------------------------- 8 | -- Table structure for dept 9 | -- ---------------------------- 10 | DROP TABLE IF EXISTS `dept`; 11 | CREATE TABLE `dept` ( 12 | `id` int(11) NOT NULL AUTO_INCREMENT, 13 | `name` varchar(64) NOT NULL COMMENT '部门名称', 14 | `rank` int(11) NOT NULL COMMENT '排序', 15 | `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级部门 id', 16 | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', 17 | PRIMARY KEY (`id`) 18 | ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4; 19 | 20 | -- ---------------------------- 21 | -- Records of dept 22 | -- ---------------------------- 23 | BEGIN; 24 | INSERT INTO `dept` (`id`, `name`, `rank`, `parent_id`, `updated_at`) VALUES (1, '深圳总公司', 0, 0, '2023-09-22 13:43:26'); 25 | INSERT INTO `dept` (`id`, `name`, `rank`, `parent_id`, `updated_at`) VALUES (2, '研发部', 1, 1, '2023-09-22 13:52:25'); 26 | INSERT INTO `dept` (`id`, `name`, `rank`, `parent_id`, `updated_at`) VALUES (3, '开发部', 1, 2, '2023-09-22 13:52:36'); 27 | INSERT INTO `dept` (`id`, `name`, `rank`, `parent_id`, `updated_at`) VALUES (4, '运维部', 2, 2, '2023-09-22 13:52:41'); 28 | INSERT INTO `dept` (`id`, `name`, `rank`, `parent_id`, `updated_at`) VALUES (5, '运营部', 2, 1, '2023-09-22 13:52:57'); 29 | COMMIT; 30 | 31 | -- ---------------------------- 32 | -- Table structure for permission 33 | -- ---------------------------- 34 | DROP TABLE IF EXISTS `permission`; 35 | CREATE TABLE `permission` ( 36 | `id` int(11) NOT NULL AUTO_INCREMENT, 37 | `title` varchar(64) NOT NULL COMMENT '标题', 38 | `name` varchar(64) NOT NULL COMMENT '路由名称', 39 | `type` tinyint(4) NOT NULL COMMENT '类型:1-目录,2-菜单,3-功能', 40 | `f_route` varchar(64) DEFAULT NULL COMMENT '前端路由路径', 41 | `b_routes` json DEFAULT NULL COMMENT '后端路由路径', 42 | `redirect` varchar(64) DEFAULT NULL COMMENT '重定向路径', 43 | `icon` varchar(32) DEFAULT NULL COMMENT '图标', 44 | `rank` int(11) DEFAULT NULL COMMENT '排序', 45 | `show_link` bit(1) NOT NULL COMMENT '是否在菜单中展示', 46 | `show_parent` bit(1) NOT NULL COMMENT '是否展示父级菜单', 47 | `keep_alive` bit(1) NOT NULL COMMENT '页面缓存', 48 | `parent_id` int(11) NOT NULL COMMENT '父级权限 id', 49 | PRIMARY KEY (`id`) 50 | ) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4; 51 | 52 | -- ---------------------------- 53 | -- Records of permission 54 | -- ---------------------------- 55 | BEGIN; 56 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (1, '系统管理', 'system-manage', 1, '/system', '[]', '/system/user', 'ep:setting', 1, b'1', b'0', b'0', 0); 57 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (2, '权限管理', 'permission-manage', 2, '/system/permission', '[]', '', 'fa-solid:allergies', 3, b'1', b'1', b'1', 1); 58 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (3, '用户管理', 'user-manage', 2, '/system/user', '[]', '', 'fa:address-card', 1, b'1', b'1', b'1', 1); 59 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (4, '新增用户', 'user-add', 3, '/test4', '[\"post:/user\"]', '/test4', '', 2, b'1', b'0', b'0', 3); 60 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (5, '角色管理', 'role-manage', 2, '/system/role', '[]', '', 'ep:avatar', 2, b'1', b'1', b'1', 1); 61 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (6, '更新用户', 'user-upt', 3, '/test6', '[\"put:/user/:id\"]', '/test6', '', 3, b'1', b'0', b'0', 3); 62 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (8, '更新用户密码', 'user-upt-password', 3, '', '[\"patch:/user/:id/password\"]', '', '', 5, b'0', b'0', b'0', 3); 63 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (9, '启用、禁用用户', 'user-upt-enable', 3, '', '[\"patch:/user/:id/enabled\"]', '', '', 6, b'0', b'0', b'0', 3); 64 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (10, '删除用户', 'user-del', 3, '', '[\"delete:/user/:id\"]', '', '', 4, b'0', b'0', b'0', 3); 65 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (11, '查询用户', 'user-read', 3, '', '[\"get:/user/page-list\", \"get:/dept/list\"]', '', '', 1, b'0', b'0', b'0', 3); 66 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (14, '查询权限', 'permission-read', 3, '', '[\"get:/permission/list\"]', '', '', 1, b'0', b'0', b'0', 2); 67 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (15, '新增权限', 'permission-add', 3, '', '[\"post:/permission\"]', '', '', 2, b'0', b'0', b'0', 2); 68 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (16, '更新权限', 'permission-upt', 3, '', '[\"put:/permission/:id\"]', '', '', 3, b'0', b'0', b'0', 2); 69 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (17, '删除权限', 'permission-del', 3, '', '[\"delete:/permission/:id\"]', '', '', 4, b'0', b'0', b'0', 2); 70 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (18, '更新权限是否展示在菜单', 'permission-upt-show-link', 3, '', '[\"patch:/permission/:id/show-link\"]', '', '', 5, b'0', b'0', b'0', 2); 71 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (20, '查询角色', 'role-read', 3, '', '[\"get:/role/page-list\", \"get:/permission/list\"]', '', '', 1, b'0', b'0', b'0', 5); 72 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (21, '新增角色', 'role-add', 3, '', '[\"post:/role\"]', '', '', 2, b'0', b'0', b'0', 5); 73 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (22, '更新角色', 'role-upt', 3, '', '[\"put:/role:id\"]', '', '', 3, b'0', b'0', b'0', 5); 74 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (23, '删除角色', 'role-del', 3, '', '[\"delete:/role/:id\"]', '', '', 4, b'0', b'0', b'0', 5); 75 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (24, '保存角色权限信息', 'role-upt-permission', 3, '', '[\"patch:/role/:id/permission\"]', '', '', 5, b'0', b'0', b'0', 5); 76 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (25, '系统必需', 'system-required', 3, '', '[\"get:/permission/route-list\"]', '', '', 0, b'0', b'0', b'0', 0); 77 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (27, '部门管理', 'dept-manage', 2, '/system/dept', '[]', '', 'fa:group', 4, b'1', b'1', b'1', 1); 78 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (28, '查询部门', 'dept-read', 3, '', '[\"get:/dept/list\"]', '', '', 1, b'0', b'0', b'0', 27); 79 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (29, '新增部门', 'dept-add', 3, '', '[\"post:/dept\"]', '', '', 2, b'0', b'0', b'0', 27); 80 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (30, '更新部门', 'dept-upt', 3, '', '[\"put:/dept/:id\"]', '', '', 3, b'0', b'0', b'0', 27); 81 | INSERT INTO `permission` (`id`, `title`, `name`, `type`, `f_route`, `b_routes`, `redirect`, `icon`, `rank`, `show_link`, `show_parent`, `keep_alive`, `parent_id`) VALUES (31, '删除部门', 'dept-del', 3, '', '[\"delete:/dept/:id\"]', '', '', 4, b'0', b'0', b'0', 27); 82 | COMMIT; 83 | 84 | -- ---------------------------- 85 | -- Table structure for role 86 | -- ---------------------------- 87 | DROP TABLE IF EXISTS `role`; 88 | CREATE TABLE `role` ( 89 | `id` int(11) NOT NULL AUTO_INCREMENT, 90 | `name` varchar(128) NOT NULL COMMENT '角色名称', 91 | `code` varchar(30) NOT NULL COMMENT '角色代码', 92 | `permission` json DEFAULT NULL COMMENT '关联权限', 93 | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', 94 | PRIMARY KEY (`id`) 95 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; 96 | 97 | -- ---------------------------- 98 | -- Records of role 99 | -- ---------------------------- 100 | BEGIN; 101 | INSERT INTO `role` (`id`, `name`, `code`, `permission`, `updated_at`) VALUES (1, '管理员', 'admin', '[25, 1, 3, 11, 4, 6, 10, 8, 9, 5, 20, 21, 22, 23, 24, 2, 14, 15, 16, 17, 18]', '2023-09-22 11:06:46'); 102 | INSERT INTO `role` (`id`, `name`, `code`, `permission`, `updated_at`) VALUES (2, '测试', 'test', '[25, 11, 5, 20, 21, 22, 23, 24, 16]', '2023-09-22 11:06:46'); 103 | COMMIT; 104 | 105 | -- ---------------------------- 106 | -- Table structure for user 107 | -- ---------------------------- 108 | DROP TABLE IF EXISTS `user`; 109 | CREATE TABLE `user` ( 110 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 111 | `username` varchar(128) NOT NULL COMMENT '用户名', 112 | `password` varchar(128) NOT NULL COMMENT '密码', 113 | `phone` varchar(128) DEFAULT NULL COMMENT '手机号码', 114 | `email` varchar(128) DEFAULT NULL COMMENT '邮箱', 115 | `real_name` varchar(128) DEFAULT NULL COMMENT '真实姓名', 116 | `enabled` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用状态', 117 | `role_ids` json DEFAULT NULL COMMENT '角色 id', 118 | `dept_id` int(11) NOT NULL COMMENT '所属部门 id', 119 | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', 120 | PRIMARY KEY (`id`) 121 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; 122 | 123 | -- ---------------------------- 124 | -- Records of user 125 | -- ---------------------------- 126 | BEGIN; 127 | INSERT INTO `user` (`id`, `username`, `password`, `phone`, `email`, `real_name`, `enabled`, `role_ids`, `dept_id`, `updated_at`) VALUES (1, 'admin', '$2a$10$4R/ujw20O63gNwBTS0vJmOfAUukGT5pCMll0gsqy6IALPHZC7SDv2', '16666666666', '632404164@qq.com', '管理员', b'1', '[1]', 1, '2023-09-22 16:45:33'); 128 | INSERT INTO `user` (`id`, `username`, `password`, `phone`, `email`, `real_name`, `enabled`, `role_ids`, `dept_id`, `updated_at`) VALUES (2, 'test', '$2a$10$aEX83iCGh/JrxiTImN0PE.0bK/dLE1lFFeZ4ssHdK4/rrXCqMgRHe', '16666666666', '632404164@qq.com', '测试用户', b'1', '[2]', 4, '2023-09-22 16:45:50'); 129 | COMMIT; 130 | 131 | SET FOREIGN_KEY_CHECKS = 1; 132 | 133 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: template-single 5 | labels: 6 | app: template-single 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: template-single 12 | template: 13 | metadata: 14 | labels: 15 | app: template-single 16 | spec: 17 | containers: 18 | - name : main 19 | image: template-single 20 | imagePullPolicy: Always 21 | 22 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - deployment.yaml 5 | - service.yaml 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: template-single 5 | spec: 6 | ports: 7 | - port: 80 8 | protocol: TCP 9 | targetPort: 8000 10 | selector: 11 | app: template-single 12 | 13 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: template-single-configmap 5 | data: 6 | config.yaml: | 7 | server: 8 | address: ":8000" 9 | openapiPath: "/api.json" 10 | swaggerPath: "/swagger" 11 | 12 | logger: 13 | level : "all" 14 | stdout: true 15 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: template-single 5 | spec: 6 | template: 7 | spec: 8 | containers: 9 | - name : main 10 | image: template-single:develop -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - ../../base 6 | - configmap.yaml 7 | 8 | patchesStrategicMerge: 9 | - deployment.yaml 10 | 11 | namespace: default 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /manifest/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM loads/alpine:3.8 2 | 3 | ############################################################################### 4 | # INSTALLATION 5 | ############################################################################### 6 | 7 | ENV WORKDIR /app 8 | ADD resource $WORKDIR/ 9 | ADD manifest/config $WORKDIR/config 10 | ADD ./temp/linux_amd64/main $WORKDIR/main 11 | RUN chmod +x $WORKDIR/main 12 | 13 | ############################################################################### 14 | # START 15 | ############################################################################### 16 | WORKDIR $WORKDIR 17 | CMD ./main --gf.gcfg.file=config-prod.yaml 18 | -------------------------------------------------------------------------------- /manifest/docker/docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This shell is executed before docker build. 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /manifest/protobuf/.keep-if-necessary: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/manifest/protobuf/.keep-if-necessary -------------------------------------------------------------------------------- /resource/i18n/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/i18n/.gitkeep -------------------------------------------------------------------------------- /resource/imgs/dept-manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/imgs/dept-manage.png -------------------------------------------------------------------------------- /resource/imgs/permission-manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/imgs/permission-manage.png -------------------------------------------------------------------------------- /resource/imgs/role-manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/imgs/role-manage.png -------------------------------------------------------------------------------- /resource/imgs/user-manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/imgs/user-manage.png -------------------------------------------------------------------------------- /resource/public/html/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/public/html/.gitkeep -------------------------------------------------------------------------------- /resource/public/plugin/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/public/plugin/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/css/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/public/resource/css/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/image/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/public/resource/image/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/js/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/public/resource/js/.gitkeep -------------------------------------------------------------------------------- /resource/template/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/resource/template/.gitkeep -------------------------------------------------------------------------------- /tests/1_test.go: -------------------------------------------------------------------------------- 1 | package tests 2 | 3 | import ( 4 | "devops-super/utility/util" 5 | "fmt" 6 | "github.com/gogf/gf/v2/os/gtime" 7 | "strings" 8 | "testing" 9 | ) 10 | 11 | func Test1_1(t *testing.T) { 12 | t.Log(util.EncryptPassword("admin123")) 13 | //a := "$2a$10$yCU6QndNxyrLGjEMSn.YIOXph2LfaedbnrGKkZJ8vpcpaDhKMSb5K" 14 | b := "$2a$10$lmPQ9aQ287342NpIdZctH.m9vP1gljNGJExhT1TVhbisVia.0cNRC" 15 | t.Log(util.ComparePassword(b, "admin123")) 16 | } 17 | 18 | func Test1(t *testing.T) { 19 | t.Log(gtime.Now().Unix()) 20 | t.Log(gtime.Now().UnixMilli()) 21 | t.Log(gtime.Now().UnixMicro()) 22 | t.Log(gtime.Now().UnixNano()) 23 | } 24 | 25 | func Test1_3(t *testing.T) { 26 | var iv int = 3 27 | switch iv { 28 | case 1 | 2: 29 | fmt.Println("into 1") 30 | case 4: 31 | fmt.Println("into 4") 32 | } 33 | fmt.Println("testSwitch run end") 34 | } 35 | 36 | func Test1_4(t *testing.T) { 37 | route := "get:/test/:id" 38 | t.Log(strings.SplitN(route, ":", 2)) 39 | } 40 | -------------------------------------------------------------------------------- /utility/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zze326/zze-admin-go/9145cb1008e5da547dc4a60befb4d9527e7359b6/utility/.gitkeep -------------------------------------------------------------------------------- /utility/util/encrypt.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "golang.org/x/crypto/bcrypt" 4 | 5 | func EncryptPassword(password string) (string, error) { 6 | hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), 3) 7 | if err != nil { 8 | return "", err 9 | } 10 | 11 | return string(hashedPassword), nil 12 | } 13 | 14 | func ComparePassword(hashedPassword, password string) bool { 15 | // 比较哈希后的密码和输入的密码是否匹配 16 | err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) 17 | return err == nil 18 | } 19 | -------------------------------------------------------------------------------- /utility/util/generic.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | func GetPointer[T any](v T) *T { 4 | return &v 5 | } 6 | 7 | func SqlLikeStr(str string) string { 8 | return "%" + str + "%" 9 | } 10 | 11 | func InSlice[T comparable](slice []T, v T) bool { 12 | for _, item := range slice { 13 | if item == v { 14 | return true 15 | } 16 | } 17 | return false 18 | } 19 | --------------------------------------------------------------------------------