1 Star 0 Fork 39

supbose / go-admin

forked from hequan / go-admin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Go Web Admin

版本 语言 base base

一个Go Web Api 后端 简单例子,包含 用户、权限、菜单、JWT 、 RBAC(Casbin)等!

  • user
    • username password
  • role
    • name
  • menu
    • name path method

DEMO

http://129.28.156.219:8002/swagger/index.html

admin 密码 123456

http://129.28.156.219:8002

API 注释

http://127.0.0.1:8000/swagger/index.html

demo

目录结构

  • conf:用于存储配置文件
  • docs: 文档(SQL和API注释)
  • logs: 日志
  • middleware:应用中间件
  • models:应用数据库模型
  • pkg:第三方包
  • routers: 路由逻辑处理
  • service: 逻辑处理
  • test: 单元测试

权限验证说明

项目启动时,会自动user  role  menu 进行自动关联!  如有更改,会删除对应的权限,重新加载!

用户  关联  角色  
角色  关联  菜单  
权限关系为:
角色(role.name,  menu.path,  menu.method)  
用户(user.username,   role.name)

例如:
运维部      /api/v1/users       GET
hequan     运维部

当hequan  GET  /api/v1/users 地址的时候,会去检查权限,因为他属于运维部 ,同时 运维部 有对应权限,所以本次请求会通过。

用户 admin 有所有的权限,不进行权限匹配

登录接口 /auth  不进行验证

请求

请求和接收 都是 传递 json 格式 数据

例如:
访问 /auth    获取token
{
	"username": "admin",
	"password": "123456"
}

访问      /api/v1/menus?page=2    页面是page
请求头设置  Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

部署

支持

  • 部署 Mysql

Create a go database and import SQL

创建一个库 go,然后导入sql,创建表!

配置文件

You should modify conf/app.ini

[database]
Type = mysql
User = root
Password =
Host = 127.0.0.1:3306
Name = go
TablePrefix = go_

安装部署


yum install go -y 


export GOPROXY=https://goproxy.io
go get github.com/hequan2017/go-admin
cd $GOPATH/src/github.com/hequan2017/go-admin
go build main.go
go run  main.go 

热编译(开发时使用)


go get github.com/silenceper/gowatch

gowatch   

运行

更新角色权限关系 [[hequan 运维部]]
角色权限关系 [[hequan 运维部]]
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] POST   /auth                     --> github.com/hequan2017/go-admin/routers/api.Auth (4 handlers)
[GIN-debug] GET    /swagger/*any             --> github.com/swaggo/gin-swagger.WrapHandler.func1 (4 handlers)
[GIN-debug] GET    /api/v1/menus             --> github.com/hequan2017/go-admin/routers/api/v1.GetMenus (6 handlers)
[GIN-debug] GET    /api/v1/menus/:id         --> github.com/hequan2017/go-admin/routers/api/v1.GetMenu (6 handlers)
[GIN-debug] POST   /api/v1/menus             --> github.com/hequan2017/go-admin/routers/api/v1.AddMenu (6 handlers)
[GIN-debug] PUT    /api/v1/menus/:id         --> github.com/hequan2017/go-admin/routers/api/v1.EditMenu (6 handlers)
[GIN-debug] DELETE /api/v1/menus/:id         --> github.com/hequan2017/go-admin/routers/api/v1.DeleteMenu (6 handlers)
[GIN-debug] GET    /api/v1/roles             --> github.com/hequan2017/go-admin/routers/api/v1.GetRoles (6 handlers)
[GIN-debug] GET    /api/v1/roles/:id         --> github.com/hequan2017/go-admin/routers/api/v1.GetRole (6 handlers)
[GIN-debug] POST   /api/v1/roles             --> github.com/hequan2017/go-admin/routers/api/v1.AddRole (6 handlers)
[GIN-debug] PUT    /api/v1/roles/:id         --> github.com/hequan2017/go-admin/routers/api/v1.EditRole (6 handlers)
[GIN-debug] DELETE /api/v1/roles/:id         --> github.com/hequan2017/go-admin/routers/api/v1.DeleteRole (6 handlers)
[GIN-debug] GET    /api/v1/users             --> github.com/hequan2017/go-admin/routers/api.GetUsers (6 handlers)
[GIN-debug] GET    /api/v1/users/:id         --> github.com/hequan2017/go-admin/routers/api.GetUser (6 handlers)
[GIN-debug] POST   /api/v1/users             --> github.com/hequan2017/go-admin/routers/api.AddUser (6 handlers)
[GIN-debug] PUT    /api/v1/users/:id         --> github.com/hequan2017/go-admin/routers/api.EditUser (6 handlers)
[GIN-debug] DELETE /api/v1/users/:id         --> github.com/hequan2017/go-admin/routers/api.DeleteUser (6 handlers)
2019/05/31 14:48:43 [info] start http server listening :8000

Features

- RESTful API
- Gorm
- logging
- Jwt-go
- Swagger
- Gin
- Graceful restart or stop (fvbock/endless)
- App configurable
- 一键生成 Restful API接口

开发者

  • 何全

特别感谢

本项目主要参考了:
https://github.com/EDDYCJY/go-gin-example  包含更多的例子,上传文件图片等。本项目进行了增改。
https://github.com/LyricTian/gin-admin     主要为 gin+ casbin例子。

其他

## 更新API文档
swag init

## 
cd /opt/go-admin
nohup  go run  main.go   >>  /tmp/go-http.log   2>&1  & 
The MIT License (MIT) Copyright (c) The go-admin Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

go 后端api,包含gin+gorm+jwt+rbac。 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/yazhitv/go-admin.git
git@gitee.com:yazhitv/go-admin.git
yazhitv
go-admin
go-admin
master

搜索帮助